-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscaffold.js
More file actions
40 lines (33 loc) · 1.36 KB
/
Copy pathscaffold.js
File metadata and controls
40 lines (33 loc) · 1.36 KB
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
const fs = require('fs-extra');
const path = require('path');
const cssTemplate = require('./scaffold/css');
const htmlTemplate = require('./scaffold/html');
const jsTemplate = require('./scaffold/js');
const dir = require('./build/constants/directories')(__dirname);
const argPath = process.env.npm_config_path;
if (argPath === undefined) {
console.error('Path argument required! Example: --path=/test');
return;
}
console.log(argPath);
const pageName = argPath.substring(1);
const stylesLocation = path.join(dir.src, `/styles/${pageName}.scss`);
const scriptsLocation = path.join(dir.src, `/js/${pageName}.js`);
const ejsLocation = path.join(dir.src, `/templates/${pageName}.ejs`);
const scssClass = argPath.replace(/\//g, '.');
const htmlClass = pageName.replace(/\//g, ' ');
fs.mkdirpSync(path.dirname(scriptsLocation));
fs.writeFile(scriptsLocation, jsTemplate(), (err) => {
if (err) throw err;
console.log(`${scriptsLocation} successfully created`);
});
fs.mkdirpSync(path.dirname(stylesLocation));
fs.writeFile(stylesLocation, cssTemplate({ className: scssClass }), (err) => {
if (err) throw err;
console.log(`${stylesLocation} successfully created`);
});
fs.mkdirpSync(path.dirname(ejsLocation));
fs.writeFile(ejsLocation, htmlTemplate({ className: htmlClass, pageName }), (err) => {
if (err) throw err;
console.log(`${ejsLocation} successfully created`);
});