forked from adeyahya/regenr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·46 lines (37 loc) · 1.46 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
44
45
46
#!/usr/bin/env node
var program = require("commander"),
filendir = require("filendir"),
colors = require("colors"),
templates = require("./template.js");
var createFile = function(path, css) {
css = css || "scss";
var filename = path.match(/[^\\|/]*$/)[0];
var dir = path.substring((path.match(/[^\\|/]*$/).index), -1);
console.log("\n=====================\n== React Generator ==\n=====================");
filendir.writeFile(dir + filename + "/" + filename + ".js", templates.getReact(filename, css, true), function(err) {
if (err) return console.log(err);
console.log("Created " + `${dir}${filename}/` + colors.yellow.underline(`${filename}.js`));
return true;
});
filendir.writeFile(`${dir}${filename}/${filename}.${css}`, templates.getStyle(filename, css), function(err) {
if (err) return console.log(err);
console.log("Created " + `${dir}${filename}/` + colors.blue.underline(`${filename}.${css}`));
return true;
});
filendir.writeFile(dir + filename + "/" + "index.js", templates.getIndex(filename), function(err) {
if (err) return console.log(err);
console.log("Created " + `${dir}${filename}/` + colors.magenta.underline("index.js"));
return true;
});
};
program
.arguments("<file>")
.option("-c, --css <css>", "Css preprocessor")
.action(function(file) {
if (typeof program.css != "undefined") {
createFile(file, program.css);
} else {
createFile(file);
}
})
.parse(process.argv);