@@ -25,6 +25,7 @@ const fs = require('fs')
25
25
const rimraf = require ( 'rimraf' )
26
26
const replaceLib = require ( './replaceLib' )
27
27
const stripCode = require ( 'gulp-strip-code' )
28
+ const compareVersions = require ( 'compare-versions' )
28
29
29
30
const cwd = process . cwd ( )
30
31
const libDir = path . join ( cwd , 'lib' )
@@ -173,7 +174,6 @@ function githubRelease () {
173
174
const [ _ , owner , repo ] = execSync ( 'git remote get-url origin' ) // eslint-disable-line
174
175
. toString ( )
175
176
. match ( / g i t h u b .c o m [: / ] ( .+ ) \/ ( .+ ) \. g i t / )
176
-
177
177
github . repos . createRelease ( {
178
178
owner,
179
179
repo,
@@ -236,6 +236,9 @@ function pub (done) {
236
236
}
237
237
} )
238
238
}
239
+ // gulp.task('test', () => {
240
+ // githubRelease()
241
+ // })
239
242
240
243
gulp . task ( 'dist' , [ 'compile' ] , ( done ) => {
241
244
dist ( done )
@@ -261,6 +264,43 @@ gulp.task('pub', ['check-git', 'compile'], (done) => {
261
264
}
262
265
} )
263
266
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 ( / g i t h u b .c o m [: / ] ( .+ ) \/ ( .+ ) \. g i t / )
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 ( / b u m p ( .+ ) / ) || [ ]
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
+
264
304
function reportError ( ) {
265
305
console . log ( chalk . bgRed ( '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' ) )
266
306
console . log ( chalk . bgRed ( '!! `npm publish` is forbidden for this package. !!' ) )
0 commit comments