-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (35 loc) · 1.11 KB
/
index.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
#!/usr/bin/env node
const fs = require("fs");
const templatePath = __dirname + "/template";
if (process.argv.length < 3) {
console.log("Please enter component name!");
} else {
const componentName = process.argv[2];
const path = "./src/components/" + componentName;
fs.existsSync(path) || fs.mkdirSync(path);
fs.createReadStream(`${templatePath}/component.html`).pipe(
fs.createWriteStream(path + "/" + componentName + ".html")
);
fs.createReadStream(`${templatePath}/component.scss`).pipe(
fs.createWriteStream(path + "/" + componentName + ".scss")
);
fs.readFile(`${templatePath}/component.vue`, "utf8", function (err, content) {
content = content.replace(/{componentName}/g, componentName);
content = content.replace(
"{componentNameUpperCase}",
componentName.charAt(0).toUpperCase() + componentName.slice(1)
);
fs.writeFile(
path + "/" + componentName + ".vue",
content,
"utf8",
function (err) {
if (err) {
console.log(err.message);
} else {
console.log("Component created!");
}
}
);
});
}