-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (72 loc) · 2.22 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
const { setRootDir, getRootDir } = require("./src/rootDirectory");
const { program } = require("./src/cliManager");
const { makeDir } = require("./src/fileMaker");
const { setTemplate } = require("./src/templateBuilder");
const { takeConfirmation } = require("./src/confirmation");
const colors = require("colors");
const storage = require("node-persist");
exports.mainCliProcess = async (args) => {
program.parse(args);
await storage.init({
dir: `${__dirname}/storage`,
stringify: JSON.stringify,
parse: JSON.parse,
encoding: "utf8",
logging: false,
expiredInterval: 2 * 60 * 1000,
forgiveParseErrors: false,
});
if ((await storage.getItem("lang")) === undefined) {
storage.setItem("lang", "cpp");
}
if (!!program.root) {
let newRootDir = process.cwd();
let isSuccessfull = setRootDir(newRootDir);
if (!!isSuccessfull) {
console.log(`"${newRootDir}" is now the root dir.`.cyan);
} else {
console.log(
"error: There is some problem, please try again later.".bgRed
);
}
}
else if (!!program.template) {
let currDir = process.cwd();
let isSuccessfull = setTemplate(currDir);
if (!!isSuccessfull) {
console.log(
`CLI will look in "${currDir}" for template now, make sure you have "template.txt" here.`
.cyan
);
} else {
console.log(
"error: There is some problem, please try again later.".bgRed
);
}
}
else {
const rootDir = await getRootDir();
const dirName = program.dir;
const numberOfFiles = parseInt(program.number);
if (program.lang) {
await storage.setItem("lang", program.lang);
}
if (dirName == undefined) {
console.log("error: option '-d, --dir <type>' argument missing".red);
} else {
const res = await makeDir(rootDir, dirName, numberOfFiles);
if (typeof res == "boolean") {
if (!!res === true) {
console.log(`${dirName} created at "${rootDir}"`.bgBrightGreen.black);
takeConfirmation();
} else {
console.log(
"error: There is some problem, please try again later.".bgRed
);
}
} else {
console.log(res.red);
}
}
}
};