forked from refactorthis/xtform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
130 lines (102 loc) · 3.47 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
'use strict';
var path = require('path'),
streamqueue = require('streamqueue'),
gulp = require('gulp'),
extend = require('extend'),
karma = require('karma').server,
karmaConfig = require('./karma.conf'),
config = require('./build.conf.js'),
plugins = require('gulp-load-plugins')(),
ngAnnotate = require('gulp-ng-annotate');
var ciMode = false;
gulp.task('clean', function () {
return gulp
.src([
config.buildFolder,
config.coverageFolder,
config.docs.build
], {read: false})
.pipe(plugins.clean());
});
gulp.task('scripts', function () {
return gulp.src(config.srcJs)
// jshint
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter('jshint-stylish'))
.pipe(plugins.if(ciMode, plugins.jshint.reporter('fail')))
// package
.pipe(plugins.concat(config.buildJsFilename))
.pipe(plugins.header(config.closureStart))
.pipe(plugins.footer(config.closureEnd))
.pipe(plugins.header(config.banner))
.pipe(ngAnnotate())
.pipe(gulp.dest(config.buildFolder))
.pipe(plugins.filesize())
// minify
.pipe(plugins.uglify())
.pipe(plugins.rename({extname: '.min.js'}))
.pipe(gulp.dest(config.buildFolder))
.pipe(plugins.filesize())
.on('error', plugins.util.log);
});
gulp.task('templates', ['scripts'], function () {
streamqueue({objectMode: true},
// read built scripts file
gulp.src(config.buildFolder + '/' + config.buildJsFilename),
// convert templates to JS
gulp.src(config.views)
.pipe(plugins.ngHtml2js({
declareModule: false,
moduleName: 'xtForm',
prefix: 'xtForm/'
})))
// concat with JS and save unminified
.pipe(plugins.concat(config.templateJsFilename))
.pipe(gulp.dest(config.buildFolder))
// minify
.pipe(plugins.uglify())
.pipe(plugins.rename({extname: '.min.js'}))
.pipe(gulp.dest(config.buildFolder))
.pipe(plugins.filesize())
.on('error', plugins.util.log);
gulp.src('dist/*').pipe(gulp.dest('docs/dist/'));
});
gulp.task('docs', ['default'], function () {
gulp.src('dist/*').pipe(gulp.dest('docs/dist/'));
gulp.src(config.docs.views)
.pipe(plugins.ngHtml2js({
declareModule: false,
moduleName: 'sample',
prefix: 'templates/'
}))
.pipe(plugins.concat(config.docs.templateJsFilename))
.pipe(plugins.header(config.docs.templateBanner))
.pipe(gulp.dest(config.docs.build));
});
gulp.task('docs:deploy', function () {
return gulp.src(config.docs.items)
.pipe(plugins.ghPages());
});
gulp.task('test', function () {
karmaConfig({
set: function (testConfig) {
extend(testConfig, {
singleRun: ciMode,
autoWatch: !ciMode,
browsers: ['PhantomJS']
});
karma.start(testConfig, function (exitCode) {
plugins.util.log('Karma has exited with ' + exitCode);
process.exit(exitCode);
});
}
});
});
gulp.task('watch', function () {
return gulp.watch(config.srcJs, ['scripts', 'templates']);
});
gulp.task('ci', function () {
ciMode = true;
return gulp.start(['clean', 'scripts', 'templates', 'test']);
});
gulp.task('default', ['scripts', 'templates']);