diff --git a/src/commands/clear.ts b/src/commands/clear.ts index 9f614ff2..cc61c4fa 100644 --- a/src/commands/clear.ts +++ b/src/commands/clear.ts @@ -22,9 +22,9 @@ export const clear = async (args?: string[]) => { return; } - await clearAsset({fullPath: file, args}); + await clearAsset({fullPath: file}); return; } - await clearServices(args); + await clearServices(); }; diff --git a/src/commands/config.ts b/src/commands/config.ts index 08dbba1e..00a6ad49 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -13,8 +13,8 @@ import ora from 'ora'; import {initAgent} from '../api/agent.api'; import {assertConfigAndLoadSatelliteContext} from '../utils/satellite.utils'; -export const config = async (args?: string[]) => { - const {satellite, satelliteConfig} = await assertConfigAndLoadSatelliteContext(args); +export const config = async () => { + const {satellite, satelliteConfig} = await assertConfigAndLoadSatelliteContext(); const {storage, authentication, datastore, settings} = satelliteConfig; const spinner = ora(`Configuring...`).start(); diff --git a/src/commands/deploy.ts b/src/commands/deploy.ts index d386d6fd..a867071d 100644 --- a/src/commands/deploy.ts +++ b/src/commands/deploy.ts @@ -30,7 +30,7 @@ export const deploy = async (args?: string[]) => { const immediate = hasArgs({args, options: ['-i', '--immediate']}); if (immediate) { - await deployImmediate({args, clearOption}); + await deployImmediate({clearOption}); return; } @@ -89,7 +89,6 @@ const deployWithProposal = async ({args, clearOption}: {args?: string[]; clearOp }; const result = await executeDeployWithProposal({ - args, deployFn, uploadFileFn }); @@ -105,12 +104,12 @@ const deployWithProposal = async ({args, clearOption}: {args?: string[]; clearOp proposalId }); - await links(args); + await links(); }; -const deployImmediate = async ({args, clearOption}: {args?: string[]; clearOption: boolean}) => { +const deployImmediate = async ({clearOption}: {clearOption: boolean}) => { if (clearOption) { - await clear(args); + await clear(); } const deployFn = async ({deploy}: DeployFnParams): Promise => @@ -138,10 +137,9 @@ const deployImmediate = async ({args, clearOption}: {args?: string[]; clearOptio }; await executeDeployImmediate({ - args, deployFn, uploadFileFn }); - await links(args); + await links(); }; diff --git a/src/commands/open.ts b/src/commands/open.ts index 28270848..c7ca0c4a 100644 --- a/src/commands/open.ts +++ b/src/commands/open.ts @@ -6,7 +6,7 @@ import {openUrl} from '../utils/open.utils'; import {assertConfigAndLoadSatelliteContext} from '../utils/satellite.utils'; export const open = async (args?: string[]) => { - const {satellite} = await assertConfigAndLoadSatelliteContext(args); + const {satellite} = await assertConfigAndLoadSatelliteContext(); const {satelliteId} = satellite; const browser = nextArg({args, option: '-b'}) ?? nextArg({args, option: '--browser'}); diff --git a/src/commands/snapshot.ts b/src/commands/snapshot.ts index 34930ed6..5015469c 100644 --- a/src/commands/snapshot.ts +++ b/src/commands/snapshot.ts @@ -59,7 +59,7 @@ const executeSnapshotFn = async ({ orbiterFn }: { args?: string[]; - satelliteFn: (params: {args?: string[]}) => Promise; + satelliteFn: () => Promise; missionControlFn: () => Promise; orbiterFn: () => Promise; }) => { @@ -68,7 +68,7 @@ const executeSnapshotFn = async ({ switch (target) { case 's': case 'satellite': - await satelliteFn({args}); + await satelliteFn(); break; case 'm': case 'mission-control': diff --git a/src/commands/start-stop.ts b/src/commands/start-stop.ts index 20128e33..bbfcc05e 100644 --- a/src/commands/start-stop.ts +++ b/src/commands/start-stop.ts @@ -15,7 +15,7 @@ export const startStop = async ({args, action}: {args?: string[]; action: StartS switch (target) { case 's': case 'satellite': - await startStopSatellite({args, action}); + await startStopSatellite({action}); break; case 'm': case 'mission-control': diff --git a/src/commands/version.ts b/src/commands/version.ts index 1703770d..178ea03c 100644 --- a/src/commands/version.ts +++ b/src/commands/version.ts @@ -37,7 +37,7 @@ export const version = async (args?: string[]) => { } await missionControlVersion(); - await satelliteVersion(args); + await satelliteVersion(); await orbitersVersion(); }; @@ -112,8 +112,8 @@ const missionControlVersion = async () => { }); }; -const satelliteVersion = async (args?: string[]) => { - const {satellite} = await assertConfigAndLoadSatelliteContext(args); +const satelliteVersion = async () => { + const {satellite} = await assertConfigAndLoadSatelliteContext(); const {satelliteId, ...actorParams} = satellite; const getVersion = async (): Promise => { diff --git a/src/commands/whoami.ts b/src/commands/whoami.ts index f5e1230b..b0923ce6 100644 --- a/src/commands/whoami.ts +++ b/src/commands/whoami.ts @@ -4,14 +4,14 @@ import {green} from 'kleur'; import {getToken, getUse, isDefaultProfile} from '../configs/cli.config'; import {links} from '../services/links.services'; -export const whoami = async (args?: string[]) => { +export const whoami = async () => { const {success} = await info(); if (!success) { return; } - await links(args); + await links(); }; const info = async (): Promise<{success: boolean}> => { diff --git a/src/env.ts b/src/env.ts new file mode 100644 index 00000000..fb82ee3d --- /dev/null +++ b/src/env.ts @@ -0,0 +1,14 @@ +import {nextArg} from '@junobuild/cli-tools'; +import type {JunoConfigEnv} from '@junobuild/config'; + +const loadEnv = (): JunoConfigEnv => { + const [_, ...args] = process.argv.slice(2); + + const mode = nextArg({args, option: '-m'}) ?? nextArg({args, option: '--mode'}); + + return { + mode: mode ?? 'production' + }; +}; + +export const ENV = loadEnv(); diff --git a/src/index.ts b/src/index.ts index 4bb9a565..3ac41ae3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -133,10 +133,10 @@ export const run = async () => { await deploy(args); break; case 'config': - await config(args); + await config(); break; case 'clear': - await clear(args); + await clear(); break; case 'version': await versionCommand(args); @@ -148,7 +148,7 @@ export const run = async () => { await upgrade(args); break; case 'whoami': - await whoami(args); + await whoami(); break; case 'use': await use(args); diff --git a/src/services/assets/clear.services.ts b/src/services/assets/clear.services.ts index 8dca5673..1a2b44e3 100644 --- a/src/services/assets/clear.services.ts +++ b/src/services/assets/clear.services.ts @@ -5,8 +5,8 @@ import {green} from 'kleur'; import ora from 'ora'; import {assertConfigAndLoadSatelliteContext} from '../../utils/satellite.utils'; -export const clear = async (args?: string[]) => { - const {satellite} = await assertConfigAndLoadSatelliteContext(args); +export const clear = async () => { + const {satellite} = await assertConfigAndLoadSatelliteContext(); const spinner = ora('Clearing app assets...').start(); @@ -35,8 +35,8 @@ const cleanFullPath = (fullPath: string): string => { return `${path.startsWith('/') ? '' : '/'}${path}`; }; -export const clearAsset = async ({fullPath, args}: {fullPath: string; args?: string[]}) => { - const {satellite} = await assertConfigAndLoadSatelliteContext(args); +export const clearAsset = async ({fullPath}: {fullPath: string}) => { + const {satellite} = await assertConfigAndLoadSatelliteContext(); const spinner = ora(`Clearing ${fullPath}...`).start(); diff --git a/src/services/assets/deploy/deploy.assert.services.ts b/src/services/assets/deploy/deploy.assert.services.ts index db874b97..28ad08e5 100644 --- a/src/services/assets/deploy/deploy.assert.services.ts +++ b/src/services/assets/deploy/deploy.assert.services.ts @@ -8,8 +8,8 @@ import { import {NEW_CMD_LINE, confirmAndExit} from '../../../utils/prompt.utils'; import {assertConfigAndLoadSatelliteContext} from '../../../utils/satellite.utils'; -export const assertSatelliteMemorySize = async (args?: string[]) => { - const {satellite, satelliteConfig} = await assertConfigAndLoadSatelliteContext(args); +export const assertSatelliteMemorySize = async () => { + const {satellite, satelliteConfig} = await assertConfigAndLoadSatelliteContext(); const {assertions} = satelliteConfig; diff --git a/src/services/assets/deploy/deploy.execute.services.ts b/src/services/assets/deploy/deploy.execute.services.ts index 4d46e695..73abedfc 100644 --- a/src/services/assets/deploy/deploy.execute.services.ts +++ b/src/services/assets/deploy/deploy.execute.services.ts @@ -25,7 +25,6 @@ export type UploadFileFnParams = UploadFileStorage & {satellite: SatelliteParame export type UploadFileFnParamsWithProposal = UploadFileFnParams & {proposalId: bigint}; export const executeDeployWithProposal = async ({ - args, deployFn, uploadFileFn }: { @@ -34,14 +33,12 @@ export const executeDeployWithProposal = async ({ uploadFileFn: (params: UploadFileFnParamsWithProposal) => Promise; }): Promise => { return await executeDeploy({ - args, deployFn, uploadFileFn }); }; export const executeDeployImmediate = async ({ - args, deployFn, uploadFileFn }: { @@ -50,7 +47,6 @@ export const executeDeployImmediate = async ({ uploadFileFn: (params: UploadFileFnParams) => Promise; }): Promise => { return await executeDeploy({ - args, deployFn, uploadFileFn }); @@ -60,19 +56,17 @@ const executeDeploy = async < P extends UploadFileStorage, R extends DeployResult | DeployResultWithProposal >({ - args, deployFn, uploadFileFn }: { - args?: string[]; deployFn: (params: DeployFnParams<(params: P) => Promise>) => Promise; uploadFileFn: (params: P & {satellite: SatelliteParametersWithId}) => Promise; }): Promise => { const assertMemory = async () => { - await assertSatelliteMemorySize(args); + await assertSatelliteMemorySize(); }; - const {satellite, satelliteConfig} = await assertConfigAndLoadSatelliteContext(args); + const {satellite, satelliteConfig} = await assertConfigAndLoadSatelliteContext(); const listExistingAssets = async ({startAfter}: {startAfter?: string}): Promise => await listAssets({ diff --git a/src/services/changes/changes.apply.services.ts b/src/services/changes/changes.apply.services.ts index 74c3bd43..73671452 100644 --- a/src/services/changes/changes.apply.services.ts +++ b/src/services/changes/changes.apply.services.ts @@ -7,7 +7,7 @@ import {assertConfigAndLoadSatelliteContext} from '../../utils/satellite.utils'; import {clearProposalStagedAssets} from './changes.clear.services'; export const applyChanges = async (args?: string[]) => { - const {satellite} = await assertConfigAndLoadSatelliteContext(args); + const {satellite} = await assertConfigAndLoadSatelliteContext(); const {proposalId, hash} = readChangesIdAndHash(args); diff --git a/src/services/changes/changes.clear.services.ts b/src/services/changes/changes.clear.services.ts index 32162e99..3f429e83 100644 --- a/src/services/changes/changes.clear.services.ts +++ b/src/services/changes/changes.clear.services.ts @@ -22,7 +22,7 @@ export const clearProposalStagedAssets = async ({ const spinner = ora('Deleting staged assets...').start(); try { - const {satellite} = await assertConfigAndLoadSatelliteContext(args); + const {satellite} = await assertConfigAndLoadSatelliteContext(); await deleteProposalAssets({ cdn: {satellite}, diff --git a/src/services/changes/changes.list.services.ts b/src/services/changes/changes.list.services.ts index 18f5acf5..83be8273 100644 --- a/src/services/changes/changes.list.services.ts +++ b/src/services/changes/changes.list.services.ts @@ -6,7 +6,7 @@ import {formatDate} from '../../utils/format.utils'; import {assertConfigAndLoadSatelliteContext} from '../../utils/satellite.utils'; export const listChanges = async (args?: string[]) => { - const {satellite} = await assertConfigAndLoadSatelliteContext(args); + const {satellite} = await assertConfigAndLoadSatelliteContext(); const all = hasArgs({args, options: ['-a', '--all']}); const every = hasArgs({args, options: ['-e', '--every']}); diff --git a/src/services/changes/changes.reject.services.ts b/src/services/changes/changes.reject.services.ts index 8582ed71..07f18f9e 100644 --- a/src/services/changes/changes.reject.services.ts +++ b/src/services/changes/changes.reject.services.ts @@ -7,7 +7,7 @@ import {assertConfigAndLoadSatelliteContext} from '../../utils/satellite.utils'; import {clearProposalStagedAssets} from './changes.clear.services'; export const rejectChanges = async (args?: string[]) => { - const {satellite} = await assertConfigAndLoadSatelliteContext(args); + const {satellite} = await assertConfigAndLoadSatelliteContext(); const {proposalId, hash} = readChangesIdAndHash(args); diff --git a/src/services/functions/publish.services.ts b/src/services/functions/publish.services.ts index 44495b2e..3511d548 100644 --- a/src/services/functions/publish.services.ts +++ b/src/services/functions/publish.services.ts @@ -20,7 +20,7 @@ import {type UploadFileFnParamsWithProposal} from '../assets/deploy/deploy.execu import {clearProposalStagedAssets} from '../changes/changes.clear.services'; export const publish = async (args?: string[]) => { - const {satellite} = await assertConfigAndLoadSatelliteContext(args); + const {satellite} = await assertConfigAndLoadSatelliteContext(); const srcArgs = nextArg({args, option: '-s'}) ?? nextArg({args, option: '--src'}); const src = srcArgs ?? `${SATELLITE_OUTPUT}.gz`; @@ -127,7 +127,7 @@ const publishWasmWithProposal = async ({ }; const assertMemory = async () => { - await assertSatelliteMemorySize(args); + await assertSatelliteMemorySize(); }; const sourceAbsolutePath = dirname(filePath); diff --git a/src/services/functions/upgrade/upgrade.services.ts b/src/services/functions/upgrade/upgrade.services.ts index 35fd0c0f..81226555 100644 --- a/src/services/functions/upgrade/upgrade.services.ts +++ b/src/services/functions/upgrade/upgrade.services.ts @@ -6,7 +6,7 @@ import {upgradeSatelliteWithSrc} from '../../modules/upgrade/upgrade.satellite.s import {upgradeWithCdn} from './upgrade.cdn.services'; export const upgradeFunctions = async (args?: string[]) => { - const {satellite} = await assertConfigAndLoadSatelliteContext(args); + const {satellite} = await assertConfigAndLoadSatelliteContext(); const cdnOption = hasArgs({args, options: ['--cdn', '--cdn-path']}); diff --git a/src/services/links.services.ts b/src/services/links.services.ts index 62dbfcc8..7e673f8d 100644 --- a/src/services/links.services.ts +++ b/src/services/links.services.ts @@ -5,14 +5,14 @@ import {terminalLink} from '../utils/links.utils'; import {isHeadless} from '../utils/process.utils'; import {assertConfigAndLoadSatelliteContext} from '../utils/satellite.utils'; -export const links = async (args?: string[]) => { +export const links = async () => { // If a developer is using a JUNO_TOKEN to execute command(s), the links will not be printed. // This is particularly useful for CI environment where such output is not needed and also because only ADMIN controllers can list custom domains. if (isHeadless()) { return; } - const {satellite} = await assertConfigAndLoadSatelliteContext(args); + const {satellite} = await assertConfigAndLoadSatelliteContext(); const {satelliteId} = satellite; const defaultUrl = defaultSatelliteDomain(satelliteId); diff --git a/src/services/modules/snapshot/snapshot.satellite.services.ts b/src/services/modules/snapshot/snapshot.satellite.services.ts index 4b9ea8ee..6aecba84 100644 --- a/src/services/modules/snapshot/snapshot.satellite.services.ts +++ b/src/services/modules/snapshot/snapshot.satellite.services.ts @@ -5,32 +5,27 @@ import {consoleNoConfigFound} from '../../../utils/msg.utils'; import {assertConfigAndLoadSatelliteContext} from '../../../utils/satellite.utils'; import {createSnapshot, deleteSnapshot, restoreSnapshot} from './snapshot.services'; -export const createSnapshotSatellite = async (params: {args?: string[]}) => { +export const createSnapshotSatellite = async () => { await executeSnapshotFn({ - ...params, fn: createSnapshot }); }; -export const restoreSnapshotSatellite = async (params: {args?: string[]}) => { +export const restoreSnapshotSatellite = async () => { await executeSnapshotFn({ - ...params, fn: restoreSnapshot }); }; -export const deleteSnapshotSatellite = async (params: {args?: string[]}) => { +export const deleteSnapshotSatellite = async () => { await executeSnapshotFn({ - ...params, fn: deleteSnapshot }); }; const executeSnapshotFn = async ({ - args, fn }: { - args?: string[]; fn: (params: {canisterId: string; segment: AssetKey}) => Promise; }) => { if (!(await junoConfigExist())) { @@ -38,7 +33,7 @@ const executeSnapshotFn = async ({ return; } - const satelliteId = await loadSatelliteId({args}); + const satelliteId = await loadSatelliteId(); await fn({ canisterId: satelliteId, @@ -46,8 +41,8 @@ const executeSnapshotFn = async ({ }); }; -const loadSatelliteId = async ({args}: {args?: string[]}): Promise => { - const {satellite} = await assertConfigAndLoadSatelliteContext(args); +const loadSatelliteId = async (): Promise => { + const {satellite} = await assertConfigAndLoadSatelliteContext(); const {satelliteId} = satellite; // TS guard. satelliteParameters exit if satelliteId is undefined. diff --git a/src/services/modules/start-stop.services.ts b/src/services/modules/start-stop.services.ts index fe410d15..214c85ba 100644 --- a/src/services/modules/start-stop.services.ts +++ b/src/services/modules/start-stop.services.ts @@ -49,14 +49,8 @@ export const startStopOrbiter = async ({action}: {args?: string[]; action: Start }); }; -export const startStopSatellite = async ({ - args, - action -}: { - args?: string[]; - action: StartStopAction; -}) => { - const {satellite} = await assertConfigAndLoadSatelliteContext(args); +export const startStopSatellite = async ({action}: {action: StartStopAction}) => { + const {satellite} = await assertConfigAndLoadSatelliteContext(); const {satelliteId} = satellite; await startStop({ diff --git a/src/services/modules/upgrade/upgrade.satellite.services.ts b/src/services/modules/upgrade/upgrade.satellite.services.ts index ed9776b7..abfc7314 100644 --- a/src/services/modules/upgrade/upgrade.satellite.services.ts +++ b/src/services/modules/upgrade/upgrade.satellite.services.ts @@ -29,7 +29,7 @@ import { } from './upgrade.services'; export const upgradeSatellite = async (args?: string[]) => { - const {satellite} = await assertConfigAndLoadSatelliteContext(args); + const {satellite} = await assertConfigAndLoadSatelliteContext(); const {satelliteId} = satellite; console.log( diff --git a/src/utils/config.utils.ts b/src/utils/config.utils.ts index 32fd2705..c5dc3c36 100644 --- a/src/utils/config.utils.ts +++ b/src/utils/config.utils.ts @@ -1,6 +1,4 @@ import {nonNullish} from '@dfinity/utils'; -import {nextArg} from '@junobuild/cli-tools'; -import type {JunoConfigEnv} from '@junobuild/config'; import Conf from 'conf'; import envPaths from 'env-paths'; import {existsSync} from 'node:fs'; @@ -8,13 +6,6 @@ import {resolve} from 'node:path'; import {CONFIG_OPTIONS} from '../constants/config.constants'; import type {CliConfig} from '../types/cli.config'; -export const configEnv = (args?: string[]): JunoConfigEnv => { - const mode = nextArg({args, option: '-m'}) ?? nextArg({args, option: '--mode'}); - return { - mode: mode ?? 'production' - }; -}; - export const loadConfig = (encryptionKey: string | undefined): Conf => { return new Conf({ ...CONFIG_OPTIONS, diff --git a/src/utils/satellite.utils.ts b/src/utils/satellite.utils.ts index d7dc040c..b0da38e2 100644 --- a/src/utils/satellite.utils.ts +++ b/src/utils/satellite.utils.ts @@ -1,36 +1,32 @@ import {assertNonNullish, isNullish} from '@dfinity/utils'; -import {type JunoConfigEnv, type SatelliteConfig} from '@junobuild/config'; +import {type SatelliteConfig} from '@junobuild/config'; import {red} from 'kleur'; import {actorParameters} from '../api/actor.api'; import {getCliOrbiters, getCliSatellites} from '../configs/cli.config'; import {junoConfigExist, readJunoConfig} from '../configs/juno.config'; +import {ENV} from '../env'; import type {SatelliteConfigEnv} from '../types/config'; import type {SatelliteParametersWithId} from '../types/satellite'; -import {configEnv} from './config.utils'; import {consoleNoConfigFound} from './msg.utils'; -export const assertConfigAndLoadSatelliteContext = async ( - args?: string[] -): Promise<{ +export const assertConfigAndLoadSatelliteContext = async (): Promise<{ satellite: SatelliteParametersWithId; satelliteConfig: SatelliteConfig; - env: JunoConfigEnv; }> => { if (!(await junoConfigExist())) { consoleNoConfigFound(); process.exit(1); } - const env = configEnv(args); - const {satellite: satelliteConfig} = await readJunoConfig(env); + const {satellite: satelliteConfig} = await readJunoConfig(ENV); - const satellite = await satelliteParameters({satellite: satelliteConfig, env}); + const satellite = await satelliteParameters({satellite: satelliteConfig, env: ENV}); // TS guard. satelliteParameters exit if satelliteId is undefined. // Should not happen. assertNonNullish(satellite.satelliteId); - return {satellite, satelliteConfig, env}; + return {satellite, satelliteConfig}; }; const satelliteParameters = async ({