Skip to content

Commit 6e215b4

Browse files
committed
fix: tweak the message styles
1 parent c75df5d commit 6e215b4

File tree

9 files changed

+70
-50
lines changed

9 files changed

+70
-50
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"inquirer": "^6.2.2",
3535
"is-git-dirty": "^1.0.0",
3636
"metro-react-native-babel-preset": "^0.53.1",
37-
"ora": "^3.3.0",
3837
"yargs": "^13.2.2"
3938
},
4039
"devDependencies": {
@@ -49,7 +48,6 @@
4948
"@types/fs-extra": "^5.0.5",
5049
"@types/glob": "^7.1.1",
5150
"@types/inquirer": "^6.0.0",
52-
"@types/ora": "^3.2.0",
5351
"@types/yargs": "^12.0.11",
5452
"commitlint": "^7.5.2",
5553
"conventional-changelog-cli": "^2.0.12",

src/cli.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'path';
22
import fs from 'fs-extra';
3+
import chalk from 'chalk';
34
import yargs from 'yargs';
45
import inquirer from 'inquirer';
56
import cosmiconfig from 'cosmiconfig';
@@ -148,7 +149,11 @@ yargs
148149
pkg.scripts.prepare = prepare;
149150
}
150151

151-
if (pkg.files) {
152+
if (
153+
pkg.files &&
154+
JSON.stringify(pkg.files.slice().sort()) !==
155+
JSON.stringify(files.slice().sort())
156+
) {
152157
const { replace } = await inquirer.prompt({
153158
type: 'confirm',
154159
name: 'replace',
@@ -190,7 +195,7 @@ yargs
190195
}
191196
}
192197

193-
console.log('🎉 Your project is configured!');
198+
logger.success('Your project is configured!');
194199
})
195200
.command('build', 'build files for publishing', {}, async argv => {
196201
const result = explorer.searchSync();
@@ -236,36 +241,48 @@ yargs
236241
);
237242
}
238243

244+
const report = {
245+
info: logger.info,
246+
warn: logger.warn,
247+
error: logger.error,
248+
success: logger.success,
249+
};
250+
239251
for (const target of options.targets!) {
240252
const targetName = Array.isArray(target) ? target[0] : target;
241253
const targetOptions = Array.isArray(target) ? target[1] : undefined;
242254

255+
report.info(`Building target ${chalk.blue(targetName)}`);
256+
243257
switch (targetName) {
244258
case 'commonjs':
245259
await buildCommonJS({
246260
root,
247-
source: source as string,
261+
source: path.resolve(root, source as string),
248262
output: path.resolve(root, output as string, 'commonjs'),
249263
options: targetOptions,
264+
report,
250265
});
251266
break;
252267
case 'module':
253268
await buildModule({
254269
root,
255-
source: source as string,
270+
source: path.resolve(root, source as string),
256271
output: path.resolve(root, output as string, 'module'),
257272
options: targetOptions,
273+
report,
258274
});
259275
break;
260276
case 'typescript':
261277
await buildTypescript({
262278
root,
263-
source: source as string,
279+
source: path.resolve(root, source as string),
264280
output: path.resolve(root, output as string, 'typescript'),
281+
report,
265282
});
266283
break;
267284
default:
268-
logger.exit(`Invalid target '${target}'.`);
285+
logger.exit(`Invalid target ${chalk.blue(targetName)}.`);
269286
}
270287
}
271288
})

src/targets/commonjs.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import del from 'del';
22
import compile from '../utils/compile';
3-
import * as logger from '../utils/logger';
43
import { Input } from '../types';
54

65
type Options = Input & {
@@ -12,10 +11,12 @@ export default async function build({
1211
source,
1312
output,
1413
options,
14+
report
1515
}: Options) {
16-
logger.info('building files for commonjs target');
16+
report.info('Cleaning up previous build');
1717

1818
await del([output]);
19+
1920
await compile({
2021
root,
2122
source,
@@ -24,5 +25,6 @@ export default async function build({
2425
presets: [[require.resolve('metro-react-native-babel-preset')]],
2526
},
2627
flow: options && options.flow ? true : false,
28+
report
2729
});
2830
}

src/targets/module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import del from 'del';
22
import compile from '../utils/compile';
3-
import * as logger from '../utils/logger';
43
import { Input } from '../types';
54

65
type Options = Input & {
@@ -12,10 +11,12 @@ export default async function build({
1211
source,
1312
output,
1413
options,
14+
report
1515
}: Options) {
16-
logger.info('building files for module target');
16+
report.info('Cleaning up previous build');
1717

1818
await del([output]);
19+
1920
await compile({
2021
root,
2122
source,
@@ -29,5 +30,6 @@ export default async function build({
2930
],
3031
},
3132
flow: options && options.flow ? true : false,
33+
report
3234
});
3335
}

src/targets/typescript.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1+
import chalk from 'chalk';
12
import path from 'path';
23
import child_process from 'child_process';
34
import del from 'del';
4-
import * as logger from '../utils/logger';
55
import { Input } from '../types';
66

7-
export default async function build({ root, output }: Input) {
8-
logger.info('building files for typscript target');
7+
export default async function build({ root, output, report }: Input) {
8+
report.info('Cleaning up previous build');
99

1010
await del([output]);
1111

12+
report.info(`Generating type definitions with ${chalk.blue('tsc')}`);
13+
1214
child_process.execFileSync(path.join(root, 'node_modules', '.bin', 'tsc'), [
1315
'--declaration',
1416
'--emitDeclarationOnly',
1517
'--outDir',
1618
output,
1719
]);
1820

19-
logger.info(`wrote definition files to ${path.relative(root, output)}`);
21+
report.success(
22+
`Wrote definition files to ${chalk.blue(path.relative(root, output))}`
23+
);
2024
}

src/types.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1+
export type Log = (message: string) => void;
2+
13
export type Input = {
2-
root: string,
3-
source: string,
4-
output: string,
4+
root: string;
5+
source: string;
6+
output: string;
7+
report: {
8+
info: Log;
9+
warn: Log;
10+
success: Log;
11+
error: Log;
12+
};
513
};
614

715
export type Target = 'commonjs' | 'module' | 'typescript';
816

917
export type Options = {
10-
source?: string,
11-
output?: string,
12-
targets?: Array<Target | [Target, object]>
13-
}
18+
source?: string;
19+
output?: string;
20+
targets?: Array<Target | [Target, object]>;
21+
};

src/utils/compile.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import path from 'path';
22
import fs from 'fs-extra';
3+
import chalk from 'chalk';
34
import * as babel from '@babel/core';
45
import glob from 'glob';
56
import { Input } from '../types';
6-
import * as logger from './logger';
77

88
type Options = Input & {
99
options: babel.TransformOptions;
10-
flow: boolean,
10+
flow: boolean;
1111
};
1212

1313
export default async function compile({
1414
root,
1515
source,
1616
output,
1717
options,
18-
flow
18+
flow,
19+
report,
1920
}: Options) {
2021
const files = glob.sync('**/*', {
2122
cwd: source,
@@ -24,6 +25,12 @@ export default async function compile({
2425
ignore: '**/__tests__/**,**/__fixtures__/**',
2526
});
2627

28+
report.info(
29+
`Compiling ${chalk.blue(String(files.length))} files in ${chalk.blue(
30+
path.relative(root, source)
31+
)} with ${chalk.blue('babel')}`
32+
);
33+
2734
await Promise.all(
2835
files.map(async filepath => {
2936
const outputFilename = path
@@ -68,5 +75,5 @@ export default async function compile({
6875
})
6976
);
7077

71-
logger.info(`built ${files.length} files in ${path.relative(root, source)} to ${path.relative(root, output)}`);
78+
report.success(`Wrote files to ${chalk.blue(path.relative(root, output))}`);
7279
}

src/utils/logger.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import chalk from 'chalk';
22

33
const logger = (type: string, color: Function) => (...messages: unknown[]) => {
4-
console.log(color(`[${type}]`), ...messages);
4+
console.log(color(chalk.bold(type)), ...messages);
55
};
66

7-
export const info = logger('info', chalk.blue);
8-
export const warn = logger('warn', chalk.yellow);
9-
export const error = logger('error', chalk.red);
7+
export const info = logger('ℹ', chalk.blue);
8+
export const warn = logger('⚠', chalk.yellow);
9+
export const error = logger('✖', chalk.red);
10+
export const success = logger('✓', chalk.green);
1011

1112
export const exit = (...messages: unknown[]) => {
1213
error(...messages);

yarn.lock

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,13 +1074,6 @@
10741074
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.11.6.tgz#df929d1bb2eee5afdda598a41930fe50b43eaa6a"
10751075
integrity sha512-Exw4yUWMBXM3X+8oqzJNRqZSwUAaS4+7NdvHqQuFi/d+synz++xmX3QIf+BFqneW8N31R8Ky+sikfZUXq07ggQ==
10761076

1077-
"@types/ora@^3.2.0":
1078-
version "3.2.0"
1079-
resolved "https://registry.yarnpkg.com/@types/ora/-/ora-3.2.0.tgz#b2f65d1283a8f36d8b0f9ee767e0732a2f429362"
1080-
integrity sha512-jll99xUKpiFbIFZSQcxm4numfsLaOWBzWNaRk3PvTSE7BPqTzzOCFmS0mQ7m8qkTfmYhuYbehTGsxkvRLPC++w==
1081-
dependencies:
1082-
ora "*"
1083-
10841077
"@types/through@*":
10851078
version "0.0.29"
10861079
resolved "https://registry.yarnpkg.com/@types/through/-/through-0.0.29.tgz#72943aac922e179339c651fa34a4428a4d722f93"
@@ -3808,18 +3801,6 @@ optimist@^0.6.1:
38083801
minimist "~0.0.1"
38093802
wordwrap "~0.0.2"
38103803

3811-
ora@*, ora@^3.3.0:
3812-
version "3.3.0"
3813-
resolved "https://registry.yarnpkg.com/ora/-/ora-3.3.0.tgz#9b3b6b03ba2dac40c7c7ce144cca76a0f1abb351"
3814-
integrity sha512-DTFh3rat9CftF9ldG++sa7ci6KocASWvm6aqNzuXnl8uNCkDprM39f8oZwnXnWoNIcbLYeBuPrruQ4+0+Bf0PA==
3815-
dependencies:
3816-
chalk "^2.4.2"
3817-
cli-cursor "^2.1.0"
3818-
cli-spinners "^2.0.0"
3819-
log-symbols "^2.2.0"
3820-
strip-ansi "^5.0.0"
3821-
wcwidth "^1.0.1"
3822-
38233804
38243805
version "3.2.0"
38253806
resolved "https://registry.yarnpkg.com/ora/-/ora-3.2.0.tgz#67e98a7e11f7f0ac95deaaaf11bb04de3d09e481"

0 commit comments

Comments
 (0)