-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpresets.js
48 lines (42 loc) · 1.16 KB
/
presets.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
const fs = require('fs');
const path = require('path');
const { normalizeText } = require('./utils/normalize');
// Check if the user has correctly specified a name
// for the new page template he wants
if (!process.argv[2]) {
return console.log(
`You must specify a page name like so:\n\nnpm run create pageName\n\n`
);
}
const requestedPage = process.argv[2];
const requestedPath = path.join(
__dirname,
'src',
'views',
'templates',
requestedPage
);
// Chcek if the folder for desired page already exists
if (fs.existsSync(requestedPath)) {
return console.log('Page folder already exists!');
}
// Create necessary .hbs, .js and .scss files
fs.mkdirSync(path.join(requestedPath));
fs.writeFile(
requestedPath + `/${requestedPage}.js`,
`import './${requestedPage}.scss';`,
() => {
console.log(`Created file: ${requestedPage}.js`);
}
);
fs.openSync(requestedPath + `/${requestedPage}.scss`, 'a');
console.log(`Created file: ${requestedPage}.scss`);
fs.writeFile(
requestedPath + `/${requestedPage}.hbs`,
`
{{#> main }}
<h1>${normalizeText(requestedPage)}</h1>
{{/main}}
`,
() => console.log(`Created file: ${requestedPage}.hbs`)
);