mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
feat: add micro cli for initializing the config
This commit is contained in:

committed by
Nathan Walker

parent
6448303425
commit
19e38f8c2f
@ -6,18 +6,23 @@
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"bin": {
|
||||
"nativescript-webpack": "dist/bin/index.js"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "jest",
|
||||
"prepack": "npm run build && cp -R src/stubs dist/stubs"
|
||||
"prepack": "npm run build && cp -R src/stubs dist/stubs && chmod +x dist/bin/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.12.3",
|
||||
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
|
||||
"babel-loader": "^8.2.1",
|
||||
"chalk": "^4.1.0",
|
||||
"clean-webpack-plugin": "^3.0.0",
|
||||
"cli-highlight": "^2.1.8",
|
||||
"commander": "^6.2.0",
|
||||
"copy-webpack-plugin": "^6.3.2",
|
||||
"css": "^3.0.0",
|
||||
"css-loader": "^5.0.1",
|
||||
|
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);
|
@ -11,6 +11,7 @@ export enum messages {
|
||||
/**
|
||||
* This little plugin will report the webpack state through the console.
|
||||
* So the {N} CLI can get some idea when compilation completes.
|
||||
* @deprecated todo: remove soon
|
||||
*/
|
||||
export class WatchStateLoggerPlugin {
|
||||
isRunningWatching: boolean;
|
||||
|
Reference in New Issue
Block a user