-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate.js
executable file
·47 lines (40 loc) · 1.36 KB
/
create.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
const path = require("path");
const { copyDirectory, ErrorMessage, SuccessMessage } = require("./helper");
const { CLEAN_NPM_CACHE, SPECIALCHAR } = require("./constants");
const {
installDependencies,
getDependencies,
getDevDependencies,
getProdDependencies,
} = require("./dependencies");
var args = process.argv.slice(2);
var dirName = args[0];
var end_to_end = args[1];
if (dirName === "undefined") {
throw new Error(ErrorMessage("directory name can't be empty"));
} else if (dirName[0].match("^[A-Z0-9]")) {
throw new Error(
ErrorMessage("directory name can't start from capital letters "),
);
} else if (dirName.match(SPECIALCHAR)) {
throw new Error(
ErrorMessage(
"directory name can't start from capital letters or contain special characters in it",
),
);
} else {
//using process.cwd for getting current path
const TEMPLATE_PATH = path.join(__dirname, "../template");
let destination = path.join(process.cwd() + "/" + args[0]);
const prod = end_to_end == "-e";
copyDirectory(TEMPLATE_PATH, destination, prod);
let commands = [],
options;
commands.push(CLEAN_NPM_CACHE);
commands.push(getDependencies());
prod && commands.push(getProdDependencies());
commands.push(getDevDependencies());
options = { cwd: destination, stdio: "inherit" };
installDependencies(commands, options);
console.log(SuccessMessage("Successfully created the directory"));
}