forked from fabric8-ui/fabric8-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
42 lines (39 loc) · 1.47 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
const gulp = require('gulp'),
del = require('del'),
sourcemaps = require('gulp-sourcemaps'),
changeCase = require('change-case'),
replace = require('gulp-string-replace'),
rename = require('gulp-rename'),
exec = require('child_process').exec,
argv = require('yargs')
.usage('Usage: $0 [options]')
.command('create', 'Create a new component')
.example('$0 --component=example-widget --dest=src/app/')
.alias('d', 'dest')
.describe('d', 'The directory to place the component in.')
.alias('c', 'component')
.describe('c', 'The name of the component to create in snake case.')
.demandOption(['c', 'd'])
.argv;
var appSrc = 'src';
var libraryDist = 'dist';
function copyToDest(srcArr) {
return gulp.src(srcArr)
.pipe(gulp.dest(function (file) {
return libraryDist + file.base.slice(__dirname.length); // save directly to dist
}));
}
gulp.task('create', function () {
let headerCase = argv.c;
let pascalCase = changeCase.pascalCase(headerCase);
let dest = argv.d;
let origHeaderCase = 'starter-widget';
let origPascalCase = changeCase.pascalCase(origHeaderCase);
return gulp.src([`src/templates/${origHeaderCase}/**`])
.pipe(rename(function (path) {
path.basename = path.basename.replace(new RegExp(origHeaderCase), headerCase);
}))
.pipe(replace(new RegExp(origHeaderCase, "g"), headerCase))
.pipe(replace(new RegExp(origPascalCase, "g"), pascalCase))
.pipe(gulp.dest(`${dest}/${headerCase}`));
});