-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
101 lines (97 loc) · 2.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#! /usr/bin/env node
import inquirer from "inquirer";
import fs from "fs";
import { fileURLToPath } from "url";
import { dirname } from "path";
import nodeExpress from "./configs/nodeExpress.js";
import staticFile from "./configs/static.js ";
import commonConfig from "./configs/commonConfig.js";
const existingConfig = fs.existsSync("config.json");
const filename = fileURLToPath(import.meta.url);
const __dirname = dirname(filename);
const currFile = new URL(import.meta.url).pathname.split("/").pop();
async function buildConfig() {
let config = {
version: 2,
};
const answers = await inquirer.prompt([
{
type: "text",
name: "name",
message: "What is the name of your project?",
default: currFile,
},
{
type: "list",
name: "type",
message: "What is the type of your project?",
choices: ["node-express", "static", "react", "vue", "static-build"],
},
]);
config.name = answers.name;
switch (answers.type) {
case "node-express":
config = await nodeExpress(config);
break;
case "static":
config = await staticFile(config);
break;
case "react":
config = await commonConfig(config,'build');
break;
case "vue":
config = await commonConfig(config);
break;
case "static-build":
config = await commonConfig(config);
break;
}
const aliases = await inquirer.prompt([
{
type: "confirm",
name: "specifyAlias",
message: "Would you like to specify an alias?(Specify multiple separated by commas)",
default: true,
},
{
type: "text",
name: "alias",
message: "Mention the alias?",
default: answers.name,
when: a => a.specifyAlias,
},
// {
// type: "confirm",
// name: "deploy",
// message: "Would you like to deploy?",
// default: false,
// },
]);
config.alias = aliases.alias?aliases.alias.split(','):undefined;
fs.writeFileSync("config.json",JSON.stringify(config,null,2),'utf-8');
console.log('All done!');
process.exit(0);
if(aliases.deploy){
}
console.log(config);
}
if (existingConfig) {
inquirer
.prompt([
{
type: "confirm",
name: "overwrite",
message: "config.json already exists.Do you want to overwrite?",
default: false,
},
])
.then((answers) => {
if (answers.overwrite) {
buildConfig();
} else {
console.log("OK cool");
}
});
}else{
buildConfig();
}