-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
87 lines (84 loc) · 2.5 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
const fs = require('fs');
const path = require('path');
const gulp = require('gulp');
const vsftp = require('gulp-vsftp');
const zip = require('gulp-zip');
const moment = require('moment-kirk');
const webpackFile = require('./config/webpack/webpack.file.conf');
const packageInfo = require('./package.json');
/*修改myConfig*/
gulp.task('modifyToDev', () => {
let filePath = './app/public/js/myConfig.js';
let myConfig = fs.readFileSync(filePath, 'utf-8');
myConfig = myConfig.replace(/environment:\s'product'/, "environment: 'development'");
return fs.writeFile(
filePath,
myConfig,
function(err) {
if (err) {
return console.log(err);
}
console.log('myConfig修改为开发环境!', path.resolve());
}
);
});
gulp.task('modifyToPro', () => {
let filePath = './app/public/js/myConfig.js';
let myConfig = fs.readFileSync(filePath, 'utf-8');
myConfig = myConfig.replace(/environment:\s'development'/, "environment: 'product'");
return fs.writeFile(
filePath,
myConfig,
function(err) {
if (err) {
return console.log(err);
}
console.log('myConfig修改为生产环境!', path.resolve());
}
);
});
/*生成构建时间 存放在 生产目录里*/
gulp.task('buildTime', () =>
fs.writeFile(
path.resolve(webpackFile.proDirectory) + '/buildTime.txt',
moment(new Date()).format('YYYY-MM-DD HH:mm:ss') + ' ' + packageInfo.version,
function(err) {
if (err) {
return console.log(err);
}
console.log('The file was saved!', path.resolve());
}
)
);
/*打包生产目录*/
gulp.task('zip', () =>
gulp
.src(path.resolve(webpackFile.proDirectory + '/**'))
.pipe(zip('pc-[' + packageInfo.version + ']-[' + moment(new Date()).format('YYYY-MM-DD HH-mm-ss') + '].zip'))
.pipe(gulp.dest('backup'))
);
/*上传生产目录到测试环境*/
gulp.task('test', function() {
return gulp.src(webpackFile.proDirectory + '/**').pipe(
vsftp({
host: '192.168.1.100',
user: 'developer',
pass: 'xxxxxxxxxxxxx',
cleanFiles: true,
remotePath: '/docker-developer-test/modules/www/static/pc/'
})
);
});
/*上传生产目录到预生成环境*/
gulp.task('prep', function() {
return gulp.src(webpackFile.proDirectory + '/**').pipe(
vsftp({
host: '192.168.1.101',
user: 'developer',
pass: 'xxxxxxxxxxxxx',
cleanFiles: true,
remotePath: '/data1/docker-developer-test/modules/web/pc/'
})
);
});
/*如果有其他环境,可以继续往下面写*/