-
-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create commander cli and implement skip feat
created commander cli implement init command with -s -f flags to skip and -f to override
- Loading branch information
Showing
1 changed file
with
39 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,46 @@ | ||
import { Command } from "commander"; | ||
const program = new Command(); | ||
import { resolve, join } from "path"; | ||
import nodePlop from "node-plop"; | ||
// Cspell:ignore plopfile, plopfile.js | ||
|
||
import pkg from "../package.json" with { type: "json" }; | ||
const program = new Command(); | ||
const plop = await nodePlop("./lib/plopfile.js"); | ||
const defaultValues = { | ||
init: { | ||
projectName: "webpack-project", | ||
projectPath: resolve(join(process.cwd(), ".")), | ||
langType: "none", | ||
devServer: true, | ||
htmlWebpackPlugin: true, | ||
workboxWebpackPlugin: true, | ||
cssType: "CSS only", | ||
isCSS: true, | ||
isPostCSS: true, | ||
extractPlugin: "No", | ||
packageManager: "npm", | ||
}, | ||
}; | ||
|
||
program.version(pkg.version, "-v, --version"); | ||
program.version("1.0.0", "-v, --version"); | ||
program.helpOption("-h, --help", "Display help for command"); | ||
|
||
program | ||
.option("-s, --skip", "Skip the prompt and use the default values") | ||
.option("-f, --force", "Force the generator actions to override existing files"); | ||
|
||
program.parse(process.argv); | ||
.command("init") | ||
.description("Initialize a new Webpack project") | ||
.option("-s, --skip", "Skip the prompt and use the default values", false) | ||
.option("-f, --force", "Force the generator actions to override existing files", false) | ||
.action(function (opts) { | ||
console.log("Initializing a new Webpack project"); | ||
const { skip, force } = opts; | ||
const initGenerator = plop.getGenerator("init"); | ||
if (skip) { | ||
console.log("Skipping the prompt and using the default values"); | ||
initGenerator.runActions(defaultValues.init); | ||
} else { | ||
initGenerator.runPrompts([]).then((answers) => { | ||
initGenerator.runActions(answers); | ||
}); | ||
} | ||
}); | ||
|
||
console.log(program.opts()); | ||
program.parse(); |