@@ -12,6 +12,8 @@ var cson = require('cson-parser');
1212var https = require ( 'https' ) ;
1313var url = require ( 'url' ) ;
1414
15+ let commitDate = '0000-00-00' ;
16+
1517/**
1618 * @param {string } urlString
1719 */
@@ -120,30 +122,35 @@ exports.update = function (repoId, repoPath, dest, modifyGrammar, version = 'mas
120122
121123 try {
122124 fs . writeFileSync ( dest , JSON . stringify ( result , null , '\t' ) . replace ( / \n / g, '\r\n' ) ) ;
123- // Add commit sha to cgmanifest
124125 let cgmanifestRead = JSON . parse ( fs . readFileSync ( './cgmanifest.json' ) . toString ( ) ) ;
125126 let promises = new Array ( ) ;
126- let packageJsonPath = 'https://raw.githubusercontent.com/' + repoId + `/${ info . commitSha } /package.json` ;
127- for ( let i = 0 ; i < cgmanifestRead . registrations . length ; i ++ ) {
128- if ( cgmanifestRead . registrations [ i ] . component . git . repositoryUrl . substr ( cgmanifestRead . registrations [ i ] . component . git . repositoryUrl . length - repoId . length , repoId . length ) === repoId ) {
129- cgmanifestRead . registrations [ i ] . component . git . commitHash = info . commitSha ;
130- promises . push ( download ( packageJsonPath ) . then ( function ( packageJson ) {
131- if ( packageJson ) {
132- try {
133- cgmanifestRead . registrations [ i ] . version = JSON . parse ( packageJson ) . version ;
134- } catch ( e ) {
135- console . log ( 'File does not exist at' + packageJsonPath ) ;
136- }
137- }
138- } ) ) ;
139- break ;
127+ const currentCommitDate = info . commitDate . substr ( 0 , 10 ) ;
128+
129+ // Add commit sha to cgmanifest.
130+ if ( currentCommitDate > commitDate ) {
131+ let packageJsonPath = 'https://raw.githubusercontent.com/' + repoId + `/${ info . commitSha } /package.json` ;
132+ for ( let i = 0 ; i < cgmanifestRead . registrations . length ; i ++ ) {
133+ if ( cgmanifestRead . registrations [ i ] . component . git . repositoryUrl . substr ( cgmanifestRead . registrations [ i ] . component . git . repositoryUrl . length - repoId . length , repoId . length ) === repoId ) {
134+ cgmanifestRead . registrations [ i ] . component . git . commitHash = info . commitSha ;
135+ commitDate = currentCommitDate ;
136+ promises . push ( download ( packageJsonPath ) . then ( function ( packageJson ) {
137+ if ( packageJson ) {
138+ try {
139+ cgmanifestRead . registrations [ i ] . version = JSON . parse ( packageJson ) . version ;
140+ } catch ( e ) {
141+ console . log ( 'Cannot get version. File does not exist at ' + packageJsonPath ) ;
142+ }
143+ }
144+ } ) ) ;
145+ break ;
146+ }
140147 }
141148 }
142149 Promise . all ( promises ) . then ( function ( allResult ) {
143150 fs . writeFileSync ( './cgmanifest.json' , JSON . stringify ( cgmanifestRead , null , '\t' ) . replace ( / \n / g, '\r\n' ) ) ;
144151 } ) ;
145152 if ( info ) {
146- console . log ( 'Updated ' + path . basename ( dest ) + ' to ' + repoId + '@' + info . commitSha . substr ( 0 , 7 ) + ' (' + info . commitDate . substr ( 0 , 10 ) + ')' ) ;
153+ console . log ( 'Updated ' + path . basename ( dest ) + ' to ' + repoId + '@' + info . commitSha . substr ( 0 , 7 ) + ' (' + currentCommitDate + ')' ) ;
147154 } else {
148155 console . log ( 'Updated ' + path . basename ( dest ) ) ;
149156 }
0 commit comments