Skip to content

Commit e2cc995

Browse files
committed
feat: Good looking console output
1 parent b8952b6 commit e2cc995

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

src/cli/utils/defineCommand.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ export function defineCommand(cb: (...args: any[]) => void | Promise<void>) {
99

1010
await cb(...args);
1111

12-
consola.success(`Done in ${Date.now() - startTime} ms`);
12+
consola.success(`Finished in ${Date.now() - startTime} ms`);
1313
} catch (err) {
14-
consola.fail(`Command failed after ${Date.now() - startTime} ms`, err);
14+
consola.fail(`Command failed after ${Date.now() - startTime} ms`);
15+
consola.error(err);
1516
process.exit(1);
1617
}
1718
};

src/cli/utils/printHeader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import { version } from '../..';
33
import { consola } from 'consola';
44

55
export function printHeader() {
6-
consola.log(`\n${pc.dim('Exvite')} ${pc.dim(pc.bold(version))}`);
6+
consola.log(`\n${pc.gray('Exvite')} ${pc.gray(pc.bold(version))}`);
77
}

src/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,34 @@ import { generateTypesDir } from './utils/generateTypesDir';
1010
export { version } from '../package.json';
1111
export * from './types/external';
1212
export * from './utils/defineConfig';
13+
import pc from 'picocolors';
1314

1415
/**
1516
* Bundles the extension for production. Returns a promise of the build result.
1617
*/
1718
export async function build(config: InlineConfig): Promise<BuildOutput> {
1819
const internalConfig = await getInternalConfig(config, 'build');
20+
const verb = internalConfig.command === 'serve' ? 'Prerendering' : 'Building';
21+
const target = `${internalConfig.browser}-mv${internalConfig.manifestVersion}`;
22+
internalConfig.logger.info(
23+
`${verb} ${pc.cyan(target)} for ${pc.cyan(internalConfig.mode)}`,
24+
);
25+
26+
// Cleanup
1927
await fs.rm(internalConfig.outDir, { recursive: true, force: true });
2028
await fs.ensureDir(internalConfig.outDir);
2129

30+
// Build
2231
const entrypoints = await findEntrypoints(internalConfig);
2332
await generateTypesDir(entrypoints, internalConfig);
2433
const output = await buildEntrypoints(entrypoints, internalConfig);
2534

35+
// Write manifest
2636
const manifest = await generateMainfest(entrypoints, output, internalConfig);
27-
await writeManifest(manifest, internalConfig);
37+
await writeManifest(manifest, output, internalConfig);
2838

39+
// Post-build
40+
internalConfig.logger.success('Entrypoints built');
2941
await printBuildSummary(output, internalConfig);
3042

3143
return output;

src/types/external.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface Logger {
4242
warn(...args: any[]): void;
4343
error(...args: any[]): void;
4444
fatal(...args: any[]): void;
45+
success(...args: any[]): void;
4546
}
4647

4748
export interface BaseEntrypoint {

src/utils/printBuildSummary.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,32 @@ export async function printBuildSummary(
1717
return lWeight - rWeight;
1818
});
1919

20+
let totalSize = 0;
21+
2022
const chunkRows: string[][] = await Promise.all(
21-
chunks.map(async (chunk) => {
23+
chunks.map(async (chunk, i) => {
2224
const file = [
2325
relative(process.cwd(), config.outDir) + path.sep,
2426
chunk.fileName,
2527
];
2628
const ext = extname(chunk.fileName);
29+
const prefix = i === chunks.length - 1 ? ' └─' : ' ├─';
2730
const color = CHUNK_COLORS[ext] ?? DEFAULT_COLOR;
2831
const stats = await fs.lstat(resolve(config.outDir, chunk.fileName));
32+
totalSize += stats.size;
2933
const size = String(filesize(stats.size));
30-
return [`${pc.dim(file[0])}${color(file[1])}`, pc.dim(size)];
34+
return [
35+
`${pc.gray(prefix)} ${pc.dim(file[0])}${color(file[1])}`,
36+
pc.dim(size),
37+
];
3138
}),
3239
);
3340

34-
printTable(config.logger.log, [['Chunks'], ...chunkRows]);
41+
printTable(config.logger.log, chunkRows);
42+
43+
config.logger.log(
44+
`${pc.cyan('Σ Total size:')} ${String(filesize(totalSize))}`,
45+
);
3546
}
3647

3748
const DEFAULT_SORT_WEIGHT = 100;

src/utils/printTable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function printTable(
2121
str += col.padEnd(columnWidths[j], ' ');
2222
if (j !== row.length - 1) str += ''.padEnd(gap, ' ');
2323
});
24-
str += '\n';
24+
if (i !== rows.length - 1) str += '\n';
2525
});
2626

2727
log(str);

0 commit comments

Comments
 (0)