@@ -7,6 +7,7 @@ import { parseArgs } from "jsr:@std/cli";
77import { startServer as HonoServer } from './standalone/standalone.ts' ;
88import { startServer as FastifyServer } from './full/server.ts' ;
99import { fromFileUrl } from 'jsr:@std/path' ;
10+ import ora , { Ora } from 'npm:ora' ;
1011
1112import packageJSON from "../package.json" with { type : 'json' } ;
1213const { version } = packageJSON ;
@@ -22,7 +23,9 @@ interface StartArgs extends CLIArgs {
2223 seo ?: boolean ;
2324} ;
2425
25- interface UpgradeArgs extends CLIArgs { } ;
26+ interface UpgradeArgs extends CLIArgs {
27+ check : boolean ;
28+ } ;
2629
2730interface DescriptionType {
2831 name : string ;
@@ -73,8 +76,59 @@ if (args._.length !== 0 && args._[0] !== "upgrade") {
7376}
7477
7578if ( args . _ [ 0 ] === "upgrade" ) {
76- const upgradeCLI = new CLI < UpgradeArgs > ( { booleans : [ ] , strings : [ ] } ) ;
77- await upgradeCLI . start ( ( ) => { } ) ;
79+ const upgradeCLI = new CLI < UpgradeArgs > ( { booleans : [ "check" ] , strings : [ ] } ) ;
80+ const uArgs = upgradeCLI . getArgs ( ) ;
81+
82+ const checkForVersion = async ( checkFlag : boolean ) => {
83+ const res = await fetch ( "https://raw.githubusercontent.com/titaniumnetwork-dev/Incognito/refs/heads/main/package.json" ) ;
84+ const resp = await res . json ( ) ;
85+ if ( resp . version !== version ) {
86+ checkFlag ? console . log ( chalk . greenBright . bold ( `A new version is available! Re-run this command without --check to upgrade!` ) ) : '' ;
87+ return resp . version ;
88+ }
89+ else {
90+ console . log ( chalk . redBright . bold ( 'A new version is not available at this moment, check back later' ) ) ;
91+ Deno . exit ( ) ;
92+ }
93+ }
94+
95+ if ( uArgs . help ) {
96+ upgradeCLI . help ( [
97+ { name : 'check' , description : 'Check for a new version' }
98+ ] ) ;
99+ }
100+
101+ if ( uArgs . check ) {
102+ await checkForVersion ( true ) ;
103+ Deno . exit ( ) ;
104+ }
105+
106+ const download = async ( version : string , spinner : Ora ) => {
107+ const os = Deno . build . os ;
108+ const arch = Deno . build . arch ;
109+ if ( os === "aix" || os === "netbsd" || os === "android" || os === "freebsd" || os === "solaris" || os === "illumos" ) {
110+ spinner . fail ( 'Your OS is NOT supported! Exiting...' ) ;
111+ Deno . exit ( ) ;
112+ }
113+ if ( os === "darwin" ) {
114+ const res = await fetch ( `https://github.com/titaniumnetwork-dev/incognito/releases/download/v${ version } /incognito-MacOS${ arch === "aarch64" ? '-arm' : '' } ` ) ;
115+ const resp = await res . bytes ( ) ;
116+ await Deno . writeFile ( `incognito-MacOS${ arch === "aarch64" ? '-arm' : '' } ` , resp , { mode : 0o775 } ) ;
117+ }
118+ else {
119+ const res = await fetch ( `https://github.com/titaniumnetwork-dev/incognito/releases/download/v${ version } /incognito-${ os } ${ arch === "aarch64" ? '-arm' : '' } ` ) ;
120+ const resp = await res . bytes ( ) ;
121+ await Deno . writeFile ( `incognito-${ os } ${ arch === "aarch64" ? '-arm' : '' } ` , resp , { mode : 0o775 } ) ;
122+ }
123+ } ;
124+
125+ await upgradeCLI . start ( async ( ) => {
126+ const version = await checkForVersion ( false ) ;
127+ const spinner = ora ( 'Downloading...' ) . start ( ) ;
128+ await download ( version , spinner ) ;
129+ spinner . succeed ( 'Upgraded!' ) ;
130+ } ) ;
131+
78132 Deno . exit ( ) ;
79133}
80134
0 commit comments