1- import { satelliteVersion , upgradeSatellite } from '@junobuild/admin' ;
1+ import { SatelliteParameters , satelliteVersion , upgradeSatellite } from '@junobuild/admin' ;
22import { red } from 'kleur' ;
33import prompts from 'prompts' ;
44import { compare } from 'semver' ;
55import { SATELLITE_WASM_NAME } from '../constants/constants' ;
6+ import { hasArgs , nextArg } from '../utils/args.utils' ;
67import { GitHubAsset , GitHubRelease , githubReleases } from '../utils/github.utils' ;
78import { junoConfigExist , readSatelliteConfig } from '../utils/satellite.config.utils' ;
89import { satelliteParameters } from '../utils/satellite.utils' ;
9- import { upgradeWasm } from '../utils/wasm.utils' ;
10+ import { upgradeWasmGitHub , upgradeWasmLocal } from '../utils/wasm.utils' ;
1011
1112const promptReleases = async (
1213 githubReleases : GitHubRelease [ ]
@@ -27,7 +28,7 @@ const promptReleases = async (
2728 return assets ?. find ( ( { name} ) => name === SATELLITE_WASM_NAME ) ;
2829} ;
2930
30- export const upgrade = async ( ) => {
31+ export const upgrade = async ( args ?: string [ ] ) => {
3132 if ( ! ( await junoConfigExist ( ) ) ) {
3233 console . log ( `${ red ( 'No configuration found.' ) } ` ) ;
3334 return ;
@@ -37,6 +38,15 @@ export const upgrade = async () => {
3738
3839 const satellite = satelliteParameters ( satelliteId ) ;
3940
41+ if ( hasArgs ( { args, options : [ '-s' , '--src' ] } ) ) {
42+ await upgradeCustom ( { satellite, args} ) ;
43+ return ;
44+ }
45+
46+ await upgradeRelease ( satellite ) ;
47+ } ;
48+
49+ const upgradeRelease = async ( satellite : SatelliteParameters ) => {
4050 const currentVersion = await satelliteVersion ( {
4151 satellite
4252 } ) ;
@@ -79,5 +89,28 @@ export const upgrade = async () => {
7989 wasm_module
8090 } ) ;
8191
82- await upgradeWasm ( { asset, upgrade : upgradeSatelliteWasm } ) ;
92+ await upgradeWasmGitHub ( { asset, upgrade : upgradeSatelliteWasm } ) ;
93+ } ;
94+
95+ const upgradeCustom = async ( {
96+ satellite,
97+ args
98+ } : {
99+ satellite : SatelliteParameters ;
100+ args ?: string [ ] ;
101+ } ) => {
102+ const src = nextArg ( { args, option : '-s' } ) ?? nextArg ( { args, option : '--src' } ) ;
103+
104+ if ( src === undefined ) {
105+ console . log ( `${ red ( 'No source file provided.' ) } ` ) ;
106+ return ;
107+ }
108+
109+ const upgradeSatelliteWasm = async ( { wasm_module} : { wasm_module : Array < number > } ) =>
110+ upgradeSatellite ( {
111+ satellite,
112+ wasm_module
113+ } ) ;
114+
115+ await upgradeWasmLocal ( { src, upgrade : upgradeSatelliteWasm } ) ;
83116} ;
0 commit comments