Skip to content

Commit 1d92c55

Browse files
committed
Merge remote-tracking branch 'origin/main' into pre/v9-combined-testing
2 parents 82f19ce + e562267 commit 1d92c55

File tree

14 files changed

+346
-572
lines changed

14 files changed

+346
-572
lines changed

lib/color.ts

Lines changed: 89 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,92 @@
1-
// using chalk as some of our other dependencies are already using it...
2-
// exporting from here so we can easily refactor to a different color library if needed
3-
import * as ansi from "ansi-colors";
4-
import * as chalk from "chalk";
1+
import { styleText, stripVTControlCharacters } from "node:util";
52

6-
export type Color = typeof chalk.Color;
3+
// Define color types based on util.inspect.colors
4+
export type StyleFormat =
5+
| "reset"
6+
| "bold"
7+
| "dim"
8+
| "italic"
9+
| "underline"
10+
| "blink"
11+
| "inverse"
12+
| "hidden"
13+
| "strikethrough"
14+
| "doubleunderline"
15+
| "black"
16+
| "red"
17+
| "green"
18+
| "yellow"
19+
| "blue"
20+
| "magenta"
21+
| "cyan"
22+
| "white"
23+
| "gray"
24+
| "redBright"
25+
| "greenBright"
26+
| "yellowBright"
27+
| "blueBright"
28+
| "magentaBright"
29+
| "cyanBright"
30+
| "whiteBright"
31+
| "bgBlack"
32+
| "bgRed"
33+
| "bgGreen"
34+
| "bgYellow"
35+
| "bgBlue"
36+
| "bgMagenta"
37+
| "bgCyan"
38+
| "bgWhite"
39+
| "bgGray"
40+
| "bgRedBright"
41+
| "bgGreenBright"
42+
| "bgYellowBright"
43+
| "bgBlueBright"
44+
| "bgMagentaBright"
45+
| "bgCyanBright"
46+
| "bgWhiteBright";
747

8-
export function stripColors(formatStr: string) {
9-
return ansi.stripColor(formatStr);
10-
}
48+
export type Color = StyleFormat;
1149

12-
export const color = chalk;
50+
// Create a chalk-like API using the Node.js util.styleText function
51+
export const color = {
52+
reset: (text: string) => styleText("reset", text),
53+
bold: (text: string) => styleText("bold", text),
54+
dim: (text: string) => styleText("dim", text),
55+
italic: (text: string) => styleText("italic", text),
56+
underline: (text: string) => styleText("underline", text),
57+
inverse: (text: string) => styleText("inverse", text),
58+
hidden: (text: string) => styleText("hidden", text),
59+
strikethrough: (text: string) => styleText("strikethrough", text),
60+
61+
// Text colors
62+
black: (text: string) => styleText("black", text),
63+
red: (text: string) => styleText("red", text),
64+
blue: (text: string) => styleText("blue", text),
65+
magenta: (text: string) => styleText("magenta", text),
66+
cyan: (text: string) => styleText("cyan", text),
67+
white: (text: string) => styleText("white", text),
68+
gray: (text: string) => styleText("gray", text),
69+
yellow: (text: string) => styleText("yellow", text),
70+
green: (text: string) => styleText("green", text),
71+
grey: (text: string) => styleText("grey", text),
72+
73+
// Background colors
74+
bgBlack: (text: string) => styleText("bgBlack", text),
75+
bgBlackBright: (text: string) => styleText("bgBlackBright", text),
76+
bgRed: (text: string) => styleText("bgRed", text),
77+
bgGreen: (text: string) => styleText("bgGreen", text),
78+
bgYellow: (text: string) => styleText("bgYellow", text),
79+
bgBlue: (text: string) => styleText("bgBlue", text),
80+
bgMagenta: (text: string) => styleText("bgMagenta", text),
81+
bgCyan: (text: string) => styleText("bgCyan", text),
82+
bgWhite: (text: string) => styleText("bgWhite", text),
83+
cyanBright: (text: string) => styleText("cyanBright", text),
84+
whiteBright: (text: string) => styleText("whiteBright", text),
85+
greenBright: (text: string) => styleText("greenBright", text),
86+
yellowBright: (text: string) => styleText("yellowBright", text),
87+
redBright: (text: string) => styleText("redBright", text),
88+
89+
styleText,
90+
};
91+
92+
export const stripColors = (text: string) => stripVTControlCharacters(text);

lib/commands/clean.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ export class CleanCommand implements ICommand {
267267
spinner.warn(
268268
`This will run "${color.yellow(
269269
`ns clean`,
270-
)}" in all the selected projects and ${color.red.bold(
270+
)}" in all the selected projects and ${color.styleText(
271+
["red", "bold"],
271272
"delete files from your system",
272273
)}!`,
273274
);

lib/commands/embedding/embed.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class EmbedCommand extends PrepareCommand implements ICommand {
2424

2525
private $logger: ILogger,
2626
private $fs: IFileSystem,
27-
private $projectConfigService: IProjectConfigService
27+
private $projectConfigService: IProjectConfigService,
2828
) {
2929
super(
3030
$options,
@@ -34,7 +34,7 @@ export class EmbedCommand extends PrepareCommand implements ICommand {
3434
$platformCommandParameter,
3535
$platformsDataService,
3636
$prepareDataService,
37-
$migrateController
37+
$migrateController,
3838
);
3939
}
4040

@@ -56,10 +56,11 @@ export class EmbedCommand extends PrepareCommand implements ICommand {
5656
if (!this.$fs.exists(resolvedHostProjectPath)) {
5757
this.$logger.error(
5858
`The host project path ${color.yellow(
59-
hostProjectPath
60-
)} (resolved to: ${color.yellow.dim(
61-
resolvedHostProjectPath
62-
)}) does not exist.`
59+
hostProjectPath,
60+
)} (resolved to: ${color.styleText(
61+
["yellow", "dim"],
62+
resolvedHostProjectPath,
63+
)}) does not exist.`,
6364
);
6465
return;
6566
}
@@ -89,7 +90,7 @@ export class EmbedCommand extends PrepareCommand implements ICommand {
8990
if (!args[1]) {
9091
const hostProjectPath = this.getEmbedConfigForKey(
9192
"hostProjectPath",
92-
platform
93+
platform,
9394
);
9495
if (hostProjectPath) {
9596
args[1] = hostProjectPath;
@@ -99,7 +100,7 @@ export class EmbedCommand extends PrepareCommand implements ICommand {
99100
if (!args[2]) {
100101
const hostProjectModuleName = this.getEmbedConfigForKey(
101102
"hostProjectModuleName",
102-
platform
103+
platform,
103104
);
104105
if (hostProjectModuleName) {
105106
args[2] = hostProjectModuleName;
@@ -119,7 +120,7 @@ export class EmbedCommand extends PrepareCommand implements ICommand {
119120
// get the embed.<platform>.<key> value, or fallback to embed.<key> value
120121
return this.$projectConfigService.getValue(
121122
`embed.${platform}.${key}`,
122-
this.$projectConfigService.getValue(`embed.${key}`)
123+
this.$projectConfigService.getValue(`embed.${key}`),
123124
);
124125
}
125126
}

lib/commands/post-install.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class PostInstallCliCommand implements ICommand {
1818
private $settingsService: ISettingsService,
1919
private $analyticsService: IAnalyticsService,
2020
private $logger: ILogger,
21-
private $hostInfo: IHostInfo
21+
private $hostInfo: IHostInfo,
2222
) {}
2323

2424
public disableAnalytics = true;
@@ -35,7 +35,7 @@ export class PostInstallCliCommand implements ICommand {
3535
// TODO: Check if this is the correct place, probably we should set this at the end of the command.
3636
await this.$fs.setCurrentUserAsOwner(
3737
this.$settingsService.getProfileDir(),
38-
process.env.SUDO_USER
38+
process.env.SUDO_USER,
3939
);
4040
}
4141
}
@@ -55,15 +55,18 @@ export class PostInstallCliCommand implements ICommand {
5555
public async postCommandAction(args: string[]): Promise<void> {
5656
this.$logger.info("");
5757
this.$logger.info(
58-
color.green.bold("You have successfully installed the NativeScript CLI!")
58+
color.styleText(
59+
["green", "bold"],
60+
"You have successfully installed the NativeScript CLI!",
61+
),
5962
);
6063
this.$logger.info("");
6164
this.$logger.info("Your next step is to create a new project:");
62-
this.$logger.info(color.green.bold("ns create"));
65+
this.$logger.info(color.styleText(["green", "bold"], "ns create"));
6366

6467
this.$logger.info("");
6568
this.$logger.printMarkdown(
66-
"If you have any questions, check Stack Overflow: `https://stackoverflow.com/questions/tagged/nativescript` and our public Discord channel: `https://nativescript.org/discord`"
69+
"If you have any questions, check Stack Overflow: `https://stackoverflow.com/questions/tagged/nativescript` and our public Discord channel: `https://nativescript.org/discord`",
6770
);
6871
}
6972
}

lib/commands/typings.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { glob } from "glob";
1+
import { glob } from "node:fs/promises";
22
import { homedir } from "os";
33
import * as path from "path";
44
import { PromptObject } from "prompts";
@@ -20,7 +20,7 @@ export class TypingsCommand implements ICommand {
2020
private $childProcess: IChildProcess,
2121
private $hostInfo: IHostInfo,
2222
private $staticConfig: IStaticConfig,
23-
private $prompter: IPrompter
23+
private $prompter: IPrompter,
2424
) {}
2525

2626
public async execute(args: string[]): Promise<void> {
@@ -35,15 +35,15 @@ export class TypingsCommand implements ICommand {
3535
if (this.$options.copyTo) {
3636
this.$fs.copyFile(
3737
path.resolve(this.$projectData.projectDir, "typings"),
38-
this.$options.copyTo
38+
this.$options.copyTo,
3939
);
4040
typingsFolder = this.$options.copyTo;
4141
}
4242

4343
if (result !== false) {
4444
this.$logger.info(
4545
"Typings have been generated in the following directory:",
46-
typingsFolder
46+
typingsFolder,
4747
);
4848
}
4949
}
@@ -56,7 +56,7 @@ export class TypingsCommand implements ICommand {
5656

5757
private async resolveGradleDependencies(target: string) {
5858
const gradleHome = path.resolve(
59-
process.env.GRADLE_USER_HOME ?? path.join(homedir(), `/.gradle`)
59+
process.env.GRADLE_USER_HOME ?? path.join(homedir(), `/.gradle`),
6060
);
6161
const gradleFiles = path.resolve(gradleHome, "caches/modules-2/files-2.1/");
6262

@@ -67,33 +67,32 @@ export class TypingsCommand implements ICommand {
6767

6868
const pattern = `${target.replaceAll(":", "/")}/**/*.{jar,aar}`;
6969

70-
const res = await glob(pattern, {
70+
const items = [];
71+
for await (const item of glob(pattern, {
7172
cwd: gradleFiles,
72-
});
73-
74-
if (!res || res.length === 0) {
75-
this.$logger.warn("No files found");
76-
return [];
77-
}
78-
79-
const items = res.map((item) => {
73+
})) {
8074
const [group, artifact, version, sha1, file] = item.split(path.sep);
81-
return {
75+
items.push({
8276
id: sha1 + version,
8377
group,
8478
artifact,
8579
version,
8680
sha1,
8781
file,
8882
path: path.resolve(gradleFiles, item),
89-
};
90-
});
83+
});
84+
}
85+
86+
if (items.length === 0) {
87+
this.$logger.warn("No files found");
88+
return [];
89+
}
9190

9291
this.$logger.clearScreen();
9392

9493
const choices = await this.$prompter.promptForChoice(
9594
`Select dependencies to generate typings for (${color.greenBright(
96-
target
95+
target,
9796
)})`,
9897
items
9998
.sort((a, b) => {
@@ -108,17 +107,18 @@ export class TypingsCommand implements ICommand {
108107
.map((item) => {
109108
return {
110109
title: `${color.white(item.group)}:${color.greenBright(
111-
item.artifact
112-
)}:${color.yellow(item.version)} - ${color.cyanBright.bold(
113-
item.file
110+
item.artifact,
111+
)}:${color.yellow(item.version)} - ${color.styleText(
112+
["cyanBright", "bold"],
113+
item.file,
114114
)}`,
115115
value: item.id,
116116
};
117117
}),
118118
true,
119119
{
120120
optionsPerPage: process.stdout.rows - 6, // 6 lines are taken up by the instructions
121-
} as Partial<PromptObject>
121+
} as Partial<PromptObject>,
122122
);
123123

124124
this.$logger.clearScreen();
@@ -139,7 +139,7 @@ export class TypingsCommand implements ICommand {
139139
} catch (err) {
140140
this.$logger.trace(
141141
`Failed to resolve gradle dependencies for target "${target}"`,
142-
err
142+
err,
143143
);
144144
}
145145
}
@@ -151,29 +151,29 @@ export class TypingsCommand implements ICommand {
151151
"No .jar or .aar file specified. Please specify at least one of the following:",
152152
" - path to .jar file with --jar <jar>",
153153
" - path to .aar file with --aar <aar>",
154-
].join("\n")
154+
].join("\n"),
155155
);
156156
return false;
157157
}
158158

159159
this.$fs.ensureDirectoryExists(
160-
path.resolve(this.$projectData.projectDir, "typings", "android")
160+
path.resolve(this.$projectData.projectDir, "typings", "android"),
161161
);
162162

163163
const dtsGeneratorPath = path.resolve(
164164
this.$projectData.projectDir,
165165
"platforms",
166166
"android",
167167
"build-tools",
168-
"dts-generator.jar"
168+
"dts-generator.jar",
169169
);
170170
if (!this.$fs.exists(dtsGeneratorPath)) {
171171
this.$logger.warn("No platforms folder found, preparing project now...");
172172
await this.$childProcess.spawnFromEvent(
173173
this.$hostInfo.isWindows ? "ns.cmd" : "ns",
174174
["prepare", "android"],
175175
"exit",
176-
{ stdio: "inherit", shell: this.$hostInfo.isWindows }
176+
{ stdio: "inherit", shell: this.$hostInfo.isWindows },
177177
);
178178
}
179179

@@ -206,7 +206,7 @@ export class TypingsCommand implements ICommand {
206206
path.resolve(this.$projectData.projectDir, "typings", "android"),
207207
],
208208
"exit",
209-
{ stdio: "inherit" }
209+
{ stdio: "inherit" },
210210
);
211211
}
212212

@@ -216,7 +216,7 @@ export class TypingsCommand implements ICommand {
216216
}
217217

218218
this.$fs.ensureDirectoryExists(
219-
path.resolve(this.$projectData.projectDir, "typings", "ios")
219+
path.resolve(this.$projectData.projectDir, "typings", "ios"),
220220
);
221221

222222
await this.$childProcess.spawnFromEvent(
@@ -229,11 +229,11 @@ export class TypingsCommand implements ICommand {
229229
TNS_TYPESCRIPT_DECLARATIONS_PATH: path.resolve(
230230
this.$projectData.projectDir,
231231
"typings",
232-
"ios"
232+
"ios",
233233
),
234234
},
235235
stdio: "inherit",
236-
}
236+
},
237237
);
238238
}
239239
}

0 commit comments

Comments
 (0)