1 | const program = require("commander");
|
2 | const inquirer = require("inquirer");
|
3 | const path = require("path");
|
4 | const parseGitConfig = require("parse-git-config");
|
5 | const gitConfigPath = require("git-config-path");
|
6 |
|
7 | const cli = require("../dist");
|
8 |
|
9 | function gitUser() {
|
10 | const gitConfig = parseGitConfig.sync({ cwd: "/", path: gitConfigPath("global") });
|
11 | return Object.assign({ name: "", email: "" }, gitConfig.user);
|
12 | }
|
13 |
|
14 | program
|
15 | .option("-si, --skip-install", "skip installation")
|
16 | .option("-t, --template <name>", "all templates: module, react, react-redux, service, tcp")
|
17 | .parse(process.argv);
|
18 |
|
19 | const dest = program.args[0] || ".";
|
20 | const baseFolderName = path.basename(path.resolve(process.cwd(), dest));
|
21 | const questions = [
|
22 | {
|
23 | type: "list",
|
24 | name: "template",
|
25 | message: "which boilerplate do you want use:",
|
26 | choices: ["module", "react", "react-redux", "service", "tcp"],
|
27 | when: () => !program.template,
|
28 | },
|
29 | {
|
30 | name: "name",
|
31 | message: "What is your package name?",
|
32 | default: baseFolderName,
|
33 | },
|
34 | {
|
35 | name: "owner",
|
36 | message: "Who is package's owner?",
|
37 | default: gitUser().name,
|
38 | },
|
39 | {
|
40 | name: "scope",
|
41 | message: "What is the package scope?",
|
42 | default: "",
|
43 | },
|
44 | ];
|
45 |
|
46 | inquirer
|
47 | .prompt(questions)
|
48 | .then(answers => {
|
49 | const template = program.template || answers.template;
|
50 | return cli.init(template, dest, answers);
|
51 | })
|
52 | .catch(err => console.error(err));
|