-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
45 lines (37 loc) · 1.14 KB
/
gulpfile.js
File metadata and controls
45 lines (37 loc) · 1.14 KB
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
const path = require('path');
const gulp = require('gulp');
const yargs = require('yargs');
const template = require('gulp-template');
const rename = require('gulp-rename');
const gulpUtil = require('gulp-util');
const root = 'src';
gulp.task('component', component);
function component() {
if(!yargs.argv.name) {
throw new gulpUtil.PluginError({
plugin: 'component',
message: 'name is empty.'
});
}
const templatePath = resolveToTemplate();
const componentName = sentenceCase(yargs.argv.name);
const parentPath = yargs.argv.parent || '';
const destPath = path.join(resolveToComponents(), parentPath, componentName);
return gulp.src(templatePath)
.pipe(template({
name: componentName
}))
.pipe(rename((renamePath) => {
renamePath.basename = renamePath.basename.replace('Temp', componentName);
}))
.pipe(gulp.dest(destPath));
}
function resolveToComponents(glob) {
return path.join(root, 'modules', glob || '');
}
function resolveToTemplate() {
return path.join(__dirname, 'generator', 'component/**/*.**');
}
function sentenceCase(val) {
return val.charAt(0).toUpperCase() + val.slice(1);
}