forked from brookshi/Hitchhiker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
116 lines (101 loc) · 3.73 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
var gulp = require('gulp'),
argv = require('yargs').argv,
replace = require('gulp-replace'),
exec = require('child_process').exec,
fs = require('fs-extra'),
path = require('path'),
archiver = require('archiver');
gulp.task('build', ['copyTemplate', 'copyGlobalData', 'copyLocales', 'createBackupFolder']);
gulp.task('package', ['release'], function () {
const keepFiles = ['build', 'node_modules', 'appconfig.json', 'gulpfile.js', 'logconfig.json', 'mail.json', 'pm2.json', 'sample collection.json', 'tsconfig.json'];
const files = fs.readdirSync(__dirname);
files.forEach(f => {
if (!keepFiles.find(fileName => f.endsWith(fileName))) {
fs.removeSync(f)
}
});
const zipPath = __dirname;
const zipFile = `${zipPath}.zip`;
if (fs.existsSync(zipFile)) {
fs.unlinkSync(zipFile);
}
const output = fs.createWriteStream(zipFile);
const archive = archiver('zip');
let isClose = false;
output.on('close', () => {
isClose = true;
});
output.on('end', () => {
isClose = true;
});
archive.pipe(output);
archive.directory(zipPath, false);
archive.finalize();
});
gulp.task('release', ['copy', 'copyTemplate', 'copyGlobalData', 'copyLocales', 'createBackupFolder']);
gulp.task('copy', ['compilerClient'], function () {
return gulp.src('./client/build/**/*.*')
.pipe(gulp.dest('./build/public'))
.on('end', function () {
gulp.src('./pm2.json')
.pipe(gulp.dest('./build'))
});
});
gulp.task('copyTemplate', function () {
fs.removeSync(path.join(__dirname, 'build/mail/templates'));
return gulp.src('./api/mail/templates/**/*.*')
.pipe(gulp.dest('./build/mail/templates'));
});
gulp.task('copyGlobalData', function () {
let globalPath = path.join(__dirname, 'build/global_data');
fs.removeSync(globalPath);
fs.mkdirpSync(`${globalPath}/project`);
return gulp.src('./api/global_data/**/*.*')
.pipe(gulp.dest('./build/global_data'));
});
gulp.task('copyLocales', function () {
fs.removeSync(path.join(__dirname, 'build/locales'));
return gulp.src('./api/locales/**/*.*')
.pipe(gulp.dest('./build/locales'));
});
gulp.task('createBackupFolder', function () {
const backupFolder = path.join(__dirname, 'build/backup');
if (fs.existsSync(backupFolder)) {
fs.removeSync(backupFolder);
}
fs.mkdirSync(backupFolder, 0o666);
});
gulp.task('compilerClient', ['compilerServer'], function (cb) {
process.chdir('./client');
exec('yarn build', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
process.chdir('../');
cb();
});
});
gulp.task('compilerServer', ['config'], function (cb) {
exec('tsc -p . -w false', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb();
});
});
gulp.task('config', [], function () {
return gulp.src('./client/src/utils/urls.ts')
.pipe(replace('http://localhost:3000/', 'HITCHHIKER_APP_HOST'))
.pipe(gulp.dest('./client/src/utils/'))
.on('end', function () {
gulp.src('./appconfig.json')
.pipe(replace('localhost:3000', `localhost:8080`))
.pipe(replace('localhost:81', `localhost:8080`))
.pipe(replace('"database": "hitchhiker"', '"database": "hitchhiker-prod"'))
.pipe(replace('DEV', `PROD`))
.pipe(gulp.dest('./'))
.on('end', function () {
gulp.src('./client/package.json')
.pipe(replace('localhost:81', `localhost:8080`))
.pipe(gulp.dest('./client/'));
});
});
});