2017-08-15 17:29:18 +00:00
"use strict" ;
2017-08-16 16:54:23 +00:00
var _ _awaiter = ( this && this . _ _awaiter ) || function ( thisArg , _arguments , P , generator ) {
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
function step ( result ) { result . done ? resolve ( result . value ) : new P ( function ( resolve ) { resolve ( result . value ) ; } ) . then ( fulfilled , rejected ) ; }
step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
} ) ;
} ;
2017-08-15 17:29:18 +00:00
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
const plugins = require ( "./smartupdate.plugins" ) ;
2017-08-16 16:54:23 +00:00
const smarttime _1 = require ( "smarttime" ) ;
2017-08-15 17:29:18 +00:00
class SmartUpdate {
constructor ( ) {
this . kvStore = new plugins . npmextra . KeyValueStore ( 'custom' , 'global:smartupdate' ) ;
}
2017-08-17 09:56:38 +00:00
check ( npmnameArg , compareVersion , changelogUrlArg ) {
2017-08-16 16:54:23 +00:00
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
let result = yield this . kvStore . readKey ( npmnameArg ) ;
let timeStamp = new smarttime _1 . TimeStamp ( ) ;
// the newData to write
let newData = {
lastCheck : timeStamp . milliSeconds ,
latestVersion : 'x.x.x' ,
performedUpgrade : false
} ;
if ( result ) {
let lastCheckTimeStamp = smarttime _1 . TimeStamp . fromMilliSeconds ( result . lastCheck ) ;
let compareTime = plugins . smarttime . getMilliSecondsFromUnits ( { days : 1 } ) ;
if ( ! lastCheckTimeStamp . isOlderThan ( timeStamp , compareTime ) ) {
2017-08-16 21:28:12 +00:00
plugins . beautylog . log ( ` smartupdate: next check tomorrow: ${ plugins . beautycolor . coloredString ( ` ${ npmnameArg } has already been checked for today. ` , 'pink' ) } ` ) ;
2017-08-16 16:54:23 +00:00
return ;
}
}
let npmPackage = yield this . getNpmPackageFromRegistry ( npmnameArg ) ;
newData . latestVersion = npmPackage . version ;
2017-08-17 09:56:38 +00:00
let upgradeBool = yield this . checkIfUpgrade ( npmPackage , compareVersion , changelogUrlArg ) ;
2017-08-16 16:54:23 +00:00
if ( upgradeBool ) {
}
this . kvStore . writeKey ( npmnameArg , newData ) ;
} ) ;
}
getNpmPackageFromRegistry ( npmnameArg ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
2017-08-16 21:28:12 +00:00
plugins . beautylog . log ( ` smartupdate: checking for newer version of ${ plugins . beautycolor . coloredString ( npmnameArg , 'pink' ) } ... ` ) ;
2017-08-16 16:54:23 +00:00
let npmRegistry = new plugins . smartnpm . NpmRegistry ( ) ;
let npmPackage = ( yield npmRegistry . search ( { name : npmnameArg , boostExact : true } ) ) [ 0 ] ;
return npmPackage ;
} ) ;
}
2017-08-17 09:56:38 +00:00
checkIfUpgrade ( npmPackage , versionArg , changelogUrlArg ) {
2017-08-16 16:54:23 +00:00
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
if ( npmPackage . version === versionArg ) {
2017-08-16 21:28:12 +00:00
plugins . beautylog . ok ( ` smartupdate: You are running the latest version of ${ plugins . beautycolor . coloredString ( npmPackage . name , 'pink' ) } ` ) ;
2017-08-16 16:54:23 +00:00
return false ;
}
else {
plugins . beautylog . warn ( ` There is a newer version of ${ npmPackage . name } available on npm. ` ) ;
2017-08-17 09:56:38 +00:00
plugins . beautylog . warn ( ` Your version: ${ versionArg } | version on npm: ${ npmPackage . version } ` ) ;
if ( ! process . env . CI && changelogUrlArg ) {
plugins . beautylog . log ( 'trying to open changelog...' ) ;
plugins . smartopen . openUrl ( changelogUrlArg ) ;
}
2017-08-16 16:54:23 +00:00
return true ;
}
} ) ;
2017-08-15 17:29:18 +00:00
}
}
2017-08-16 16:54:23 +00:00
exports . SmartUpdate = SmartUpdate ;
exports . standardHandler = new SmartUpdate ( ) ;
2017-08-17 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