-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove.js
81 lines (74 loc) · 2.09 KB
/
remove.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
#!/usr/bin/env node
const { getMessage, getBin } = require("./helpers");
const updateNotifier = require("update-notifier");
const exec = require("child_process").execSync;
const packageJson = require("./package.json");
const Configstore = require("configstore");
const isFolder = require("is-directory");
const inquirer = require("inquirer");
const fs = require("fs");
require("colors");
const config = new Configstore(packageJson.name);
if (
!(
config.has("language") ||
config.has("authorName") ||
config.has("commandsFolder")
)
) {
console.log(
"Vous devez configurer ce paquet avant de l'utiliser. Exécutez ".red +
"config-cccmd".white
);
console.log(
"You must configure this package before using it. Execute ".red +
"config-cccmd".white
);
return;
}
const user = exec("whoami")
.toString()
.trim();
console.log();
console.log(getMessage("welcomeRemove").blue);
main();
async function main() {
if (!isFolder.sync(config.get("commandsFolder")))
return console.log(
getMessage("noCommandsDir").replace("PATH", config.get("commandsFolder"))
.red
);
const dirPath = config.get("commandsFolder");
let choices;
try {
choices = fs.readdirSync(dirPath).filter(f => f !== ".DS_Store");
if (choices.length === 0) throw new Error();
} catch {
console.log(getMessage("noExistingCommands").red);
process.exit();
}
const { cmdToDelete: cmd, confirm } = await inquirer.prompt([
{
type: "list",
name: "cmdToDelete",
message: getMessage("whichCommandToDelete"),
choices
},
{
type: "confirm",
name: "confirm",
message: getMessage("confirmDeletion"),
default: false
}
]);
if (!confirm) return console.log(getMessage("deletionAborted").red);
exec(`rm -r ${dirPath}${cmd} && sudo rm ${getBin()}${cmd}`);
console.log(getMessage("deletionCompleted").replace("NAME", cmd).green);
const notifier = updateNotifier({
pkg: packageJson,
updateCheckInterval: 1000 * 60 * 24
});
if (notifier.update) {
console.log(getMessage("updateAvailable").green.bold);
}
}