File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -444,13 +444,38 @@ async function ciAsync() {
444444
445445 lintJSONInDirectory ( path . resolve ( "." ) ) ;
446446 lintJSONInDirectory ( path . resolve ( "docs" ) ) ;
447+ let pkg = readJson ( "package.json" )
447448
448- function npmPublishAsync ( ) {
449+ async function npmPublishAsync ( ) {
449450 if ( ! npmPublish ) return Promise . resolve ( ) ;
451+
452+ let latest : pxt . semver . Version ;
453+
454+ try {
455+ const version = await nodeutil . npmLatestVersionAsync ( pkg [ "name" ] ) ;
456+ latest = pxt . semver . parse ( version ) ;
457+ }
458+ catch ( e ) {
459+ // no latest tag
460+ }
461+
462+ let distTag : string ;
463+
464+ if ( latest ) {
465+ const current = pxt . semver . parse ( pkg [ "version" ] ) ;
466+
467+ if ( pxt . semver . cmp ( current , latest ) < 0 ) {
468+ distTag = `stable${ current . major } .${ current . minor } ` ;
469+ }
470+ }
471+
472+ if ( distTag ) {
473+ return nodeutil . runNpmAsync ( "publish" , "--tag" , distTag ) ;
474+ }
475+
450476 return nodeutil . runNpmAsync ( "publish" ) ;
451477 }
452478
453- let pkg = readJson ( "package.json" )
454479 if ( pkg [ "name" ] == "pxt-core" ) {
455480 pxt . log ( "pxt-core build" ) ;
456481
Original file line number Diff line number Diff line change @@ -114,6 +114,16 @@ export function runNpmAsync(...args: string[]) {
114114 return runNpmAsyncWithCwd ( "." , ...args ) ;
115115}
116116
117+ export async function npmLatestVersionAsync ( packageName : string ) {
118+ const output = await spawnWithPipeAsync ( {
119+ cmd : addCmd ( "npm" ) ,
120+ args : [ "view" , packageName , "dist-tags.latest" ] ,
121+ cwd : "." ,
122+ } ) ;
123+
124+ return output . toString ( "utf8" ) . trim ( )
125+ }
126+
117127export interface NpmRegistry {
118128 _id : string ;
119129 _name : string ;
You can’t perform that action at this time.
0 commit comments