|
1 | 1 | /** |
2 | 2 | * 每位工程师都有保持代码优雅的义务 |
3 | 3 | * Each engineer has a duty to keep the code elegant |
4 | | -**/ |
| 4 | + **/ |
5 | 5 |
|
6 | | -import path from 'path'; |
7 | | -import qiniu from 'qiniu'; |
8 | | -import fs from 'fs'; |
9 | 6 | import gulp from 'gulp'; |
10 | 7 | import clean from 'gulp-clean'; |
11 | 8 | import babel from 'gulp-babel'; |
12 | 9 | import shell from 'gulp-shell'; |
13 | | -import { version } from './package.json'; |
14 | | - |
15 | | -const uploadCDN = (file) => { |
16 | | - qiniu.conf.ACCESS_KEY = process.env.CDN_QINIU_KEY; |
17 | | - qiniu.conf.SECRET_KEY = process.env.CDN_QINIU_SECRET; |
18 | | - if (!qiniu.conf.ACCESS_KEY || !qiniu.conf.SECRET_KEY) { |
19 | | - throw new Error('Need Qiniu CDN_QINIU_KEY and CDN_QINIU_SECRET'); |
20 | | - } |
21 | | - const bucketname = 'paas_files'; |
22 | | - const key = `static/js/${version}/${path.basename(file)}`; |
23 | | - const putPolicy = new qiniu.rs.PutPolicy(bucketname + ':' + key); |
24 | | - const uptoken = putPolicy.token(); |
25 | | - const extra = new qiniu.io.PutExtra(); |
26 | | - extra.mimeType = 'application/javascript'; |
27 | | - const buffer = fs.readFileSync(file); |
28 | | - qiniu.io.put(uptoken, key, buffer, extra, (err, ret) => { |
29 | | - if (!err) { |
30 | | - console.log('https://cdn1.lncld.net/' + ret.key); |
31 | | - } else { |
32 | | - console.log(err); |
33 | | - } |
34 | | - }); |
35 | | - return file; |
36 | | -}; |
37 | 10 |
|
38 | 11 | gulp.task('clean-dist', () => |
39 | | - gulp.src([ |
40 | | - 'dist/**/*.*', |
41 | | - ]).pipe(clean({ |
42 | | - force: true |
43 | | - })) |
| 12 | + gulp.src(['dist/**/*.*']).pipe( |
| 13 | + clean({ |
| 14 | + force: true, |
| 15 | + }) |
| 16 | + ) |
44 | 17 | ); |
45 | 18 |
|
46 | 19 | // 编译浏览器版本 |
47 | | -gulp.task('bundle-browser', ['clean-dist'], shell.task('npm run build:browser')); |
| 20 | +gulp.task( |
| 21 | + 'bundle-browser', |
| 22 | + ['clean-dist'], |
| 23 | + shell.task('npm run build:browser') |
| 24 | +); |
48 | 25 | gulp.task('bundle-rn', ['clean-dist'], shell.task('npm run build:rn')); |
49 | 26 | gulp.task('bundle-weapp', ['clean-dist'], shell.task('npm run build:weapp')); |
50 | 27 |
|
51 | 28 | // 编译出 Node 版本 |
52 | 29 | gulp.task('babel-node', ['clean-dist'], () => { |
53 | | - return gulp.src('src/**/*.js') |
| 30 | + return gulp |
| 31 | + .src('src/**/*.js') |
54 | 32 | .pipe(babel()) |
55 | 33 | .pipe(gulp.dest('dist/node/')); |
56 | 34 | }); |
57 | 35 |
|
58 | | -// 上传到 CDN |
59 | | -gulp.task('upload', () => { |
60 | | - [ |
61 | | - './dist/av-min.js', |
62 | | - './dist/av-weapp-min.js', |
63 | | - './dist/av.js', |
64 | | - './dist/av-weapp.js', |
65 | | - './dist/av-live-query-min.js', |
66 | | - './dist/av-live-query-weapp-min.js', |
67 | | - './dist/av-live-query.js', |
68 | | - './dist/av-live-query-weapp.js', |
69 | | - ].map(uploadCDN).map(file => `${file}.map`).map(uploadCDN); |
70 | | -}); |
71 | | - |
72 | 36 | // 生成 release 文件 |
73 | 37 | gulp.task('build', [ |
74 | 38 | 'clean-dist', |
75 | 39 | 'bundle-browser', |
76 | 40 | 'bundle-rn', |
77 | 41 | 'bundle-weapp', |
78 | | - 'babel-node' |
| 42 | + 'babel-node', |
79 | 43 | ]); |
0 commit comments