feat: add micro cli for initializing the config

This commit is contained in:
Igor Randjelovic
2020-11-23 16:27:33 +01:00
committed by Nathan Walker
parent 6448303425
commit 19e38f8c2f
3 changed files with 45 additions and 1 deletions

View File

@ -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",

View 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);

View File

@ -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;