-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
97 lines (91 loc) · 3.22 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
var gulp = require('gulp'),
replace = require('gulp-replace'),
exec = require('child_process').exec,
fs = require('fs'),
easeftp = require('easeftp'),
upload = require('easeftp/upload').add,
ftppass = JSON.parse(fs.readFileSync('.ftppass', 'utf-8')),
pkg = require('./package.json'),
plumber = require('gulp-plumber'),
gulpTinyPng = require('gulp-tinypng-extended')
gulp.task('tinypng-dist', function () {
gulp.src('dist/**/*.{png,jpg,jpeg}')
.pipe(plumber())
.pipe(gulpTinyPng({
key: ftppass.tinypng.key,
sigFile: '.tinypng-sigs',
sameDest: true,
summarise: true,
log: true
}))
.pipe(gulp.dest('dist'))
})
gulp.task('test', function () {
exec(`cp -rf dist ${pkg.name}`, function () {
exec(`scp -r ${pkg.name} ${ftppass.test.username}@${ftppass.test.host}:/home/appops/app/activity`, function (e) {
e && console.log(e)
exec(`rm -rf ${pkg.name}`)
})
})
})
gulp.task('pre', function () {
exec(`cp -rf dist ${pkg.name}`, function () {
exec(`scp -r ${pkg.name} ${ftppass.pre.username}@${ftppass.pre.host}:/home/appops/htmlfile/activity`, function (e) {
e && console.log(e)
exec(`rm -rf ${pkg.name}`)
})
})
})
// 上传的html地址为`http://wp.m.163.com/163/html/${pkg.name}/index.html`
gulp.task('publish', function () {
if (!pkg.projectId) {
throw new Error('package.json中未添加统计的projectId')
}
const statistics = [
`<script>window.projectId ="${pkg.projectId}"; (function(w,d,s,n) {var f=d.getElementsByTagName(s)[0],k=d.createElement(s);k.async=true;k.src="//static.ws.126.net/163/frontend/antnest/"+n+".js";f.parentNode.insertBefore(k,f);})(window,document,"script","${pkg.projectId}");</script>`
].join('')
gulp.src(['dist/index.html'])
.pipe(replace('</head>', statistics))
.pipe(gulp.dest('dist/'))
upload(['index.html', 'sw.js'], {
username: ftppass.easeftp.username,
password: ftppass.easeftp.password,
path: 'html/' + pkg.name,
debug: true,
cwd: './dist', //指定匹配的根目录
}).then(({urls}) => {
console.log(urls)
})
upload(['**/**'], {
username: ftppass.easeftp.username,
password: ftppass.easeftp.password,
path: 'activity/' + pkg.name, //cdn线上路径
debug: true,
cwd: './dist', //指定匹配的根目录
exclude: ['index.html', '*.map', 'sw.js']
}).then(({urls}) => {
// console.log(urls)
})
})
gulp.task('tinypng-src-static', function () {
gulp.src('src/**/*.{png,jpg,jpeg}')
.pipe(plumber())
.pipe(gulpTinyPng({
key: ftppass.tinypng.key,
sigFile: '.tinypng-sigs',
sameDest: true,
summarise: true,
log: true
}))
.pipe(gulp.dest('src'))
gulp.src('static/**/*.{png,jpg,jpeg}')
.pipe(plumber())
.pipe(gulpTinyPng({
key: ftppass.tinypng.key,
sigFile: '.tinypng-sigs',
sameDest: true,
summarise: true,
log: true
}))
.pipe(gulp.dest('static'))
})