@@ -13,14 +13,15 @@ if (process.env['NPM_AUTH_TOKEN']) {
1313 fs . writeFileSync ( `${ process . env [ 'HOME' ] } /.npmrc` , `//registry.npmjs.org/:_authToken=${ process . env [ 'NPM_AUTH_TOKEN' ] } ` ) ;
1414}
1515
16+ log ( 'Configuration:' , 'green' )
1617const isDryRun = process . argv . includes ( '--dry' ) ;
1718if ( isDryRun ) {
18- console . log ( 'Publish dry run' ) ;
19+ log ( ' Publish dry run' ) ;
1920}
2021
2122const allAddons = process . argv . includes ( '--all-addons' ) ;
2223if ( allAddons ) {
23- console . log ( 'Publish all addons' ) ;
24+ log ( ' Publish all addons' ) ;
2425}
2526
2627const repoCommit = getRepoCommit ( ) ;
@@ -52,11 +53,10 @@ const addonPackageDirs = [
5253 path . resolve ( __dirname , '../addons/addon-web-links' ) ,
5354 path . resolve ( __dirname , '../addons/addon-webgl' )
5455] ;
55- console . log ( `Checking if addons need to be published` ) ;
56+ log ( `Checking if addons need to be published` , 'green' ) ;
5657for ( const p of addonPackageDirs ) {
5758 const addon = path . basename ( p ) ;
5859 if ( allAddons || changedFiles . some ( e => e . includes ( addon ) ) ) {
59- console . log ( `Try publish ${ addon } ` ) ;
6060 checkAndPublishPackage ( p , repoCommit , peerDependencies ) ;
6161 }
6262}
@@ -75,7 +75,7 @@ function checkAndPublishPackage(packageDir, repoCommit, peerDependencies) {
7575
7676 // Get the next version
7777 let nextVersion = isStableRelease ? packageJson . version : getNextBetaVersion ( packageJson ) ;
78- console . log ( `Publishing version: ${ nextVersion } ` ) ;
78+ log ( `Publishing version: ${ nextVersion } ` , 'green' ) ;
7979
8080 // Set the version in package.json
8181 const packageJsonFile = path . join ( packageDir , 'package.json' ) ;
@@ -84,17 +84,17 @@ function checkAndPublishPackage(packageDir, repoCommit, peerDependencies) {
8484 // Set the commit in package.json
8585 if ( repoCommit ) {
8686 packageJson . commit = repoCommit ;
87- console . log ( `Set commit of ${ packageJsonFile } to ${ repoCommit } ` ) ;
87+ log ( `Set commit of ${ packageJsonFile } to ${ repoCommit } ` ) ;
8888 } else {
8989 throw new Error ( `No commit set` ) ;
9090 }
9191
9292 // Set peer dependencies
9393 if ( peerDependencies ) {
9494 packageJson . peerDependencies = peerDependencies ;
95- console . log ( `Set peerDependencies of ${ packageJsonFile } to ${ JSON . stringify ( peerDependencies ) } ` ) ;
95+ log ( `Set peerDependencies of ${ packageJsonFile } to ${ JSON . stringify ( peerDependencies ) } ` ) ;
9696 } else {
97- console . log ( `Skipping peerDependencies` ) ;
97+ log ( `Skipping peerDependencies` ) ;
9898 }
9999
100100 // Write new package.json
@@ -108,18 +108,16 @@ function checkAndPublishPackage(packageDir, repoCommit, peerDependencies) {
108108 if ( isDryRun ) {
109109 args . push ( '--dry-run' ) ;
110110 }
111- console . log ( `Spawn: npm ${ args . join ( ' ' ) } ` ) ;
111+ log ( `Spawn: npm ${ args . join ( ' ' ) } ` ) ;
112112 const result = cp . spawnSync ( 'npm' , args , {
113113 cwd : packageDir ,
114114 stdio : 'inherit'
115115 } ) ;
116116 if ( result . status ) {
117- console . error ( `Spawn exited with code ${ result . status } ` ) ;
117+ error ( `Spawn exited with code ${ result . status } ` ) ;
118118 process . exit ( result . status ) ;
119119 }
120120
121- console . groupEnd ( ) ;
122-
123121 return { isStableRelease, nextVersion } ;
124122}
125123
@@ -196,10 +194,29 @@ function getChangedFilesInCommit(commit) {
196194}
197195
198196function updateWebsite ( ) {
199- console . log ( 'Updating website' ) ;
197+ log ( 'Updating website' , 'green ') ;
200198 const cwd = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'website-' ) ) ;
201199 const packageJson = require ( path . join ( path . resolve ( __dirname , '..' ) , 'package.json' ) ) ;
202200 if ( ! isDryRun ) {
203201 cp . spawnSync ( 'sh' , [ path . join ( __dirname , 'update-website.sh' ) , packageJson . version ] , { cwd, stdio : [ process . stdin , process . stdout , process . stderr ] } ) ;
204202 }
205203}
204+
205+ /**
206+ * @param {string } message
207+ */
208+ function log ( message , color ) {
209+ let colorSequence = '' ;
210+ switch ( color ) {
211+ case 'green' : {
212+ colorSequence = '\x1b[32m' ;
213+ break ;
214+ }
215+ }
216+ console . info ( [
217+ `[\x1b[2m${ new Date ( ) . toLocaleTimeString ( 'en-GB' ) } \x1b[0m] ` ,
218+ colorSequence ,
219+ message ,
220+ '\x1b[0m' ,
221+ ] . join ( '' ) ) ;
222+ }
0 commit comments