Skip to content

Commit d53d5e4

Browse files
committed
refactor: migrate to kleur from chalk
1 parent c3e4bfb commit d53d5e4

File tree

13 files changed

+93
-107
lines changed

13 files changed

+93
-107
lines changed

packages/create-react-native-library/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
"prepare": "babel --extensions .ts,.tsx src --out-dir lib --ignore '**/__tests__/**' --source-maps --delete-dir-on-start"
4343
},
4444
"dependencies": {
45-
"chalk": "^4.1.2",
4645
"cross-spawn": "^7.0.3",
4746
"dedent": "^0.7.0",
4847
"ejs": "^3.1.8",
4948
"fs-extra": "^10.1.0",
5049
"github-username": "^6.0.0",
50+
"kleur": "^4.1.4",
5151
"prompts": "^2.4.2",
5252
"validate-npm-package-name": "^4.0.0",
5353
"yargs": "^17.5.1"
@@ -61,7 +61,6 @@
6161
"@babel/preset-env": "^7.18.2",
6262
"@babel/preset-typescript": "^7.17.12",
6363
"@commitlint/config-conventional": "^17.0.2",
64-
"@types/chalk": "^2.2.0",
6564
"@types/cross-spawn": "^6.0.2",
6665
"@types/dedent": "^0.7.0",
6766
"@types/ejs": "^3.1.1",

packages/create-react-native-library/src/index.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'path';
22
import fs from 'fs-extra';
33
import ejs from 'ejs';
44
import dedent from 'dedent';
5-
import chalk from 'chalk';
5+
import kleur from 'kleur';
66
import yargs from 'yargs';
77
import spawn from 'cross-spawn';
88
import validateNpmPackage from 'validate-npm-package-name';
@@ -128,7 +128,7 @@ async function create(argv: yargs.Arguments<any>) {
128128

129129
if (await fs.pathExists(folder)) {
130130
console.log(
131-
`A folder already exists at ${chalk.blue(
131+
`A folder already exists at ${kleur.blue(
132132
folder
133133
)}! Please specify another folder name or delete the existing one.`
134134
);
@@ -427,29 +427,35 @@ async function create(argv: yargs.Arguments<any>) {
427427
// Ignore error
428428
}
429429

430-
const platforms: Record<string, { name: string; color: string }> = {
430+
const platforms = {
431431
ios: { name: 'iOS', color: 'cyan' },
432432
android: { name: 'Android', color: 'green' },
433-
...(example === 'expo' ? { web: { name: 'Web', color: 'blue' } } : null),
434-
};
433+
...(example === 'expo'
434+
? ({ web: { name: 'Web', color: 'blue' } } as const)
435+
: null),
436+
} as const;
435437

436438
console.log(
437-
dedent(chalk`
438-
Project created successfully at {yellow ${argv.name}}!
439+
dedent(`
440+
Project created successfully at ${kleur.yellow(argv.name)}!
439441
440-
{magenta {bold Get started} with the project}{gray :}
442+
${kleur.magenta(
443+
`${kleur.bold('Get started')} with the project`
444+
)}${kleur.gray(':')}
441445
442-
{gray $} yarn
446+
${kleur.gray('$')} yarn
443447
${Object.entries(platforms)
444448
.map(
445-
([script, { name, color }]) => chalk`
446-
{${color} Run the example app on {bold ${name}}}{gray :}
449+
([script, { name, color }]) => `
450+
${kleur[color](`Run the example app on ${kleur.bold(name)}`)}${kleur.gray(
451+
':'
452+
)}
447453
448-
{gray $} yarn example ${script}`
454+
${kleur.gray('$')} yarn example ${script}`
449455
)
450456
.join('\n')}
451457
452-
{yellow Good luck!}
458+
${kleur.yellow('Good luck!')}
453459
`)
454460
);
455461
}

packages/react-native-builder-bob/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"@babel/preset-react": "^7.17.12",
4444
"@babel/preset-typescript": "^7.17.12",
4545
"browserslist": "^4.20.4",
46-
"chalk": "^4.1.2",
4746
"cosmiconfig": "^7.0.1",
4847
"cross-spawn": "^7.0.3",
4948
"dedent": "^0.7.0",
@@ -52,6 +51,7 @@
5251
"glob": "^8.0.3",
5352
"is-git-dirty": "^2.0.1",
5453
"json5": "^2.2.1",
54+
"kleur": "^4.1.4",
5555
"prompts": "^2.4.2",
5656
"which": "^2.0.2",
5757
"yargs": "^17.5.1"
@@ -63,7 +63,6 @@
6363
"@babel/cli": "^7.17.10",
6464
"@types/babel__core": "^7.1.19",
6565
"@types/browserslist": "^4.15.0",
66-
"@types/chalk": "^2.2.0",
6766
"@types/cross-spawn": "^6.0.2",
6867
"@types/dedent": "^0.7.0",
6968
"@types/del": "^4.0.0",

packages/react-native-builder-bob/src/index.ts

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path';
22
import fs from 'fs-extra';
3-
import chalk from 'chalk';
3+
import kleur from 'kleur';
44
import dedent from 'dedent';
55
import yargs from 'yargs';
66
import { cosmiconfigSync } from 'cosmiconfig';
@@ -317,14 +317,16 @@ yargs
317317
}
318318

319319
console.log(
320-
dedent(chalk`
321-
Project {yellow ${pkg.name}} configured successfully!
320+
dedent(`
321+
Project ${kleur.yellow(pkg.name)} configured successfully!
322322
323-
{magenta {bold Perform last steps} by running}{gray :}
323+
${kleur.magenta(
324+
`${kleur.bold('Perform last steps')} by running`
325+
)}${kleur.gray(':')}
324326
325-
{gray $} yarn
327+
${kleur.gray(':')} yarn
326328
327-
{yellow Good luck!}
329+
${kleur.yellow('Good luck!')}
328330
`)
329331
);
330332
})
@@ -381,7 +383,7 @@ yargs
381383
const targetName = Array.isArray(target) ? target[0] : target;
382384
const targetOptions = Array.isArray(target) ? target[1] : undefined;
383385

384-
report.info(`Building target ${chalk.blue(targetName)}`);
386+
report.info(`Building target ${kleur.blue(targetName)}`);
385387

386388
switch (targetName) {
387389
case 'aar':
@@ -421,28 +423,10 @@ yargs
421423
});
422424
break;
423425
default:
424-
logger.exit(`Invalid target ${chalk.blue(targetName)}.`);
426+
logger.exit(`Invalid target ${kleur.blue(targetName)}.`);
425427
}
426428
}
427429
})
428-
.command(
429-
'create <name>',
430-
'create a react native library (deprecated)',
431-
{},
432-
(argv) => {
433-
console.log(
434-
dedent(chalk`
435-
The {magenta create} command has been moved to {magenta create-react-native-library}!
436-
437-
Please run:
438-
439-
{gray $} npx create-react-native-library ${argv.name}
440-
441-
Good luck!
442-
`)
443-
);
444-
}
445-
)
446430
.demandCommand()
447431
.recommendCommands()
448432
.strict().argv;

packages/react-native-builder-bob/src/targets/aar.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path';
2-
import chalk from 'chalk';
2+
import kleur from 'kleur';
33
import fs from 'fs-extra';
44
import del from 'del';
55
import androidAssemble from '../utils/androidAssemble';
@@ -42,7 +42,7 @@ export default async function build({
4242
};
4343

4444
report.info(
45-
`Cleaning up previous build at ${chalk.blue(path.relative(root, output))}`
45+
`Cleaning up previous build at ${kleur.blue(path.relative(root, output))}`
4646
);
4747

4848
await del([output]);
@@ -54,7 +54,7 @@ export default async function build({
5454
});
5555

5656
report.info(
57-
`Creating new output directory at ${chalk.blue(
57+
`Creating new output directory at ${kleur.blue(
5858
path.relative(root, output)
5959
)}`
6060
);
@@ -70,22 +70,22 @@ export default async function build({
7070
const targetAar = path.join(output, targetOptions.androidBundleName);
7171

7272
report.info(
73-
`Copying AAR from ${chalk.blue(
73+
`Copying AAR from ${kleur.blue(
7474
path.relative(root, sourceAar)
75-
)} to ${chalk.blue(path.relative(root, targetAar))}`
75+
)} to ${kleur.blue(path.relative(root, targetAar))}`
7676
);
7777
await fs.copyFile(sourceAar, targetAar);
7878

7979
const gradleFile = path.join(output, 'build.gradle');
8080
report.info(
81-
`Creating AAR Gradle file at ${chalk.blue(path.relative(root, gradleFile))}`
81+
`Creating AAR Gradle file at ${kleur.blue(path.relative(root, gradleFile))}`
8282
);
8383
await createGradleFile(gradleFile);
8484

8585
if (targetOptions.reverseJetify) {
8686
const supportOutputPath = path.join(output, 'support');
8787
report.info(
88-
`Creating new support output directory at ${chalk.blue(
88+
`Creating new support output directory at ${kleur.blue(
8989
path.relative(root, supportOutputPath)
9090
)}`
9191
);
@@ -96,7 +96,7 @@ export default async function build({
9696
targetOptions.androidBundleName
9797
);
9898
report.info(
99-
`Using Jetifier to convert AAR from AndroidX to Support AAR at ${chalk.blue(
99+
`Using Jetifier to convert AAR from AndroidX to Support AAR at ${kleur.blue(
100100
path.relative(root, supportAar)
101101
)}`
102102
);
@@ -111,12 +111,12 @@ export default async function build({
111111

112112
const supportGradleFile = path.join(supportOutputPath, 'build.gradle');
113113
report.info(
114-
`Creating Support AAR Gradle file at ${chalk.blue(
114+
`Creating Support AAR Gradle file at ${kleur.blue(
115115
path.relative(root, supportGradleFile)
116116
)}`
117117
);
118118
await createGradleFile(supportGradleFile);
119119
}
120120

121-
report.success(`Wrote files to ${chalk.blue(path.relative(root, output))}`);
121+
report.success(`Wrote files to ${kleur.blue(path.relative(root, output))}`);
122122
}

packages/react-native-builder-bob/src/targets/commonjs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path';
2-
import chalk from 'chalk';
2+
import kleur from 'kleur';
33
import del from 'del';
44
import compile from '../utils/compile';
55
import type { Input } from '../types';
@@ -20,7 +20,7 @@ export default async function build({
2020
report,
2121
}: Options) {
2222
report.info(
23-
`Cleaning up previous build at ${chalk.blue(path.relative(root, output))}`
23+
`Cleaning up previous build at ${kleur.blue(path.relative(root, output))}`
2424
);
2525

2626
await del([output]);

packages/react-native-builder-bob/src/targets/module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path';
2-
import chalk from 'chalk';
2+
import kleur from 'kleur';
33
import del from 'del';
44
import compile from '../utils/compile';
55
import type { Input } from '../types';
@@ -20,7 +20,7 @@ export default async function build({
2020
report,
2121
}: Options) {
2222
report.info(
23-
`Cleaning up previous build at ${chalk.blue(path.relative(root, output))}`
23+
`Cleaning up previous build at ${kleur.blue(path.relative(root, output))}`
2424
);
2525

2626
await del([output]);

packages/react-native-builder-bob/src/targets/typescript.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from 'chalk';
1+
import kleur from 'kleur';
22
import path from 'path';
33
import fs from 'fs-extra';
44
import which from 'which';
@@ -19,12 +19,12 @@ export default async function build({
1919
options,
2020
}: Options) {
2121
report.info(
22-
`Cleaning up previous build at ${chalk.blue(path.relative(root, output))}`
22+
`Cleaning up previous build at ${kleur.blue(path.relative(root, output))}`
2323
);
2424

2525
await del([output]);
2626

27-
report.info(`Generating type definitions with ${chalk.blue('tsc')}`);
27+
report.info(`Generating type definitions with ${kleur.blue('tsc')}`);
2828

2929
const project = options?.project ? options.project : 'tsconfig.json';
3030
const tsconfig = path.join(root, project);
@@ -58,11 +58,11 @@ export default async function build({
5858

5959
if (conflicts.length) {
6060
report.warn(
61-
`Found following options in the config file which can conflict with the CLI options. Please remove them from ${chalk.blue(
61+
`Found following options in the config file which can conflict with the CLI options. Please remove them from ${kleur.blue(
6262
project
6363
)}:${conflicts.reduce(
6464
(acc, curr) =>
65-
acc + `\n${chalk.gray('-')} ${chalk.yellow(curr)}`,
65+
acc + `\n${kleur.gray('-')} ${kleur.yellow(curr)}`,
6666
''
6767
)}`
6868
);
@@ -75,7 +75,7 @@ export default async function build({
7575
}
7676
} else {
7777
throw new Error(
78-
`Couldn't find a ${chalk.blue('tsconfig.json')} in the project root.`
78+
`Couldn't find a ${kleur.blue('tsconfig.json')} in the project root.`
7979
);
8080
}
8181

@@ -89,11 +89,11 @@ export default async function build({
8989
tsc = await which('tsc');
9090

9191
report.warn(
92-
`Using a global version of ${chalk.blue(
92+
`Using a global version of ${kleur.blue(
9393
'tsc'
94-
)}. Consider adding ${chalk.blue('typescript')} to your ${chalk.blue(
94+
)}. Consider adding ${kleur.blue('typescript')} to your ${kleur.blue(
9595
'devDependencies'
96-
)} or specifying the ${chalk.blue(
96+
)} or specifying the ${kleur.blue(
9797
'tsc'
9898
)} option for the typescript target.`
9999
);
@@ -104,13 +104,13 @@ export default async function build({
104104

105105
if (!(await fs.pathExists(tsc))) {
106106
throw new Error(
107-
`The ${chalk.blue(
107+
`The ${kleur.blue(
108108
'tsc'
109-
)} binary doesn't seem to be installed under ${chalk.blue(
109+
)} binary doesn't seem to be installed under ${kleur.blue(
110110
'node_modules'
111-
)} or present in $PATH. Make sure you have added ${chalk.blue(
111+
)} or present in $PATH. Make sure you have added ${kleur.blue(
112112
'typescript'
113-
)} to your ${chalk.blue('devDependencies')} or specify the ${chalk.blue(
113+
)} to your ${kleur.blue('devDependencies')} or specify the ${kleur.blue(
114114
'tsc'
115115
)} option for typescript.`
116116
);
@@ -145,7 +145,7 @@ export default async function build({
145145
await del([tsbuildinfo]);
146146

147147
report.success(
148-
`Wrote definition files to ${chalk.blue(path.relative(root, output))}`
148+
`Wrote definition files to ${kleur.blue(path.relative(root, output))}`
149149
);
150150
} else {
151151
throw new Error('Failed to build definition files.');

0 commit comments

Comments
 (0)