-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
362 lines (315 loc) · 10.1 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
const gulp = require('gulp');
const argv = require('minimist')(process.argv.slice(3))
const log = require('fancy-log')
const replace = require('gulp-replace');
const rimraf = require('rimraf');
const zip = require('gulp-zip');
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const connect = require('gulp-connect')
const open = require('open')
const fs = require('fs');
const karma = require('karma');
//////////////////////////
// for minified version
// js: using uglify for now.
const uglify = require('gulp-uglify');
// var closure = require('google-closure-compiler').gulp();
// var sourcemaps = require('gulp-sourcemaps');
const csso = require('gulp-csso');
///////////////////////////////////////////////////////////
// Exports:
const app = gulp.parallel(localConfig, baseStuff)
const dist_directory = gulp.series(app, vendor);
const vendor_other = gulp.parallel(vendor_other_fontawesome, vendor_other_bootstrap,
vendor_other_angular);
const min = gulp.series(config, img, vendor_other, app_min_js, app_min_css);
const dist = gulp.series(dist_directory, do_package, min);
const try_dist = gulp.series(dist, open_dist);
const install = gulp.series(check_dest, dist, do_install);
exports.default = dist;
exports.dist = dist
exports.try_dist = try_dist
exports.dev = dev;
exports.install = install;
exports.test = doKarma(false);
exports.ci = gulp.series(doKarma(true));
exports.clean = clean;
///////////////////////////////////////////////////////////
const base = argv.base;
const appInfo = require('./package');
const appName = appInfo.name;
const version = appInfo.version;
const distDest = './dist/' + appName;
const zipFile = appName + '-' + version + (base ? '-BASE' + base.replace(/\//g, '_') : '') + '.zip';
const zipDest = './dist';
log("Building version " + version);
if (base) {
log('Will insert <base href="' +base+ '">');
}
let installDest = argv.dest;
if (installDest) {
log('dest=' +installDest);
installDest = installDest.replace(/^~/, process.env.HOME);
log('Install destination: ' +installDest);
}
/////////////////////////////////////////////////////////////////////////////
// local development/testing
const localPort = 9001;
const localUrl = 'http://localhost:' +localPort+ '/src/app/indexdev.html';
function dev(cb) {
return connect.server({
port: localPort,
root: '.',
livereload: true
}, () => {
open(localUrl)
cb()
})
}
function open_dist(cb) {
return connect.server({
port: localPort,
root: 'dist',
livereload: false
}, () => {
open('http://localhost:9001/orrportal/')
cb()
})
}
function clean(cb) {
rimraf(distDest, cb);
};
/////////////////////////////////////////////////////////////////////////////
// dist
function localConfig(cb) {
var src = ['./src/app/**', '!./src/app/**/*.html'];
if (argv.localConfig) {
log("app task: Including local.config.js");
}
else {
log("app task: EXCLUDING local.config.js");
src.push('!./**/local.config.js');
}
gulp.src(src)
.pipe(gulp.dest(distDest));
cb();
}
function baseStuff(cb) {
gulp.src(['./src/app/**/*.html'])
.pipe(replace(/<head>/g, '<head>' + (base ? '<base href="' +base+ '">' : '')))
.pipe(replace(/@@version/g, version))
.pipe(replace(/\.\.\/\.\.\/node_modules/g, 'vendor'))
.pipe(gulp.dest(distDest));
cb();
}
function vendor(cb) {
gulp.src([
'./node_modules/angular/**',
'./node_modules/angular-clipboard/**',
'./node_modules/angular-cookie/**',
'./node_modules/angular-sanitize/**',
'./node_modules/angular-ui-bootstrap/**',
'./node_modules/angular-ui-grid/**',
'./node_modules/angular-ui-router/**',
'./node_modules/angular-xeditable/**',
'./node_modules/angular-recaptcha/**',
'./node_modules/angular-jwt/**',
'./node_modules/angular-local-storage/**',
'./node_modules/comma-separated-values/**',
'./node_modules/bootstrap-css-only/**',
'./node_modules/font-awesome/**',
'./node_modules/lodash/**',
'./node_modules/moment/**',
'./node_modules/ng-file-upload/**',
'./node_modules/select2/**',
'./node_modules/ui-select/**'
], {base: './node_modules/'})
.pipe(gulp.dest(distDest + '/vendor'));
cb();
}
function do_package(cb) {
gulp.src([distDest + '/**'])
.pipe(zip(zipFile))
.pipe(gulp.dest(zipDest));
cb();
}
/////////////////////////////////////////////////////////////////////////////
// install
function check_dest(cb) {
if (!installDest) throw Error("install needs --dest=dir");
if (!fs.lstatSync(installDest).isDirectory()) throw Error(installDest+ " is not a directory");
cb();
}
function do_install(cb) {
gulp.src(distDest + '/**')
.pipe(gulp.dest(installDest));
cb();
}
/////////////////////////////////////////////////////////////////////////////
function doKarma(singleRun) {
return done => {
const karmaConfig = {
configFile: __dirname + '/karma.conf.js',
singleRun: singleRun,
browsers: ['PhantomJS']
};
const karmaServer = new karma.Server(
karmaConfig,
function handleKarmaServerExit(processExitCode){
if (!processExitCode) {
done();
} else {
var err = new Error('ERROR: Karma Server exited with code "' + processExitCode + '"');
taskDone(err);
}
done();
process.exit(processExitCode); //Exit the node process
}
);
karmaServer.start();
}
}
/////////////////////////////////////////////////////////////////////////////
function config(cb) {
var cfgSrc = ['./src/app/js/config.js'];
if (argv.localConfig) {
log("config: INCLUDING local.config.js");
cfgSrc.push('./src/app/js/local.config.js');
}
else {
log("config: EXCLUDING local.config.js");
}
gulp.src(cfgSrc)
.pipe(gulp.dest(distDest + '/js'));
cb();
}
function img(cb) {
gulp.src(['./src/app/img/**'])
.pipe(gulp.dest(distDest + '/img'));
cb();
}
function vendor_other_fontawesome(cb) {
gulp.src([
'node_modules/font-awesome/fonts/**'
], {base: 'node_modules/font-awesome/'})
.pipe(gulp.dest(distDest));
cb();
}
function vendor_other_bootstrap(cb) {
gulp.src([
'node_modules/bootstrap-css-only/fonts/**'
], {base: 'node_modules/bootstrap-css-only/'})
.pipe(gulp.dest(distDest));
cb();
}
function vendor_other_angular(cb) {
gulp.src([
'node_modules/angular-ui-grid/ui-grid.woff',
'node_modules/angular-ui-grid/ui-grid.ttf'
], {base: 'node_modules/angular-ui-grid/'})
.pipe(gulp.dest(distDest + "/css"));
cb();
}
function app_min_js(cb) {
gulp.src(vendorJsSources.concat(appJsSources))
.pipe(concat('orrportal.js'))
.pipe(uglify())
.pipe(rename('orrportal.min.js'))
.pipe(gulp.dest(distDest + '/js'));
cb();
}
function app_min_css(cb) {
gulp.src(vendorCssSources.concat(appCssSources))
.pipe(concat('orrportal.all.css'))
.pipe(csso())
.pipe(rename('orrportal.min.css'))
.pipe(gulp.dest(distDest + '/css'));
cb();
}
const vendorCssSources = [
'node_modules/bootstrap-css-only/css/bootstrap.css',
'node_modules/bootstrap-css-only/css/bootstrap-theme.css',
'node_modules/font-awesome/css/font-awesome.css',
'node_modules/angular-ui-grid/ui-grid.css',
'node_modules/ui-select/dist/select.css',
'node_modules/select2/dist/css/select2.css',
'node_modules/angular-xeditable/dist/css/xeditable.css'
]
const appCssSources = [
'src/app/css/orrportal.css'
]
const appJsSources = [
'src/app/js/bUtil.js',
'src/app/js/appUtil.js',
'src/app/js/app.js',
'src/app/js/main/directives.js',
'src/app/js/main/filters.js',
'src/app/js/main/services.js',
'src/app/js/main/main.js',
'src/app/js/main/queryUtil.js',
'src/app/js/facet/facetModel.js',
'src/app/js/facet/facets.js',
'src/app/js/ontgrid/ontgrid.js',
'src/app/js/org/org.js',
'src/app/js/org/org-create.js',
'src/app/js/vocabulary/vocabulary.js',
'src/app/js/uri/uri.js',
'src/app/js/ont/metaUtil.js',
'src/app/js/ont/ont.js',
'src/app/js/ont/ont-contents.js',
'src/app/js/ont/ont-meta.js',
'src/app/js/ont/ont-meta-section.js',
'src/app/js/ont/ont-data.js',
'src/app/js/ont/v2r/v2r.js',
'src/app/js/ont/v2r/v2r-csv.js',
'src/app/js/ont/m2r/m2rUtil.js',
'src/app/js/ont/m2r/m2r.js',
'src/app/js/ont/rj/rj-viewer.js',
'src/app/js/ont/multivalueedit.js',
'src/app/js/term/term.js',
'src/app/js/user/user.js',
'src/app/js/st/st.js',
'src/app/js/kw/kw.js',
'src/app/js/search/search.js',
'src/app/js/auth/auth.js',
'src/app/js/auth/controllers.js',
'src/app/js/upload/upload.js',
'src/app/js/util/items-viewer.js',
'src/app/js/util/util.js',
'src/app/js/util/clipboardCopy.js',
'src/app/js/util/view-as-options.js',
'src/app/js/admin/users.js',
'src/app/js/admin/orgs.js',
'src/app/js/admin/triplestore.js',
'src/app/js/admin/admin.js'
]
const vendorJsSources = [
'node_modules/angular/angular.js',
'node_modules/angular-cookie/angular-cookie.js',
'node_modules/angular-ui-bootstrap/dist/ui-bootstrap-tpls.js',
'node_modules/angular-sanitize/angular-sanitize.js',
'node_modules/angular-ui-router/release/angular-ui-router.js',
'node_modules/angular-clipboard/angular-clipboard.js',
'node_modules/lodash/lodash.js',
'node_modules/moment/moment.js',
'node_modules/angular-ui-grid/ui-grid.js',
'node_modules/ng-file-upload/dist/ng-file-upload.js',
'node_modules/ui-select/dist/select.js',
'node_modules/angular-xeditable/dist/js/xeditable.js',
'node_modules/comma-separated-values/csv.js',
'node_modules/angular-recaptcha/release/angular-recaptcha.js',
'node_modules/angular-jwt/dist/angular-jwt.js',
'node_modules/angular-local-storage/dist/angular-local-storage.js'
]
// gulp.task('closure', function() {
// return gulp.src(vendorJsSources.concat(appJsSources))
// .pipe(closure({
// compilation_level: 'SIMPLE',
// // warning_level: 'VERBOSE',
// output_wrapper: '(function(){\n%output%\n}).call(this)',
// js_output_file: 'orrportal.closure.min.js'
// }))
// .pipe(sourcemaps.write('/')) // gulp-sourcemaps automatically adds the sourcemap url comment
// .pipe(gulp.dest(distDest))
// });