Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
147 lines (126 loc) · 3.91 KB
/
Copy pathgulpfile.js
File metadata and controls
147 lines (126 loc) · 3.91 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*------------------------
Imports
-------------------------*/
// util
var fs = require('fs'),
del = require('del'),
path = require('path');
// gulp
var gulp = require('gulp'),
install = require('gulp-install'),
server = require('gulp-server-livereload'),
sass = require('gulp-ruby-sass'),
sourcemaps = require('gulp-sourcemaps'),
changed = require('gulp-changed'),
runSequence = require('run-sequence'),
deploy = require('gulp-gh-pages');
/*------------------------
Environment
-------------------------*/
var argv = require('yargs').argv;
var prod = !!argv['prod'];
/*------------------------
Config
-------------------------*/
var srcDir = 'src';
var destDir = 'build';
var paths = {
styles: {
src: path.join(srcDir, 'styles'),
dest: path.join(destDir, 'styles')
},
bower: {
src: 'bower_components',
jsDeps: [
{ script: 'es6-module-loader/dist/es6-module-loader.js*'},
{ script: 'traceur/traceur.min*'},
{ script: 'system.js/dist/system.js*'},
{ script: 'plugin-text/text.js'},
{ script: 'plugin-css/css.js'},
{ script: 'vue/dist/vue*'},
{ script: 'director/build/director.min.js'},
{ script: 'CodeMirror/**/*', sub: 'CodeMirror' }
],
jsDest: path.join(destDir, 'lib'),
assetDeps: [
'loading/*.svg'
],
assetDest: path.join(destDir, 'assets')
}
};
/*------------------------
Tasks
-------------------------*/
gulp.task('clean', function(cb) {
return del([destDir], cb);
});
gulp.task('build', function(cb) {
runSequence('clean', ['copy', 'styles'], cb);
});
gulp.task('deploy', ['build'], function() {
return gulp.src(path.join(destDir, '/**/*'))
.pipe(deploy());
});
gulp.task('serve', ['build'], function() {
if (!prod) {
gulp.watch([
path.join(srcDir, '**/*'),
path.join('!'+paths.styles.src,'**/*')
], ['copy']);
gulp.watch([path.join(paths.styles.src, '**/*')], ['styles']);
}
return gulp.src(destDir)
.pipe(server({
livereload: {
enable: true,
filter: function(filePath, cb) {
cb( !(/DS_Store/.test(filePath)) );
}
},
directoryListing: false,
open: false
}));
});
gulp.task('styles', ['bower'], function() {
var sassOpts = prod? {style: 'compressed'} : {sourcemap: true};
var task = sass(paths.styles.src, sassOpts);
if (!prod) {
task = task.pipe(sourcemaps.write('./maps'));
}
task.on('error', function (err) {console.error('Error', err.message);});
return task.pipe(gulp.dest(paths.styles.dest));
});
gulp.task('copy', ['bower-js', 'bower-assets'], function() {
return gulp.src([
path.join(srcDir, '**/*'),
path.join('!'+paths.styles.src,'**/*')
])
.pipe(changed(destDir))
.pipe(gulp.dest(destDir));
});
gulp.task('bower', function() {
return gulp.src('./bower.json')
.pipe(install());
});
//gulp.task('bower-folders', ['bower'], function() {
// gulp.src(paths.bower.folderDeps.map(function(dep) {
// return path.join(paths.bower.src, dep);
// }),{base: paths.bower.src})
// .pipe(gulp.dest(paths.bower.folderDest));
//});
gulp.task('bower-js', ['bower'], function() {
paths.bower.jsDeps.forEach(function(dep) {
var d = dep.sub ? path.join(paths.bower.jsDest,dep.sub) : paths.bower.jsDest;
var s = path.join(paths.bower.src, dep.script);
gulp.src(s)
.pipe(changed(d))
.pipe(gulp.dest(d));
})
});
gulp.task('bower-assets', ['bower'], function() {
return gulp.src(paths.bower.assetDeps.map(function(dep) {
return path.join(paths.bower.src, dep);
}), {base: paths.bower.src})
.pipe(changed(paths.bower.assetDest))
.pipe(gulp.dest(paths.bower.assetDest));
});