-
Notifications
You must be signed in to change notification settings - Fork 1
/
createpage.js
57 lines (55 loc) · 1.81 KB
/
createpage.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
var fs = require("fs");
var path = require("path");
if (fs.existsSync(path.join(__dirname, "src"))) {
if (fs.existsSync(path.join(__dirname, "src", "pages"))) {
if (process.argv.length !== 3) {
console.error("This script takes exactly 1 argument");
} else {
let pagename = process.argv.slice(2)[0].trim();
if (pagename.match(/^[a-z1-9\-]+$/)) {
console.log("Creating page " + process.argv.slice(2)[0]);
if (fs.existsSync(path.join(__dirname, "src", "pages", pagename))) {
console.error("Directory already exists");
} else {
fs.mkdirSync(path.join(__dirname, "src", "pages", pagename));
let tsfile = `// for all modules, import tailwind and it's scss style
import "tailwindcss/tailwind.css";
import './${pagename}.scss';`;
let scssfile = `@import '../../global/styles/global';`
let ejsfile = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>${pagename}</title>
</head>
<body>
<div>${pagename} page!</div>
</body>
</html>`
fs.writeFileSync(
path.join(__dirname, "src", "pages", pagename, `${pagename}.ts`),
tsfile,
"utf8"
);
fs.writeFileSync(
path.join(__dirname, "src", "pages", pagename, `${pagename}.scss`),
scssfile,
"utf8"
);
fs.writeFileSync(
path.join(__dirname, "src", "pages", pagename, `${pagename}.ejs`),
ejsfile,
"utf8"
);
}
} else {
console.error("Invalid page name, use lowercase a-z and digits only.");
}
}
} else {
console.error("No pages folder found");
}
} else {
console.error("No src folder found");
}