This repository has been archived by the owner on Oct 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
gulpfile.js
76 lines (64 loc) · 2.01 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
/* Copyright (c) Trainline Limited. All rights reserved. See LICENSE.txt in the project root for license information. */
'use strict';
let fs = require('fs');
let gulp = require('gulp');
let path = require('path');
let rimraf = require('rimraf');
let run = require('gulp-run');
let zip = require('gulp-vinyl-zip');
let { gitDescribe, readPackageFile, updateVersion } = require('./version.js');
const BUILD_DIR = path.resolve('./build');
const OUT_DIR = path.resolve('./dist');
function memoize(fn) {
let memo = new Map();
return (...args) => {
let key = JSON.stringify(args);
if (memo.has(key)) {
return memo.get(key);
} else {
let value = fn(...args);
memo.set(key, value);
return value;
}
}
}
let describeVersion = memoize(gitDescribe);
function getVersionFromGit(version) {
let description = describeVersion();
return description
.replace(/^v/i, '')
.replace(/-(g\w+)$/i, '+$1');
}
function npmInstall(cwd) {
return run('npm install --production', { cwd }).exec();
}
function copyServerFiles() {
return gulp.src([
'**/*',
'!acceptance-tests/**/*',
'!node_modules/**/*',
'!test/**/*',
'!.*',
'!configuration.sample.json'
], { cwd: './server', nodir: true })
.pipe(gulp.dest(BUILD_DIR));
}
function client() {
return run(`gulp build --gulpfile client/gulpfile.js -p -o ${BUILD_DIR}/dist`).exec();
}
function pack() {
updateVersion(BUILD_DIR, getVersionFromGit);
let version = getVersionFromGit();
fs.writeFileSync(path.resolve(`${BUILD_DIR}/version.txt`), version, { encoding: 'utf-8' });
return gulp.src(`${BUILD_DIR}/**/*`)
.pipe(zip.dest(`dist/environment-manager-${version}.zip`));
}
function clean(done) {
rimraf(`{${BUILD_DIR},${OUT_DIR}}`, done);
}
gulp.task('clean', clean);
gulp.task('copy-server-files', ['clean'], copyServerFiles);
gulp.task('server', ['copy-server-files'], () => npmInstall(BUILD_DIR));
gulp.task('client', ['clean'], client);
gulp.task('pack', ['client', 'server'], pack);
gulp.task('default', ['pack']);