cross-tools
Version:
Cross-platform fundamental tools for developers
1 lines • 1.63 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),shellExecAsync_1=tslib_1.__importDefault(require("./shellExecAsync")),myPrompts_1=require("./myPrompts"),semver_1=tslib_1.__importDefault(require("semver")),colors_1=tslib_1.__importDefault(require("colors")),wait_1=tslib_1.__importDefault(require("./wait"));exports.default=async()=>{const e="cross-tools",t=await shellExecAsync_1.default("npm list -g --depth=0 --json",{silent:!0},{loadingMsg:"Checking for local installation"}),l=JSON.parse(t).dependencies[e];if(l){const t=await shellExecAsync_1.default(`npm show ${e} time --json`,{silent:!0},{loadingMsg:`Current Version: ${colors_1.default.yellow("v"+l.version)}. Checking for update...`}),o=Object.keys(JSON.parse(t)).reverse()[0];if(semver_1.default.gt(o,l.version)){const{confirmed:t}=await myPrompts_1.getConfirmation(`There is an update available (${colors_1.default.yellow(`v${l.version} -> v${o}`)}). Do you want to update it now?`);t&&(await shellExecAsync_1.default(`npm i -g ${e}@latest`,{silent:!0},{loadingMsg:"Updating "+e}),console.log(colors_1.default.green(`✅ ${e} updated to v${o}. ${colors_1.default.yellow("(Will be affected next time)")}\n`)))}else console.log(colors_1.default.green(`✅ ${e} already up to date (${o})`))}else{const{confirmed:t}=await myPrompts_1.getConfirmation("Do you want to create this package locally?\n"+colors_1.default.yellow("(By doing so, you don't have to download it on every execution.)"));t&&await shellExecAsync_1.default(`npm i -g ${e}@latest`,{silent:!0},{loadingMsg:`Installing ${e} locally`})}await wait_1.default(3)};