-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGulpfile.js
executable file
·92 lines (80 loc) · 2.29 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
var gulp = require('gulp');
var sync = require('run-sequence');
var browser = require('browser-sync');
var webpack = require('webpack-stream');
var todo = require('gulp-todoist');
var path = require('path');
var yargs = require('yargs').argv;
var tpl = require('gulp-template');
var rename = require('gulp-rename');
/*
map of paths for using with the tasks below
*/
var paths = {
entry: 'client/app/app.js',
app: ['client/app/**/*.{js,scss,html}', 'client/styles/**/*.scss'],
js: 'client/app/**/*!(.spec.js).js',
sass: ['client/app/**/*.scss', 'client/style/**/*.scss'],
toCopy: ['client/index.html'],
html: ['client/index.html', 'client/app/**/*.html'],
dest: 'dist',
blankTemplates: 'templates/component/*.**'
};
// helper funciton
var resolveToComponents = function(glob){
glob = glob || '';
return path.join('client', 'app/components', glob); // app/components/{glob}
};
gulp.task('todo', function() {
return gulp.src(paths.js)
.pipe(todo({silent: false, verbose: true}));
});
gulp.task('build', ['todo'], function() {
return gulp.src(paths.entry)
.pipe(webpack(require('./webpack.config')))
.pipe(gulp.dest(paths.dest));
});
gulp.task('serve', function() {
browser({
port: process.env.PORT || 4500,
open: false,
ghostMode: false,
server: {
baseDir: 'dist'
}
});
});
/*
simple task to copy over needed files to dist
*/
gulp.task('copy', function() {
return gulp.src(paths.toCopy, { base: 'client' })
.pipe(gulp.dest(paths.dest));
});
/*
task to watch files for changes and call build and copy tasks
*/
gulp.task('watch', function() {
gulp.watch(paths.app, ['build', browser.reload]);
gulp.watch(paths.toCopy, ['copy', browser.reload]);
});
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(tpl({
name: name,
upCaseName: cap(name)
}))
.pipe(rename(function(path){
path.basename = path.basename.replace('component', name);
}))
.pipe(gulp.dest(destPath));
});
gulp.task('default', function(done) {
sync('build', 'copy', 'serve', 'watch', done)
});