forked from PatrickJS/NG6-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
82 lines (71 loc) · 2.06 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
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
78
79
80
81
82
'use strict';
import gulp from 'gulp';
import webpack from 'webpack-stream';
import path from 'path';
import sync from 'run-sequence';
import serve from 'browser-sync';
import rename from 'gulp-rename';
import template from 'gulp-template';
import fs from 'fs';
import yargs from 'yargs';
import lodash from 'lodash';
let reload = () => serve.reload();
let root = 'client';
// helper method for resolving paths
let resolveToApp = (glob) => {
glob = glob || '';
return path.join(root, 'app', glob); // app/{glob}
};
let resolveToComponents = (glob) => {
glob = glob || '';
return path.join(root, 'app/components', glob); // app/components/{glob}
};
// map of all paths
let paths = {
js: resolveToComponents('**/*!(.spec.js).js'), // exclude spec files
styl: resolveToApp('**/*.styl'), // stylesheets
html: [
resolveToApp('**/*.html'),
path.join(root, 'index.html')
],
entry: path.join(root, 'app/app.js'),
output: root,
blankTemplates: path.join(__dirname, 'generator', 'component/**/*.**')
};
// use webpack.config.js to build modules
gulp.task('webpack', () => {
return gulp.src(paths.entry)
.pipe(webpack(require('./webpack.config')))
.pipe(gulp.dest(paths.output));
});
gulp.task('serve', () => {
serve({
port: process.env.PORT || 3000,
open: false,
server: { baseDir: root }
});
});
gulp.task('watch', () => {
let allPaths = [].concat([paths.js], paths.html, [paths.styl]);
gulp.watch(allPaths, ['webpack', reload]);
});
gulp.task('component', () => {
let cap = (val) => {
return val.charAt(0).toUpperCase() + val.slice(1);
};
let name = yargs.argv.name;
let parentPath = yargs.argv.parent || '';
let destPath = path.join(resolveToComponents(), parentPath, name);
return gulp.src(paths.blankTemplates)
.pipe(template({
name: name,
upCaseName: cap(name)
}))
.pipe(rename((path) => {
path.basename = path.basename.replace('temp', name);
}))
.pipe(gulp.dest(destPath));
});
gulp.task('default', (done) => {
sync('webpack', 'serve', 'watch', done);
});