-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulpfile.js
260 lines (214 loc) · 9.73 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
var noop = function () {},
gulp = require('gulp'),
//browserSync = require('browser-sync'),
qunit = require('node-qunit'),
plugins = require('gulp-load-plugins')(),
browserify = require('browserify'),
fs = require('fs'),
DOWNLOAD = 'download/',
DEST_JSR = '../jsrender/',
DEST_JSV = '../jsviews/',
DEST_NODESTARTER = '../jsrender-node-starter/',
DEST_JSVCOM = './',
SRC = '_src/',
packageJSON = require('./package'),
jshintConfig = packageJSON.jshintConfig,
jscsConfig = packageJSON.jscsConfig;
jshintConfig.lookup = false;
function buildTemplate(template, minify, folder, from, to) {
var stream = gulp.src([SRC + 'templates/' + (folder || '') + template])
.pipe(plugins.fileInclude({ // Compose js files from src templates
basepath: SRC
}));
if (!from) {
stream = stream.pipe(plugins.jshint(jshintConfig)) // Run JsHint
.pipe(plugins.jscs(jscsConfig)) // Enforce JsCS dode style
.on('error', noop) // Don't stop on error
.pipe(plugins.jscsStylish.combineWithHintResults()) // Combine with JsHint and JsCS results
.pipe(plugins.jshint.reporter('jshint-summary', {
reasonCol: 'blue,bold',
errorsCol: 'black,bold'
//statistics: true
}));
//.pipe(plugins.jshint.reporter('fail'))
}
stream = stream.pipe(gulp.dest(to || ((from||DOWNLOAD) + (folder || '')))) // Output js file
.pipe(plugins.debug({title: "built:"}));
if (minify) {
minifyFile(folder, null, stream);
}
return stream;
}
//plugins.uglify.options.output.comments = 'some';
//================================= COPY - Copy to jsrender and jsviews projects =================================//
gulp.task('preparejsr', function() {
return buildTemplate('package.json', false, 'jsrender/', SRC);
});
gulp.task('preparejsv', function() {
return buildTemplate('package.json', false, 'jsviews/', SRC);
});
gulp.task('preparestarter', function() {
return buildTemplate('package.json', false, 'jsrender-node-starter/', SRC);
});
gulp.task('preparejsvcom', function() {
return buildTemplate('package.json', false, 'jsviews.com/', SRC, DEST_JSVCOM);
});
gulp.task('preparejsr.d.ts', function() {
return buildTemplate('index.d.ts', false, 'jsrender/', true, DOWNLOAD + 'typescript/jsrender/');
});
gulp.task('preparejsv.d.ts', function() {
return buildTemplate('index.d.ts', false, 'jsviews/', true, DOWNLOAD + 'typescript/jsviews/');
});
gulp.task('copy', gulp.series('preparejsr', 'preparejsr.d.ts', 'preparejsv', 'preparejsv.d.ts', 'preparestarter', 'preparejsvcom', function(cb) {
gulp.src([DOWNLOAD + 'jsrender.*js*', DOWNLOAD + 'jsrender-node.js', SRC + 'jsrender/package.json'])
.pipe(gulp.dest(DEST_JSR));
gulp.src([DOWNLOAD + 'tmplify/index.js'])
.pipe(gulp.dest(DEST_JSR + 'tmplify/'));
gulp.src([DOWNLOAD + 'typescript/jsrender/index.d.ts'])
.pipe(gulp.dest(DEST_JSR + "typescript/jsrender/"));
gulp.src([DOWNLOAD + 'jsrender.*js*', DOWNLOAD + 'jsviews.*js*', DOWNLOAD + 'jquery.observable.*js*', DOWNLOAD + 'jquery.views.*js*', SRC + 'jsviews/package.json'])
.pipe(gulp.dest(DEST_JSV));
gulp.src([DOWNLOAD + 'typescript/jsviews/index.d.ts'])
.pipe(gulp.dest(DEST_JSV + "typescript/jsviews/"));
gulp.src(['test/unit-tests/tests-jsrender*.js', 'test/unit-tests/requirejs-config.js'])
.pipe(gulp.dest(DEST_JSR + 'test/unit-tests/'));
gulp.src(['test/unit-tests/tests-js*.js', 'test/unit-tests/requirejs-config.js'])
.pipe(gulp.dest(DEST_JSV + 'test/unit-tests/'));
gulp.src(['test/typescript/jsrender/tests.ts'])
.pipe(gulp.dest(DEST_JSR + 'typescript/jsrender/test/'));
gulp.src(['test/typescript/jsviews/*tests.ts'])
.pipe(gulp.dest(DEST_JSV + 'typescript/jsviews/test/'));
gulp.src([SRC + 'jsrender-node-starter/package.json'])
.pipe(gulp.dest(DEST_NODESTARTER));
cb();
}));
//================================= MINIFY - Build and minify =================================//
gulp.task('minify', function() {
return buildTemplate('*.js', true);
});
function minifyFile(folder, file, stream) {
var stream = stream || gulp.src([DOWNLOAD + folder + (file||"")]);
stream = stream.pipe(plugins.sourcemaps.init()) // Prepare sourcemap
.pipe(plugins.uglify({ // Minify
preserveComments: 'some'
}))
.pipe(plugins.rename(function (path) { // Rename minified file to min.js
path.basename += '.min';
}))
.pipe(plugins.sourcemaps.write('./')) // Output sourcemap file
.pipe(plugins.debug({title: "minified:"}))
.pipe(gulp.dest(DOWNLOAD + (folder||""))) // Output min.js file
return stream;
}
gulp.task('minifyLibs', function(cb) {
minifyFile('sample-tag-controls/', 'jsviews-jqueryui-widgets.js');
minifyFile('plugins/', 'jsrender-unicode.js');
minifyFile('sample-tag-controls/jsonview/', 'jsonview.js');
minifyFile('sample-tag-controls/multiselect/', 'multiselect.js');
minifyFile('sample-tag-controls/tabs/', 'tabs.js');
minifyFile('sample-tag-controls/tabs/', 'tabs2.js');
minifyFile('sample-tag-controls/tabs/', 'tabs3.js');
minifyFile('sample-tag-controls/areaslider/', 'areaslider.js');
minifyFile('sample-tag-controls/colorpicker/', 'colorpicker.js');
minifyFile('sample-tag-controls/colorpicker/', 'colorpicker-multiformat.js');
minifyFile('sample-tag-controls/colorpicker/', 'colorpicker-multiformat2.js');
minifyFile('sample-tag-controls/colorpicker/', 'tinycolor.js');
minifyFile('sample-tag-controls/slider/', 'slider.js');
minifyFile('sample-tag-controls/spinblock/', 'spinblock.js');
minifyFile('sample-tag-controls/textbox/', 'simple-textbox.js');
minifyFile('sample-tag-controls/treeview/', 'tree-if.js');
minifyFile('sample-tag-controls/treeview/', 'tree-visible.js');
minifyFile('sample-tag-controls/validate/', 'validate.js');
minifyFile('../', 'index.js');
minifyFile('../resources/tags/', 'built-in-tags.js');
minifyFile('../', 'datatypes.js');
minifyFile('../documentation/', 'contents-categories.js');
minifyFile('../documentation/', 'contents-download.js');
minifyFile('../documentation/', 'contents-community.js');
minifyFile('../documentation/', 'contents-getstarted.js');
minifyFile('../documentation/', 'contents-jsoapi.js');
minifyFile('../documentation/', 'contents-jsrapi.js');
minifyFile('../documentation/', 'contents-jsvapi.js');
minifyFile('../documentation/', 'contents-samples.js');
minifyFile('../documentation/', 'find-download.js');
minifyFile('../documentation/', 'find-community.js');
minifyFile('../documentation/', 'find-getstarted.js');
minifyFile('../documentation/', 'find-jsoapi.js');
minifyFile('../documentation/', 'find-jsrapi.js');
minifyFile('../documentation/', 'find-jsvapi.js');
minifyFile('../documentation/', 'find-samples.js');
minifyFile('../samples/', 'sample-viewer.js');
cb();
});
gulp.task('minifyOther', function(cb) {
minifyFile('../lib/', 'highlight.js');
cb();
});
//================================= TMPLIFY - Build tmplify/index.js =================================//
gulp.task('tmplify', function() {
return buildTemplate('index.js', false, 'tmplify/');
});
//================================= ALL - Build, minify, copy to projects and test =================================//
gulp.task('all', gulp.series('minify', 'tmplify', 'copy', 'minifyLibs', function(cb) {
// qunit('./test/unit-tests-all-jsviews.html');
// qunit('./test/unit-tests-all-observable-render-views.html');
// qunit('./test/unit-tests-all-render-observable-views.html');
// qunit('./test/unit-tests-jsobservable-no-jsrender.html');
debugger;
cb();
}));
//================================= BUILD - Build =================================//
gulp.task('build', function() {
return buildTemplate('*.js');
});
//================================= TEST - Build and test =================================//
gulp.task('test', gulp.series('build', function(cb) {
qunit('./test/unit-tests-all-jsviews.html');
cb();
}));
//================================= DEFAULT - Build and test =================================//
gulp.task('default', gulp.series('test', function(cb) {
cb();
}));
//gulp.task('default', ['test']);
//gulp.task('default', test);
//================================= JSVIEWS - Build jsviews.js only =================================//
gulp.task('jsviews', function() {
return buildTemplate('jsviews.js');
});
//================================= WATCH - Build jsviews.js and load browser. Watch for changes =================================//
//// Task that ensures the 'jsviews' task is complete before reloading browsers
//gulp.task('build-browse', ['jsviews'], browserSync.reload);
//// Task to launch BrowserSync and watch JS files
//gulp.task('watch', function () {
// // Serve files from the root of this project
// browserSync({
// server: {
// baseDir: "./"
// }
// });
// add browserSync.reload to the tasks array to make
// // all browsers reload after tasks are complete.
// gulp.watch([SRC + '*.js', 'index.html'], ['build-browse']);
//});
//================================= BUNDLE - Run Browserify - create client bundles for test cases =================================//
// See https://github.com/gulpjs/gulp/blob/master/docs/recipes/browserify-with-globs.md
// Task to create Browserify client-side bundle scripts for Browserify test cases.
gulp.task('bundle', function() {
var tmplify = require('jsrender/tmplify');
var gs = require('glob-stream');
// return gs.create('./test/browserify/*-unit-tests.js')
return gs('./test/browserify/*-unit-tests.js')
.on('data', function(file) {
// file has path, base, and cwd attrs
var fileName = file.path.slice(file.base.length, -14);
browserify(file.path, {debug:true})
.transform(tmplify)
.bundle()
.pipe(fs.createWriteStream('./test/browserify/bundles/' + fileName + "-bundle.js"))
.on('error', function(err) {
// Make sure failed tests cause gulp to exit non-zero
throw err;
});
});
});