diff --git a/scripts/lib/versions.js b/scripts/lib/versions.js index 6ed6e1e7e5c..6f5041a55b9 100755 --- a/scripts/lib/versions.js +++ b/scripts/lib/versions.js @@ -2,6 +2,8 @@ const https = require("https"); const xml2js = require('xml2js'); const fs = require('fs'); const exec = require('util').promisify(require('child_process').exec); +const cachedBowerVersions = {}; +const cachedNpmVersions = {}; async function run(cmd) { const { stdout, stderr } = await exec(cmd); @@ -106,24 +108,30 @@ async function getAnnotations(){ } async function getLatestNpmVersion(package, version, major, minor) { - cmd = `npm view ${package} versions --json`; - const json = await JSON.parse(await run(cmd)) - const versions = json.filter(version => version.startsWith(`${major}.${minor}`)); - const next = versions.pop(); - console.log(`Checking next version for ${package} ${version} ${next}`); - return next; + if (!cachedNpmVersions[package]) { + cmd = `npm view ${package} versions --json`; + const json = await JSON.parse(await run(cmd)) + const versions = json.filter(version => version.startsWith(`${major}.${minor}`)); + const next = versions.pop(); + console.log(`Checking next Npm version for ${package} ${version} ${next}`); + cachedNpmVersions[package] = next; + } + return cachedNpmVersions[package]; } async function getLatestBowerVersion(package, version, major, minor) { - cmd = `bower info ${package} --json`; - const json = await JSON.parse(await run(cmd)); - const versions = json.versions.filter(version => version.startsWith(`${major}.${minor}`)); - const next = versions[0] - console.log(`Checking next version for ${package} ${version} ${next}`); - return next; + if (!cachedBowerVersions[package]) { + cmd = `bower info ${package} --json`; + const json = await JSON.parse(await run(cmd)); + const versions = json.versions.filter(version => version.startsWith(`${major}.${minor}`)); + const next = versions[0] + console.log(`Checking next Bower version for ${package} ${version} ${next}`); + cachedBowerVersions[package] = next; + } + return cachedBowerVersions[package]; } -async function computeVertionToUpdate(data) { +async function computeVersionToUpdate(data) { return (data['updatedVersion'] = await getLatestNpmVersion(data.package, data.version, data.major, data.minor)); } @@ -131,7 +139,7 @@ module.exports = { getVersions, getVersionsCsv, getVersionsJson, - computeVertionToUpdate, + computeVersionToUpdate, getLatestNpmVersion, getAnnotations, checkoutPlatorm, diff --git a/scripts/updateNpmVer.js b/scripts/updateNpmVer.js index 1f6672f11fc..90d7967c8f1 100755 --- a/scripts/updateNpmVer.js +++ b/scripts/updateNpmVer.js @@ -12,7 +12,7 @@ const fs = require('fs'); const util = require('util'); const exec = util.promisify(require('child_process').exec); const replace = require('replace-in-file'); -const {getAnnotations, computeVertionToUpdate} = require('./lib/versions.js'); +const {getAnnotations, computeVersionToUpdate} = require('./lib/versions.js'); let exclude=[]; @@ -48,7 +48,7 @@ async function run(cmd) { /** * Allow exclude certain component package update, use ',' as separator */ -async function excludeComponents() { +function excludeComponents() { for (i = 2;process.argv[i]; i++) { switch(process.argv[i]) { case '--exclude': @@ -67,15 +67,16 @@ async function excludeComponents() { async function main() { console.log("Updating the NpmPackage annotation.") const annotations = await getAnnotations(); + if (process.argv.length > 2) { - exclude = await excludeComponents(); + exclude = excludeComponents(); } for (i = 0; i < annotations.length; i++) { if (exclude.includes(annotations[i].package)) { console.log('\x1b[33m', "skip updating " + annotations[i].package + " package"); } else { - await computeVertionToUpdate(annotations[i]); + await computeVersionToUpdate(annotations[i]); await updateFiles(annotations[i]); } }