-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
69 lines (59 loc) · 1.77 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
const { src, dest, series, parallel } = require('gulp');
const del = require('del');
const fs = require('fs');
const zip = require('gulp-zip');
const log = require('fancy-log');
const webpack_stream = require('webpack-stream');
const webpack_config = require('./webpack.config.js');
var exec = require('child_process').exec;
const paths = {
prod_build: 'prod-build',
server_file_name: 'server.bundle.js',
angular_src: 'my-app/dist/**/*',
angular_dist: 'prod-build/my-app/dist',
zipped_file_name: 'angular-nodejs.zip'
};
function clean() {
log('removing the old files in the directory')
return del('prod-build/**', {force:true});
}
function createProdBuildFolder() {
const dir = paths.prod_build;
log(`Creating the folder if not exist ${dir}`)
if(!fs.existsSync(dir)) {
fs.mkdirSync(dir);
log('📁 folder created:', dir);
}
return Promise.resolve('the value is ignored');
}
function buildAngularCodeTask(cb) {
log('building Angular code into the directory')
return exec('cd my-app && npm run build', function (err, stdout, stderr) {
log(stdout);
log(stderr);
cb(err);
})
}
function copyAngularCodeTask() {
log('copying Angular code into the directory')
return src(`${paths.angular_src}`)
.pipe(dest(`${paths.angular_dist}`));
}
function copyNodeJSCodeTask() {
log('building and copying server code into the directory')
return webpack_stream(webpack_config)
.pipe(dest(`${paths.prod_build}`))
}
function zippingTask() {
log('zipping the code ')
return src(`${paths.prod_build}/**`)
.pipe(zip(`${paths.zipped_file_name}`))
.pipe(dest(`${paths.prod_build}`))
}
exports.default = series(
clean,
createProdBuildFolder,
buildAngularCodeTask,
parallel(copyAngularCodeTask, copyNodeJSCodeTask),
zippingTask
);