-
Notifications
You must be signed in to change notification settings - Fork 4
/
Gulpfile.js
executable file
·77 lines (63 loc) · 2.01 KB
/
Gulpfile.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
68
69
70
71
72
73
74
75
76
77
var gulp = require('gulp'),
path = require('path'),
rename = require('gulp-rename'),
template = require('gulp-template'),
fs = require('fs'),
yargs = require('yargs').argv;
var root = './';
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
var createComponent = function(simpleComponent) {
var component;
if (simpleComponent) {
component = path.join(__dirname, 'generator', 'simple-component/**/*.**');
} else {
component = path.join(__dirname, 'generator', 'component/**/*.**');
}
var cap = function(val) {
return val.charAt(0).toUpperCase() + val.slice(1);
};
var name = yargs.name,
parentPath = yargs.parent || '',
destPath = path.join(path.join(root, 'src/components/'), parentPath, capitalizeFirstLetter(name));
console.log('\n\n\tCongratulations!\n' +
'\tJust now you\'ve created a `' + name + '` component.\n\n');
return gulp.src(component)
.pipe(template({
name: capitalizeFirstLetter(name),
upCaseName: cap(name)
}))
.pipe(rename(function(path) {
path.basename = path.basename.replace('temp', name);
}))
.pipe(gulp.dest(destPath));
};
var createTemplate = function(type, folder, file) {
var name = yargs.name,
parentPath = yargs.parent || '',
destPath = path.join(path.join(root, folder));
return gulp.src(path.join(__dirname, 'generator', file))
.pipe(template({
name: name,
}))
.pipe(rename(function(path) {
path.basename = path.basename.replace('temp', name);
}))
.pipe(gulp.dest(destPath));
};
gulp.task('simple-component', function() {
createComponent(true);
});
gulp.task('component', function() {
createComponent(false);
createTemplate('action', 'src/actions/', 'action/*.js');
createTemplate('reducer', 'src/reducers/', 'reducer/*.js');
});
var help = function() {
console.log('\n\tusage: gulp [simple-component] --name <name>\n' +
'\tusage: gulp [component] --name <name>\n');
};
gulp.task('default', function() {
help();
});