-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
142 lines (118 loc) · 3.54 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
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
'use strict';
var gulp = require('gulp'),
$$ = require('gulp-load-plugins')();
var runSequence = require('run-sequence'),
browserSync = require('browser-sync').create(),
exec = require('child_process').exec,
path = require('path'),
escapeStr = require('js-string-escape'),
CleanCss = require("clean-css");
var name = 'finbars',
srcDir = './src/',
testDir = './test/',
buildDir = './umd/';
// // // // // // // // // // // //
gulp.task('lint', lint);
gulp.task('test', test);
gulp.task('doc', doc);
gulp.task('browserify', function(callback) {
browserify();
browserifyMin();
callback();
});
gulp.task('serve', browserSyncLaunchServer);
gulp.task('build', function(callback) {
clearBashScreen();
runSequence(
'lint',
'test',
'doc',
'inject-css',
'browserify',
callback);
});
gulp.task('watch', function () {
gulp.watch([
srcDir + name + '.js',
'!' + srcDir + 'index.js', // ignore this file generated by 'inject-css' task
testDir + 'index.js'
], ['build'])
.on('change', function(event) {
browserSync.reload();
});
});
gulp.task('default', ['build', 'watch'], browserSyncLaunchServer);
gulp.task('inject-css', function () {
var target = gulp.src(srcDir + name + '.js'),
source = gulp.src(srcDir + name + '.css'),
destination = gulp.dest(srcDir);
target
.pipe($$.inject(source, {
transform: cssToJsFn,
starttag: '/* {{name}}:{{ext}} */',
endtag: '/* endinject */'
}))
.pipe($$.rename('index.js'))
.pipe(destination);
});
// // // // // // // // // // // //
function cssToJsFn(filePath, file) {
var STYLE_HEADER = 'cssFinBars = \'',
STYLE_FOOTER = '\';';
var css = new CleanCss({})
.minify(file.contents.toString())
.styles;
file.contents = new Buffer(STYLE_HEADER + escapeStr(css) + STYLE_FOOTER);
return file.contents.toString('utf8');
}
function lint() {
return gulp.src(srcDir + name + '.js')
.pipe($$.excludeGitignore())
.pipe($$.eslint())
.pipe($$.eslint.format())
.pipe($$.eslint.failAfterError());
}
function test(cb) {
return gulp.src(testDir + 'index.js')
.pipe($$.mocha({reporter: 'spec'}));
}
function browserify() {
return gulp.src(srcDir + 'browserify_root.js')
.pipe($$.browserify({
//insertGlobals : true,
debug: true
}))
//.pipe($$.sourcemaps.init({loadMaps: true}))
// Add transformation tasks to the pipeline here:
.on('error', $$.util.log)
.pipe($$.rename(name + '.js'))
.pipe(gulp.dest(buildDir));
}
function browserifyMin() {
return gulp.src(srcDir + 'browserify_root.js')
.pipe($$.browserify())
.pipe($$.uglify())
.pipe($$.rename(name + '.min.js'))
.pipe(gulp.dest(buildDir)); // outputs to ./build/list-dragon.min.js for githup.io publish
}
function doc(cb) {
exec(path.resolve('jsdoc.sh'), function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}
function browserSyncLaunchServer() {
browserSync.init({
server: {
// Serve up our build folder
baseDir: './',
index: "index.html"
},
port: 5005
});
}
function clearBashScreen() {
var ESC = '\x1B';
console.log(ESC + 'c'); // (VT-100 escape sequence)
}