-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
73 lines (65 loc) · 2.27 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
const gulp = require('gulp');
const run = require('gulp-run');
const gulpClean = require('gulp-clean');
const replace = require('gulp-replace');
function clean() {
console.log("Start cleaning old builds.");
return gulp.src('dist', {
read: false,
allowEmpty: true
})
.pipe(gulpClean())
}
function runWebpack() {
console.log("Start building server with webpack.");
let index = process.argv.indexOf('--mode');
if (index > -1) {
let mode = process.argv[index + 1];
if (mode === 'production') {
return run('npx webpack --config webpack.production.js').exec();
} else {
console.log("Mode is not send as gulp arguments");
throw new Error("Mode is not send as gulp arguments");
}
} else {
return run('npx webpack --config webpack.development.js').exec();
}
}
function version() {
let index = process.argv.indexOf('--releaseVersion');
if (index > -1) {
let releaseVersion = process.argv[index + 1];
console.log("Release version is :" + releaseVersion);
return gulp.src('package.json')
.pipe(replace(/(\"version\"\s*:\s*\"\d+\.\d+\.\d+)(\"|\-SNAPSHOT\")/,
'"version' + '": "' + releaseVersion + '"'))
.pipe(gulp.dest('./', {
overwrite: true
}))
} else {
console.log("Version is not send as gulp arguments");
throw new Error("Version is not send as gulp arguments");
}
}
function copyPackageJson() {
console.log("Copying package.json file to build directory.");
gulp.src('dist/server.js.map', {
read: false,
allowEmpty: true
}).pipe(gulpClean());
return gulp.src('package.json').pipe(gulp.dest('dist/'));
}
function installingDependencies() {
process.env.NODE_ENV = "production";
process.chdir('dist/');
console.log("Running npm install to fetch bundle dependencies.");
return run('npm install').exec();
}
function packageFiles() {
console.log("Packaging deployment file.");
return run('npm pack').exec();
}
const build = gulp.series(runWebpack, version, copyPackageJson, installingDependencies, packageFiles);
exports.build = build;
exports.clean = clean;
exports.default = gulp.series(clean, build);