Skip to content

Commit

Permalink
Merge pull request #2 from BearJ/master
Browse files Browse the repository at this point in the history
chore: 优化CI流程
  • Loading branch information
uxsi authored Jul 15, 2019
2 parents c141999 + eeb0227 commit 9fd428a
Show file tree
Hide file tree
Showing 4 changed files with 1,031 additions and 21 deletions.
53 changes: 53 additions & 0 deletions .picklogrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const origin = 'https://github.com/Tencent/weui';
const comparePath = `${origin}/compare/`;
const commitPath = `${origin}/commit/`;

module.exports = {
filters: [
{
name: 'Features',
regExp: /^(?:feat|add)/i,
},
{
name: 'Bugfixes',
regExp: /^fix/i,
},
{
name: 'Style',
regExp: /^style/i,
},
{
name: 'Performance',
regExp: /^perf/i,
}
],
parse(commits){
// RegExp.prototype.toJSON = RegExp.prototype.toString; // JSON.stringify会调用正则表达式的toJSON
// return JSON.stringify(commits, null, 2); // output commits

let output = '';

commits.forEach((log) => {
let date = new Date(log.timestamp * 1000);
date = `${date.getFullYear()}-${('0' + (date.getMonth() + 1)).substr(-2)}-${('0' + date.getDate()).substr(-2)}`;

let currentTag = log.tag || log.commits[0].h;
let prevTag = log.previousTag || log.commits[log.commits.length - 1].h;
output += `### [${currentTag}](${comparePath}${prevTag || ''}...${currentTag}) (${date})\n\n`;

log.results.forEach((result) => {
output += `#### ${result.filter.name}\n`;

result.commits.forEach((commit) => {
output += `* ${commit.s}([${commit.h}](${commitPath}${commit.h}))\n`;
});

output += '\n';
});

output += '\n\n';
});

return output;
}
};
61 changes: 58 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ var comments = require('postcss-discard-comments');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync');
var prompt = require('inquirer').prompt;
var childProcess = require('child_process');
var pkg = require('./package.json');
var bower = require('./bower.json');
var yargs = require('yargs').options({
w: {
alias: 'watch',
Expand All @@ -30,6 +33,21 @@ var yargs = require('yargs').options({
var option = { base: 'src' };
var dist = __dirname + '/dist';

function exec (cmd) {
return new Promise((resolve, reject) => {
const process = childProcess.exec(cmd, (error) => {
if (error) {
reject(error);
} else {
resolve();
}
});
process.stdout.on('data', function(data) {
console.log(data);
});
});
}

gulp.task('build:style', function() {
var banner = [
'/*!',
Expand Down Expand Up @@ -129,9 +147,9 @@ gulp.task('build:example', [
'build:example:html'
]);

gulp.task('release', ['build:style', 'build:example']);
gulp.task('build', ['build:style', 'build:example']);

gulp.task('watch', ['release'], function() {
gulp.task('watch', ['build'], function() {
gulp.watch('src/style/**/*', ['build:style']);
gulp.watch('src/example/example.less', ['build:example:style']);
gulp.watch('src/example/**/*.?(png|jpg|gif|js)', ['build:example:assets']);
Expand All @@ -155,11 +173,48 @@ gulp.task('server', function() {
});
});

gulp.task('release', function() {
return new Promise(async (resolve) => {
try {
const answers = await prompt({
type: 'input',
name: 'tag',
message: 'Input a tag:',
});

const tag = answers.tag.replace(/^v/, '');
const tagName = `v${tag}`;

pkg.version = tag;
bower.version = tag;
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 4));
fs.writeFileSync('bower.json', JSON.stringify(bower, null, 4));

console.log('Building Project');
await exec(`npm run build && git add . && git commit -m "[release] ${tagName}"`);

console.log(`Setting tag ${tagName}`);
await exec(`git tag ${tagName}`);

console.log('Generating Changelog');
await exec(`npm run changelog && git add . && git commit -m "docs: update changelog"`);

console.log('Pushing Project');
await exec('git push && git push --tag');

console.log('Release Success!');
resolve();
} catch(error) {
throw error;
}
});
});

// 参数说明
// -w: 实时监听
// -s: 启动服务器
// -p: 服务器启动端口,默认8080
gulp.task('default', ['release'], function() {
gulp.task('default', ['build'], function() {
if (yargs.s) {
gulp.start('server');
}
Expand Down
Loading

0 comments on commit 9fd428a

Please sign in to comment.