-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcreate-component.js
58 lines (47 loc) · 1.32 KB
/
create-component.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
58
// Creates component from CLI
const fs = require('fs');
const path = require('path');
let basePath = './src/components/';
const files = {
pug: `mixin {component}\n .{component}`,
scss: `.{component} {\n \n}`,
};
const args = process.argv.slice(2);
const createFiles = (component) => {
const componentPath = path.join(basePath, component);
Object.keys(files).forEach((extension) => {
const fileName = `${component}.${extension}`;
const fileSource = files[extension].replace(/\{component}/g, component);
const filePath = path.join(componentPath, fileName);
fs.writeFile(filePath, fileSource, 'utf8', (err) => {
if (err) throw err;
});
});
};
const createFolder = (component) => {
fs.mkdir(`${basePath}${component}`, (err) => {
if (err) {
throw err;
} else {
createFiles(component);
}
});
};
if (args.includes('--ui')) {
basePath += '_ui/';
}
if (args.includes('--js')) {
files.js = '';
}
if (args.includes('--ts')) {
files.ts = '';
}
if (args.includes('--section')) {
files.pug = `mixin {component}\n section.{component}.container\n .{component}__wrapper.wrapper`;
}
args.map((component) => {
if (!['--ui', '--js', '--ts', '--section'].includes(component)) {
createFolder(component);
console.info(`Component "${component}" was successfully created`);
}
});