UNPKG

@smythos/cli

Version:

SmythOS SRE Command Line Interface

3 lines (2 loc) 5.3 kB
#!/usr/bin/env node "use strict";var d=Object.defineProperty;var o=(n,e)=>d(n,"name",{value:e,configurable:!0});var index=require("../chunks/index2.cjs"),getPackageManager=require("../chunks/getPackageManager.cjs"),require$$0=require("child_process"),index$1=require("../chunks/index5.cjs"),index$2=require("../chunks/index8.cjs");require("node:url");require("node:fs");require("node:fs/promises");require("node:util");require("node:path");require("fs");require("path");require("os");require("node:os");require("tty");require("util");require("inspector");require("node:perf_hooks");require("url");require("node:readline");require("node:process");require("node:tty");require("node:child_process");require("constants");require("stream");require("assert");require("events");require("http");require("../chunks/index6.cjs");require("node:assert");require("readline");require("../chunks/index4.cjs");require("buffer");require("string_decoder");require("crypto");require("node:stream");var y=Object.defineProperty,c=o((n,e)=>y(n,"name",{value:e,configurable:!0}),"c");class l extends index.libExports.Command{static{o(this,"l")}static{c(this,"Update")}static description="Check for and install updates";static examples=["<%= config.bin %> <%= command.id %>","<%= config.bin %> <%= command.id %> --check","<%= config.bin %> <%= command.id %> --force"];static flags={help:index.libExports.Flags.help({char:"h"}),check:index.libExports.Flags.boolean({description:"Only check for updates without installing",char:"c"}),force:index.libExports.Flags.boolean({description:"Force update check and installation",char:"f"}),package:index.libExports.Flags.string({description:"Specify package manager (npm, pnpm, yarn)",char:"p",options:["npm","pnpm","yarn"]})};async run(){const{flags:e}=await this.parse(l),t=e.package||getPackageManager.getPackageManager();this.log(index.chalk.blue("\u{1F504} SmythOS CLI Update Manager")),this.log("");const s=getPackageManager.updateNotifier({pkg:{name:"@smythos/cli",version:getPackageManager.version},updateCheckInterval:0}),a=index$1.ora("Checking for updates...").start();try{const r=await s.fetchInfo();if(a.stop(),r.latest!==r.current){const{latest:i,current:h,type:u}=r;if(this.log(index.chalk.green("\u2705 Update Available!")),this.log(""),this.log(index.chalk.gray(`Current version: ${index.chalk.yellow(h)}`)),this.log(index.chalk.gray(`Latest version: ${index.chalk.green(i)}`)),this.log(index.chalk.gray(`Update type: ${index.chalk.cyan(u)}`)),this.log(""),e.check)this.log(index.chalk.blue("\u{1F4CB} Check complete. Use without --check to install.")),this.showManualInstructions(t);else{const{confirm:g}=await index$2.inquirer.prompt([{type:"confirm",name:"confirm",message:"Do you want to install this update now?",default:!0}]);g?await this.performUpdate(t,i):(this.log(""),this.log(index.chalk.yellow("Update cancelled by user.")),this.showManualInstructions(t))}}else this.log(index.chalk.green("\u2705 You are using the latest version!")),this.log(index.chalk.gray(`Current version: ${index.chalk.yellow(getPackageManager.version)}`)),e.force&&(this.log(""),this.log(index.chalk.yellow("\u{1F4A1} Force flag was used, but no updates are available.")))}catch(r){a.stop(),this.log(index.chalk.red("\u274C Error checking for updates:")),this.log(index.chalk.gray(r.message)),this.log(""),this.showManualInstructions(t)}}async forceUpdateCheck(e){}async performUpdate(e,t){this.log(index.chalk.blue("\u{1F680} Installing update...")),this.log("");const s=index$1.ora(`Installing @smythos/cli@${t} with ${e}...`).start();try{const a=this.getUpdateCommand(e);await this.runCommand(a.cmd,a.args),s.succeed(index.chalk.green("\u2705 Update installed successfully!")),this.log(""),this.log(index.chalk.blue("\u{1F389} SmythOS CLI has been updated!")),this.log(index.chalk.gray("You can now use the latest features and improvements.")),this.log(""),this.log(index.chalk.yellow("\u{1F4A1} Run your command again to use the updated version."))}catch(a){s.fail(index.chalk.red("\u274C Update failed")),this.log(""),this.log(index.chalk.red("Error during installation:")),this.log(index.chalk.gray(a.message)),this.log(""),this.showManualInstructions(e)}}getUpdateCommand(e){switch(e){case"npm":return{cmd:"npm",args:["install","-g","@smythos/cli@latest"]};case"yarn":return{cmd:"yarn",args:["global","add","@smythos/cli@latest"]};case"pnpm":default:return{cmd:"pnpm",args:["install","-g","@smythos/cli@latest"]}}}runCommand(e,t){return new Promise((s,a)=>{const r=require$$0.spawn(e,t,{stdio:"inherit",shell:!0});r.on("close",i=>{i===0?s():a(new Error(`Command failed with exit code ${i}`))}),r.on("error",a)})}showManualInstructions(e){switch(this.log(index.chalk.blue("\u{1F4D6} Manual update instructions:")),this.log(""),e){case"npm":this.log(index.chalk.cyan(" npm install -g @smythos/cli@latest"));break;case"yarn":this.log(index.chalk.cyan(" yarn global add @smythos/cli@latest"));break;case"pnpm":default:this.log(index.chalk.cyan(" pnpm install -g @smythos/cli@latest"));break}this.log(""),this.log(index.chalk.gray("Or try with a different package manager:")),this.log(index.chalk.gray(" sre update --package npm")),this.log(index.chalk.gray(" sre update --package yarn")),this.log(index.chalk.gray(" sre update --package pnpm"))}}module.exports=l;