Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
4 changes: 2 additions & 2 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 5 additions & 7 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -89,7 +89,6 @@ const deployWithProposal = async ({args, clearOption}: {args?: string[]; clearOp
};

const result = await executeDeployWithProposal({
args,
deployFn,
uploadFileFn
});
Expand All @@ -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<DeployResult> =>
Expand Down Expand Up @@ -138,10 +137,9 @@ const deployImmediate = async ({args, clearOption}: {args?: string[]; clearOptio
};

await executeDeployImmediate({
args,
deployFn,
uploadFileFn
});

await links(args);
await links();
};
2 changes: 1 addition & 1 deletion src/commands/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'});
Expand Down
4 changes: 2 additions & 2 deletions src/commands/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const executeSnapshotFn = async ({
orbiterFn
}: {
args?: string[];
satelliteFn: (params: {args?: string[]}) => Promise<void>;
satelliteFn: () => Promise<void>;
missionControlFn: () => Promise<void>;
orbiterFn: () => Promise<void>;
}) => {
Expand All @@ -68,7 +68,7 @@ const executeSnapshotFn = async ({
switch (target) {
case 's':
case 'satellite':
await satelliteFn({args});
await satelliteFn();
break;
case 'm':
case 'mission-control':
Expand Down
2 changes: 1 addition & 1 deletion src/commands/start-stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
6 changes: 3 additions & 3 deletions src/commands/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const version = async (args?: string[]) => {
}

await missionControlVersion();
await satelliteVersion(args);
await satelliteVersion();
await orbitersVersion();
};

Expand Down Expand Up @@ -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<string | undefined> => {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/whoami.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}> => {
Expand Down
14 changes: 14 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -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();
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/services/assets/clear.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/services/assets/deploy/deploy.assert.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 2 additions & 8 deletions src/services/assets/deploy/deploy.execute.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export type UploadFileFnParams = UploadFileStorage & {satellite: SatelliteParame
export type UploadFileFnParamsWithProposal = UploadFileFnParams & {proposalId: bigint};

export const executeDeployWithProposal = async ({
args,
deployFn,
uploadFileFn
}: {
Expand All @@ -34,14 +33,12 @@ export const executeDeployWithProposal = async ({
uploadFileFn: (params: UploadFileFnParamsWithProposal) => Promise<void>;
}): Promise<DeployResultWithProposal> => {
return await executeDeploy<UploadFileStorageWithProposal, DeployResultWithProposal>({
args,
deployFn,
uploadFileFn
});
};

export const executeDeployImmediate = async ({
args,
deployFn,
uploadFileFn
}: {
Expand All @@ -50,7 +47,6 @@ export const executeDeployImmediate = async ({
uploadFileFn: (params: UploadFileFnParams) => Promise<void>;
}): Promise<DeployResult> => {
return await executeDeploy<UploadFileStorage, DeployResult>({
args,
deployFn,
uploadFileFn
});
Expand All @@ -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<void>>) => Promise<R>;
uploadFileFn: (params: P & {satellite: SatelliteParametersWithId}) => Promise<void>;
}): Promise<R> => {
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<Asset[]> =>
await listAssets({
Expand Down
2 changes: 1 addition & 1 deletion src/services/changes/changes.apply.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/services/changes/changes.clear.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion src/services/changes/changes.list.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']});
Expand Down
2 changes: 1 addition & 1 deletion src/services/changes/changes.reject.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/services/functions/publish.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down Expand Up @@ -127,7 +127,7 @@ const publishWasmWithProposal = async ({
};

const assertMemory = async () => {
await assertSatelliteMemorySize(args);
await assertSatelliteMemorySize();
};

const sourceAbsolutePath = dirname(filePath);
Expand Down
2 changes: 1 addition & 1 deletion src/services/functions/upgrade/upgrade.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']});

Expand Down
4 changes: 2 additions & 2 deletions src/services/links.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 6 additions & 11 deletions src/services/modules/snapshot/snapshot.satellite.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,44 @@ 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<void>;
}) => {
if (!(await junoConfigExist())) {
consoleNoConfigFound();
return;
}

const satelliteId = await loadSatelliteId({args});
const satelliteId = await loadSatelliteId();

await fn({
canisterId: satelliteId,
segment: 'satellite'
});
};

const loadSatelliteId = async ({args}: {args?: string[]}): Promise<string> => {
const {satellite} = await assertConfigAndLoadSatelliteContext(args);
const loadSatelliteId = async (): Promise<string> => {
const {satellite} = await assertConfigAndLoadSatelliteContext();
const {satelliteId} = satellite;

// TS guard. satelliteParameters exit if satelliteId is undefined.
Expand Down
Loading