Skip to content

Commit

Permalink
chore: remove upload to CDN task
Browse files Browse the repository at this point in the history
  • Loading branch information
leeyeh committed Oct 31, 2019
1 parent efc91e0 commit 1fefd04
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 206 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ npm install leancloud-storage@2 --save
5. 使用 GitHub 基于 dist 分支发布一个 release
6. Fetch and checkout remote `dist` branch 并确认该提交的内容是即将发布的版本
7. npm publish(`npm publish`,需 npm 协作者身份),如果是 pre-release 版本需要带 next tag
8. 发布到 CDN,需要七牛权限(执行 `gulp upload`
64 changes: 14 additions & 50 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,43 @@
/**
* 每位工程师都有保持代码优雅的义务
* Each engineer has a duty to keep the code elegant
**/
**/

import path from 'path';
import qiniu from 'qiniu';
import fs from 'fs';
import gulp from 'gulp';
import clean from 'gulp-clean';
import babel from 'gulp-babel';
import shell from 'gulp-shell';
import { version } from './package.json';

const uploadCDN = (file) => {
qiniu.conf.ACCESS_KEY = process.env.CDN_QINIU_KEY;
qiniu.conf.SECRET_KEY = process.env.CDN_QINIU_SECRET;
if (!qiniu.conf.ACCESS_KEY || !qiniu.conf.SECRET_KEY) {
throw new Error('Need Qiniu CDN_QINIU_KEY and CDN_QINIU_SECRET');
}
const bucketname = 'paas_files';
const key = `static/js/${version}/${path.basename(file)}`;
const putPolicy = new qiniu.rs.PutPolicy(bucketname + ':' + key);
const uptoken = putPolicy.token();
const extra = new qiniu.io.PutExtra();
extra.mimeType = 'application/javascript';
const buffer = fs.readFileSync(file);
qiniu.io.put(uptoken, key, buffer, extra, (err, ret) => {
if (!err) {
console.log('https://cdn1.lncld.net/' + ret.key);
} else {
console.log(err);
}
});
return file;
};

gulp.task('clean-dist', () =>
gulp.src([
'dist/**/*.*',
]).pipe(clean({
force: true
}))
gulp.src(['dist/**/*.*']).pipe(
clean({
force: true,
})
)
);

// 编译浏览器版本
gulp.task('bundle-browser', ['clean-dist'], shell.task('npm run build:browser'));
gulp.task(
'bundle-browser',
['clean-dist'],
shell.task('npm run build:browser')
);
gulp.task('bundle-rn', ['clean-dist'], shell.task('npm run build:rn'));
gulp.task('bundle-weapp', ['clean-dist'], shell.task('npm run build:weapp'));

// 编译出 Node 版本
gulp.task('babel-node', ['clean-dist'], () => {
return gulp.src('src/**/*.js')
return gulp
.src('src/**/*.js')
.pipe(babel())
.pipe(gulp.dest('dist/node/'));
});

// 上传到 CDN
gulp.task('upload', () => {
[
'./dist/av-min.js',
'./dist/av-weapp-min.js',
'./dist/av.js',
'./dist/av-weapp.js',
'./dist/av-live-query-min.js',
'./dist/av-live-query-weapp-min.js',
'./dist/av-live-query.js',
'./dist/av-live-query-weapp.js',
].map(uploadCDN).map(file => `${file}.map`).map(uploadCDN);
});

// 生成 release 文件
gulp.task('build', [
'clean-dist',
'bundle-browser',
'bundle-rn',
'bundle-weapp',
'babel-node'
'babel-node',
]);
Loading

0 comments on commit 1fefd04

Please sign in to comment.