forked from PatrickJS/NG6-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGulpfile.js
101 lines (91 loc) · 2.57 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var gulp = require('gulp'),
path = require('path'),
jspm = require('jspm'),
rename = require('gulp-rename'),
template = require('gulp-template'),
uglify = require('gulp-uglify'),
htmlreplace = require('gulp-html-replace'),
ngAnnotate = require('gulp-ng-annotate'),
serve = require('browser-sync'),
yargs = require('yargs').argv,
rimraf = require('rimraf')
var root = 'client';
// helper method to resolveToApp paths
var resolveTo = function(resolvePath) {
return function(glob) {
glob = glob || '';
return path.resolve(path.join(root, resolvePath, glob));
}
};
var resolveToApp = resolveTo('app'); // app/{glob}
var resolveToComponents = resolveTo('app/components'); // app/components/{glob}
// map of all our paths
var paths = {
css: resolveToApp('**/*.css'),
html: [
resolveToApp('**/*.html'),
path.join(root, 'index.html')
],
blankTemplates: path.join(__dirname, 'generator', 'component/**/*.**'),
dist: path.join(__dirname, 'dist/')
};
gulp.task('serve', function(){
'use strict'
require('chokidar-socket-emitter')({port: 8081, path: 'client', relativeTo: 'client'})
serve({
port: process.env.PORT || 3000,
open: false,
files: [].concat(
[paths.css],
paths.html
),
server: {
baseDir: root,
// serve our jspm dependencies with the client folder
routes: {
'/jspm.config.js': './jspm.config.js',
'/jspm_packages': './jspm_packages'
}
},
});
});
gulp.task('build', function() {
var dist = path.join(paths.dist + 'app.js');
rimraf.sync(path.join(paths.dist, '*'));
// Use JSPM to bundle our app
return jspm.bundleSFX(resolveToApp('app'), dist, {})
.then(function() {
// Also create a fully annotated minified copy
return gulp.src(dist)
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(rename('app.min.js'))
.pipe(gulp.dest(paths.dist))
})
.then(function() {
// Inject minified script into index
return gulp.src('client/index.html')
.pipe(htmlreplace({
'js': 'app.min.js'
}))
.pipe(gulp.dest(paths.dist));
});
});
gulp.task('component', function(){
var cap = function(val){
return val.charAt(0).toUpperCase() + val.slice(1);
};
var name = yargs.name;
var parentPath = yargs.parent || '';
var destPath = path.join(resolveToComponents(), parentPath, name);
return gulp.src(paths.blankTemplates)
.pipe(template({
name: name,
upCaseName: cap(name)
}))
.pipe(rename(function(path){
path.basename = path.basename.replace('temp', name);
}))
.pipe(gulp.dest(destPath));
});
gulp.task('default', ['serve'])