-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
120 lines (92 loc) · 3.18 KB
/
index.js
File metadata and controls
120 lines (92 loc) · 3.18 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env node
const degit = require("degit");
const templates = require("./templates");
const chalk = require("chalk");
const { AutoComplete } = require("enquirer");
console.log(chalk.cyanBright("solid-cli") + chalk.gray("@" + require("./package.json").version) + "\n")
const args = process.argv.splice(2);
const usages = {
init: {
command: "init [template] <app-name>",
description: "initializes a new project from a template"
}
}
function successMessage(appName, template) {
console.log(
`\n` + chalk.green("SUCCESS:") + ` The setup is now complete for '${appName}' with the '${template}' template` +
`\n\n` +
`You may now run the following commands:` +
`\n\n` +
` cd ${appName}` +
`\n` +
` npm start` +
`\n\n\n\n` +
`Happy coding!`
);
}
function templateQuery() {
let templateNames = [];
templates.forEach(t => templateNames.push(t.name));
const prompt = new AutoComplete({
name: "template",
message: "Pick the template that best suits your needs",
choices: templateNames,
})
return prompt.run();
}
(async function () {
switch (args[0]) {
case "init": {
var template = args.length === 2 ? undefined : args[1];
const appName = args.length === 2 ? args[1] : args[2];
if (!appName) {
console.log(
chalk.redBright("ERR:") + " Please give your project a name" +
`\n\n` +
`Usage: ${usages.init.command}`
);
return;
}
if (!template) {
template = await templateQuery();
}
//checks wether the user inputted template exists in the templates
const templateObj = templates.find((v => v.name === template));
//the template was not found
if (!templateObj) {
console.log(chalk.redBright("ERR:") + ` template '${template}' was not found from the available templates`);
return
}
//the template was found - continue
const emitter = degit(templateObj.repo);
emitter.on("warn", m => {
console.log(chalk.yellow("WARN: " + m.message))
})
emitter.clone(appName).then(() => successMessage(appName, template))
break;
}
case "templates":
var rendered = "";
templates.forEach(template => {
rendered += `\n ${template.name}`;
rendered += " " + chalk.gray(template.description) + `\n`;
});
console.log(
`Templates:` +
`\n` +
rendered
)
break;
default:
console.log(
`Usage: solid <command> [options]` +
`\n\n` +
`Commands:` +
`\n` +
` ${usages.init.command} ${usages.init.description}` +
`\n` +
` templates shows the available templates`
)
break;
}
})();