mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 13:51:27 +08:00
feat: add micro cli for initializing the config
This commit is contained in:
38
packages/webpack5/src/bin/index.ts
Normal file
38
packages/webpack5/src/bin/index.ts
Normal file
@ -0,0 +1,38 @@
|
||||
#!/user/bin/env node
|
||||
|
||||
import { redBright, green, greenBright } from 'chalk';
|
||||
import { program } from 'commander';
|
||||
import dedent from 'ts-dedent';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
const defaultConfig = path.resolve(
|
||||
__dirname,
|
||||
'../stubs/default.config.stub.js'
|
||||
);
|
||||
const tag = `[${green('@nativescript/webpack')}]`;
|
||||
|
||||
function error(message: string) {
|
||||
console.error(`${tag} ${redBright(dedent(message))}`);
|
||||
}
|
||||
|
||||
function info(message: string) {
|
||||
console.info(`${tag} ${greenBright(dedent(message))}`);
|
||||
}
|
||||
|
||||
program
|
||||
.command('init')
|
||||
.description('Initialize a new webpack.config.js in the current directory.')
|
||||
.action(() => {
|
||||
const targetPath = path.resolve(process.cwd(), 'webpack.config.js');
|
||||
|
||||
if (fs.existsSync(targetPath)) {
|
||||
return error(`File Already Exists: ${targetPath}`);
|
||||
}
|
||||
|
||||
fs.copyFileSync(defaultConfig, targetPath);
|
||||
|
||||
info('Initialized config.');
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
Reference in New Issue
Block a user