-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew-project.js
41 lines (31 loc) · 947 Bytes
/
new-project.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
const fs = require("fs");
const path = require("path");
const projectDir = process.argv[2];
console.log(`Checking for directory ${projectDir}`);
if (fs.existsSync(projectDir)) {
console.log("Directory exists!");
process.exit();
}
console.log(`Creating directory ${projectDir}`);
fs.mkdir(projectDir, (err) => {
if (err) {
console.log("error creating direcory");
console.log(err);
process.exit();
}
});
const sketchjs = loadFile("_templates/sketch.js");
let indexhtml = loadFile("_templates/index.html");
indexhtml = indexhtml.replace("{{title}}", projectDir.replace("-", " "));
console.log("Creating sketch.js");
fs.writeFileSync(projectDir + "/sketch.js", sketchjs, {
mode: 0666,
});
console.log("Creating index.html");
fs.writeFileSync(projectDir + "/index.html", indexhtml, {
mode: 0666,
});
console.log("So simple!");
function loadFile(name) {
return fs.readFileSync(path.join(__dirname, name), "utf-8");
}