-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
50 lines (41 loc) · 1.1 KB
/
gulpfile.babel.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
'use strict'
import gulp from 'gulp'
import yargs from 'yargs'
import path from 'path'
import template from 'gulp-template'
import rename from 'gulp-rename'
import _ from 'lodash'
const isNameValid = (name) => {
// ensure camelCase name
return name === _.camelCase(name)
}
const generate = (sourcePath, generatorPath) => {
const cap = (val) => {
return val.charAt(0).toUpperCase() + val.slice(1)
}
const name = yargs.argv.name
const parentPath = yargs.argv.parent || ''
const destPath = path.join(generatorPath, parentPath, name)
if (!isNameValid(name)) {
throw new Error('name must be camelCase')
}
return gulp.src(sourcePath)
.pipe(template({
name: name,
upCaseName: cap(name)
}))
.pipe(rename((path) => {
path.basename = path.basename.replace('temp', name)
}))
.pipe(gulp.dest(destPath))
}
const root = 'app'
const paths = {
templates: {
component: path.join(__dirname, 'component/**/*.**')
},
components: path.join(root, 'components')
}
gulp.task('component', () => {
return generate(paths.templates.component, paths.components)
})