forked from metadatacenter/cedar-template-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
473 lines (423 loc) · 14.4 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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
// Include gulp & gulp plugins
var gulp = require('gulp'),
jshint = require('gulp-jshint'),
less = require('gulp-less'),
stylish = require('jshint-stylish'),
autoprefixer = require('gulp-autoprefixer'),
gutil = require('gulp-util'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
minifyCSS = require('gulp-minify-css'),
connect = require('gulp-connect'),
htmlreplace = require('gulp-html-replace'),
ngAnnotate = require('gulp-ng-annotate'),
historyApiFallback = require('connect-history-api-fallback'),
Server = require('karma').Server,
protractor = require('gulp-protractor').protractor,
replace = require('gulp-replace'),
wait = require('gulp-wait'),
colors = require('colors'),
Proxy = require('gulp-connect-proxy',
request = require('sync-request'),
fs = require('fs')
);
/**
* Create error handling exception using gulp-util.
*/
var onError = function (err) {
gutil.beep();
console.log(err.red);
this.emit('end'); //added so that gulp will end the task on error, and won't hang.
};
// Lint task
gulp.task('lint', function (done) {
return gulp.src('app/scripts/*.js')
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(connect.reload());
done();
});
// Compile LESS files
gulp.task('less', function (done) {
return gulp.src(['app/less/style-creator.less'])
.pipe(plumber({
errorHandler: onError
}))
.pipe(less().on('error', gutil.log))
.pipe(autoprefixer({
browsers: ['> 1%', 'last 2 versions', 'Firefox ESR', 'Opera 12.1', 'IE 9'],
cascade : true
}))
.pipe(gulp.dest('app/css'))
.pipe(connect.reload());
done();
});
gulp.task('copy:resources', function () {
var glyphiconsGlob = 'app/bower_components/bootstrap/fonts/*.*';
return gulp.src(glyphiconsGlob).pipe(gulp.dest('app/fonts/'));
});
gulp.task('server-development', function (done) {
console.log("Server development");
connect.server({
root : 'app',
port : 4200,
livereload: true,
fallback : 'app/index.html'
});
done();
});
gulp.task('html', function (done) {
return gulp.src('/app/views/*.html')
.pipe(connect.reload());
done();
});
// Task to replace service URLs
gulp.task('replace-url', function (done) {
gulp.src(['app/config/src/url-service.conf.json'])
.pipe(replace('templateServerUrl', 'https://template.' + cedarRestHost))
.pipe(replace('resourceServerUrl', 'https://resource.' + cedarRestHost))
.pipe(replace('userServerUrl', 'https://user.' + cedarRestHost))
.pipe(replace('terminologyServerUrl', 'https://terminology.' + cedarRestHost))
.pipe(replace('resourceServerUrl', 'https://resource.' + cedarRestHost))
.pipe(replace('valueRecommenderServerUrl', 'https://valuerecommender.' + cedarRestHost))
.pipe(replace('groupServerUrl', 'https://group.' + cedarRestHost))
.pipe(replace('schemaServerUrl', 'https://schema.' + cedarRestHost))
.pipe(replace('submissionServerUrl', 'https://submission.' + cedarRestHost))
.pipe(replace('messagingServerUrl', 'https://messaging.' + cedarRestHost))
.pipe(replace('openViewBaseUrl', 'https://openview.' + cedarRestHost))
.pipe(replace('impexServerUrl', 'https://impex.' + cedarRestHost))
.pipe(replace('artifactsFrontendUrl', 'https://artifacts.' + cedarRestHost))
.pipe(replace('dataciteDOIBaseUrl', 'https://bridging.' + cedarRestHost + '/doi/datacite'))
.pipe(gulp.dest('app/config/'));
done();
});
// Task to set up tracking
gulp.task('replace-tracking', function (done) {
gulp.src(['app/config/src/tracking-service.conf.json'])
.pipe(replace('googleAnalyticsKey', cedarAnalyticsKey))
.pipe(gulp.dest('app/config/'));
done();
});
// Task to set up version numbers in included js file
gulp.task('replace-version', function (done) {
gulp.src(['app/config/src/version.js'])
.pipe(replace('cedarVersionValue', cedarVersion))
.pipe(replace('cedarVersionModifierValue', cedarVersionModifier))
.pipe(replace('dataciteEnabledValue', dataciteEnabled))
.pipe(gulp.dest('app/config/'));
done();
});
// Watch files for changes
gulp.task('watch', function (done) {
gulp.watch('app/scripts/*.js', gulp.series('lint'));
gulp.watch('app/less/*.less', gulp.series('less'));
gulp.watch('app/views/*.html', gulp.series('html'));
done();
});
// Sets up the environment required to run the Karma tests in Travis
gulp.task('karma-travis-env', gulp.series(['replace-url', 'replace-tracking', 'replace-version', 'lint', 'less', 'copy:resources'], function (done) {
done();
}));
gulp.task('karma-tests', function (done) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, function (exitCode) {
done();
process.exit(exitCode);
}).start();
});
gulp.task('test-env', function (done) {
gulp.src(['tests/config/src/test-env.js'], {allowEmpty:true})
.pipe(replace('protractorBaseUrl', 'https://cedar.' + cedarUIHost))
.pipe(replace('protractorTestUser1Login', cedarTestUser1Login))
.pipe(replace('protractorTestUser1Password', cedarTestUser1Password))
.pipe(replace('protractorTestUser1Name', cedarTestUser1Name))
.pipe(replace('protractorTestUser2Login', cedarTestUser2Login))
.pipe(replace('protractorTestUser2Password', cedarTestUser2Password))
.pipe(replace('protractorTestUser2Name', cedarTestUser2Name))
.pipe(replace('protractorCedarVersion', cedarVersion))
.pipe(gulp.dest('tests/config/'));
done();
});
// Protractor tests
gulp.task('test-clean-up', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/clean-up-spec.js'
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test-work-space', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/workspace-spec.js'
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test-staging', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/staging-spec.js'
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test-sidebar', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/sidebar-spec.js'
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test-all', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/clean-up-spec.js',
'./tests/e2e/sidebar-spec.js',
'./tests/e2e/metadata-creator-spec.js',
'./tests/e2e/template-creator-spec.js',
'./tests/e2e/copy-move-spec.js',
'./tests/e2e/share-delete-spec.js',
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test-folder-permissions', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/clean-up-spec.js',
'./tests/e2e/folder-permissions-spec.js',
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test-resource-permissions', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/clean-up-spec.js',
'./tests/e2e/resource-permissions-spec.js',
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test-delete', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/create-folders-spec.js',
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test-copy-move', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/copy-move-spec.js',
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test-share-delete', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/share-delete-spec.js',
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test-permissions', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/delete-resource-spec.js',
'./tests/e2e/folder-permissions-spec.js',
'./tests/e2e/resource-permissions-spec.js',
'./tests/e2e/update-permissions-spec.js'
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test-update-permissions', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/update-permissions-spec.js'
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test--update-permissions', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/update-permissions-spec.js'
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test-metadata', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/metadata-creator-spec.js'
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test-template', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/template-creator-spec.js'
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
gulp.task('test-form', gulp.series('test-env', function () {
return gulp.src([
'./tests/e2e/metadata-creator-spec.js',
'./tests/e2e/template-creator-spec.js'
])
.pipe(protractor({
configFile: "protractor-sequential.config.js"
}))
.on('error', function (e) {
throw e
});
}));
function exitWithError(msg) {
onError(msg);
console.log(
"Please see: https://github.com/metadatacenter/cedar-docs/wiki/Configure-environment-variables-on-OS-X".yellow);
console.log("Please restart the application after setting the variables!".green);
console.log();
console.log();
process.exit();
}
function readAllEnvVarsOrFail() {
console.log("- Environment variables used:".yellow);
for (var key in envConfig) {
if (!process.env.hasOwnProperty(key)) {
exitWithError('You need to set the following environment variable: ' + key);
} else {
var value = process.env[key];
envConfig[key] = value;
if (key.indexOf('PASSWORD') <= -1) {
console.log(("- Environment variable " + key + " found: ").green + value.bold);
} else {
console.log(("- Environment variable " + key + " found: ").green + "*******".bold);
}
}
}
}
function getFrontendEnvVar(varNameSuffix) {
return 'CEDAR_FRONTEND_' + cedarFrontendTarget + '_' + varNameSuffix;
}
// Get environment variables
let envConfig = {
'CEDAR_ANALYTICS_KEY' : null,
'CEDAR_FRONTEND_BEHAVIOR' : null,
'CEDAR_FRONTEND_TARGET' : null,
'CEDAR_VERSION' : null,
'CEDAR_VERSION_MODIFIER' : null,
'CEDAR_DATACITE_ENABLED' : null
};
console.log();
console.log();
console.log(
"-------------------------------------------- ************* --------------------------------------------".red);
console.log("- Starting CEDAR front end server...".green);
readAllEnvVarsOrFail();
const cedarAnalyticsKey = envConfig['CEDAR_ANALYTICS_KEY'];
const cedarFrontendBehavior = envConfig['CEDAR_FRONTEND_BEHAVIOR'];
const cedarFrontendTarget = envConfig['CEDAR_FRONTEND_TARGET'];
const cedarVersion = envConfig['CEDAR_VERSION'];
const cedarVersionModifier = envConfig['CEDAR_VERSION_MODIFIER'];
const dataciteEnabled = envConfig['CEDAR_DATACITE_ENABLED'];
var cedarUIHostVarName = getFrontendEnvVar('UI_HOST');
envConfig[cedarUIHostVarName] = null;
var cedarRestHostVarName = getFrontendEnvVar('REST_HOST');
envConfig[cedarRestHostVarName] = null;
var cedarUser1LoginVarName = getFrontendEnvVar('USER1_LOGIN');
envConfig[cedarUser1LoginVarName] = null;
var cedarUser1PasswordVarName = getFrontendEnvVar('USER1_PASSWORD');
envConfig[cedarUser1PasswordVarName] = null;
var cedarUser1NameVarName = getFrontendEnvVar('USER1_NAME');
envConfig[cedarUser1NameVarName] = null;
var cedarUser2LoginVarName = getFrontendEnvVar('USER2_LOGIN');
envConfig[cedarUser2LoginVarName] = null;
var cedarUser2PasswordVarName = getFrontendEnvVar('USER2_PASSWORD');
envConfig[cedarUser2PasswordVarName] = null;
var cedarUser2NameVarName = getFrontendEnvVar('USER2_NAME');
envConfig[cedarUser2NameVarName] = null;
readAllEnvVarsOrFail();
var cedarUIHost = envConfig[cedarUIHostVarName];
var cedarRestHost = envConfig[cedarRestHostVarName];
var cedarTestUser1Login = envConfig[cedarUser1LoginVarName];
var cedarTestUser1Password = envConfig[cedarUser1PasswordVarName];
var cedarTestUser1Name = envConfig[cedarUser1NameVarName];
var cedarTestUser2Login = envConfig[cedarUser2LoginVarName];
var cedarTestUser2Name = envConfig[cedarUser2NameVarName];
var cedarTestUser2Password = envConfig[cedarUser2PasswordVarName];
console.log(
"-------------------------------------------- ************* --------------------------------------------".red);
console.log();
// Prepare task list
var taskNameList = [];
if (cedarFrontendBehavior === 'develop') {
taskNameList.push('server-development');
taskNameList.push('watch');
} else if (cedarFrontendBehavior === 'server') {
console.log("Editor is configuring URLs, and exiting. The frontend content will be served by nginx");
} else {
exitWithError("Invalid CEDAR_FRONTEND_BEHAVIOR value. Please set to 'develop' or 'server'!");
}
taskNameList.push('lint', 'less', 'copy:resources', 'replace-url', 'replace-tracking', 'replace-version', 'test-env');
// Launch tasks
gulp.task('default', gulp.series(taskNameList, function (done) {
done();
}));