-
Notifications
You must be signed in to change notification settings - Fork 0
/
scaffold.js
67 lines (54 loc) · 1.43 KB
/
scaffold.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
59
60
61
62
63
64
65
66
67
var readline = require('readline');
var fs = require('fs-extra');
var glob = require('glob');
var options = {
js: true
};
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var write = function(file){
fs.readFile(file, 'utf8', function(err, data) {
if (err) {
return console.log(err);
}
var result = data.replace(/boilerplate/g, options.name).replace(/Boilerplate/g, options.upperCaseName);
fs.writeFile(file, result, 'utf8', function (err) {
var newName;
if(err){
console.log(err);
return;
}
newName = file.replace(/boilerplate/g, options.name).replace(/Boilerplate/g, options.upperCaseName);
if(file != newName){
fs.rename(file, newName, function(er){
if(er){
console.log(er)
}
});
}
});
});
};
var writeAll = function() {
var componentSrc = 'sources/components/'
var boilerplateDir = componentSrc + 'rb_boilerplate';
if(fs.existsSync(boilerplateDir)) {
fs.renameSync(boilerplateDir, componentSrc + 'rb_' + options.name);
}
glob('!(node_modules|dist)/**/*{json,hbs,scss,es6,js,html}', function(err, files) {
if(err) {
console.log(err);
}
files.push('README.md', 'package.json');
files.forEach(write);
});
fs.removeSync('scaffold.js')
};
rl.question('Name of your project: ', function(name) {
options.name = name;
options.upperCaseName = options.name.charAt(0).toUpperCase() + options.name.substr(1);
writeAll();
rl.close();
});