-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.js
105 lines (100 loc) · 2.89 KB
/
configure.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
102
103
104
105
#!/usr/bin/env node
const updateNotifier = require("update-notifier");
const exec = require("child_process").execSync;
const packageJson = require("./package.json");
const isValidPath = require("is-valid-path");
const { getMessage } = require("./helpers");
const Configstore = require("configstore");
const inquirer = require("inquirer");
const mkdirp = require("mkdirp");
require("colors");
const user = exec("whoami")
.toString()
.trim();
const config = new Configstore(packageJson.name);
main();
function main() {
console.log();
console.log(
"Bienvenue dans l'interface de configuration de Create-Custom-Command / Welcome in the configuration interface of Create-Custom-Command"
.blue
);
inquirer
.prompt([
{
type: "list",
name: "language",
message:
"Dans quelle langue voulez-vous utiliser ce CLI ? In which language do you want to use this CLI ?",
choices: [
{
name: "Français",
value: "fr"
},
{
name: "English",
value: "en"
}
],
default: config.get("language")
}
])
.then(({ language }) => {
config.set("language", language);
inquirer
.prompt([
{
type: "input",
name: "authorName",
message: getMessage("authorName"),
default: config.get("authorName"),
validate(val) {
if (!val) return getMessage("emptyAuthorName");
return true;
}
},
{
type: "path",
name: "commandsFolder",
message: getMessage("commandsFolder"),
default:
config.get("commandsFolder") ||
(process.platform === "darwin"
? `/Users/${user}/Desktop/custom-commands`
: `/home/${user}/custom-commands`),
validate(val) {
return isValidPath(val) && /[!@#$%^&*(),.?":{}|<>/]/.test(val)
? true
: getMessage("invalidPath");
}
},
{
type: "confirm",
name: "autoCreateF",
message: getMessage("autoCreateF"),
default: true
}
])
.then(({ authorName, commandsFolder, autoCreateF }) => {
config.set("authorName", authorName);
config.set(
"commandsFolder",
"/" +
commandsFolder
.split("/")
.filter(s => s)
.join("/") +
"/"
);
if (autoCreateF) mkdirp(commandsFolder);
console.log(getMessage("configureSuccess").green);
});
});
const notifier = updateNotifier({
pkg: packageJson,
updateCheckInterval: 1000 * 60 * 24
});
if (notifier.update) {
console.log(getMessage("updateAvailable").green.bold);
}
}