Skip to content

Commit dc6acbb

Browse files
committed
chore: update npm publish script
1 parent 68a9472 commit dc6acbb

File tree

5 files changed

+224
-174
lines changed

5 files changed

+224
-174
lines changed

.npmrc.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
2+
loglevel=info
3+
registry=https://registry.npmjs.org/

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ node_js:
55
before_script:
66
- npm install vue vue-template-compiler
77
script:
8+
- cp ./scripts/.npmrc.template $HOME/.npmrc
89
- COVERAGE=true npm run test
910
- npm run codecov
11+
- npm run pub-with-ci
1012
- bash ./scripts/deploy-to-gh-pages.sh
1113
env:
1214
matrix:

antd-tools/gulpfile.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const fs = require('fs')
2525
const rimraf = require('rimraf')
2626
const replaceLib = require('./replaceLib')
2727
const stripCode = require('gulp-strip-code')
28+
const compareVersions = require('compare-versions')
2829

2930
const cwd = process.cwd()
3031
const libDir = path.join(cwd, 'lib')
@@ -173,7 +174,6 @@ function githubRelease () {
173174
const [_, owner, repo] = execSync('git remote get-url origin') // eslint-disable-line
174175
.toString()
175176
.match(/github.com[:/](.+)\/(.+)\.git/)
176-
177177
github.repos.createRelease({
178178
owner,
179179
repo,
@@ -236,6 +236,9 @@ function pub (done) {
236236
}
237237
})
238238
}
239+
// gulp.task('test', () => {
240+
// githubRelease()
241+
// })
239242

240243
gulp.task('dist', ['compile'], (done) => {
241244
dist(done)
@@ -261,6 +264,43 @@ gulp.task('pub', ['check-git', 'compile'], (done) => {
261264
}
262265
})
263266

267+
gulp.task('pub-with-ci', (done) => {
268+
if (process.env.NPM_TOKEN) {
269+
console.log('NPM token found, skip')
270+
} else {
271+
const github = new GitHub()
272+
github.authenticate({
273+
type: 'oauth',
274+
token: process.env.GITHUB_TOKEN,
275+
})
276+
const [_, owner, repo] = execSync('git remote get-url origin') // eslint-disable-line
277+
.toString()
278+
.match(/github.com[:/](.+)\/(.+)\.git/)
279+
const getLatestRelease = github.repos.getLatestRelease({
280+
owner,
281+
repo,
282+
})
283+
const getCommits = github.repos.getCommits({
284+
owner,
285+
repo,
286+
per_page: 1,
287+
})
288+
Promise.all([getLatestRelease, getCommits]).then(([latestRelease, commits]) => {
289+
const preVersion = latestRelease.data.tag_name
290+
const { version } = packageJson
291+
const [_, newVersion] = commits.data[0].commit.message.trim().match(/bump (.+)/) || []
292+
if (compareVersions(version, preVersion) === 1 && newVersion && newVersion.trim() === version) {
293+
gulp.run('pub', (err) => {
294+
err && console.log('err', err)
295+
done()
296+
})
297+
} else {
298+
console.log('donot need publish' + version)
299+
}
300+
})
301+
}
302+
})
303+
264304
function reportError () {
265305
console.log(chalk.bgRed('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'))
266306
console.log(chalk.bgRed('!! `npm publish` is forbidden for this package. !!'))

0 commit comments

Comments
 (0)