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
10 changes: 9 additions & 1 deletion src/commands/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import {red} from 'kleur';
import {logHelpFunctionsBuild} from '../help/functions.build.help';
import {logHelpFunctionsEject} from '../help/functions.eject.help';
import {logHelpFunctions} from '../help/functions.help';
import {logHelpFunctionsPublish} from '../help/functions.publish.help';
import {logHelpFunctionsUpgrade} from '../help/functions.upgrade.help';
import {build} from '../services/functions/build/build.services';
import {eject} from '../services/functions/eject/eject.services';
import {upgradeFunctions} from '../services/functions/upgrade/upgrade.services';
import {publish} from '../services/functions/publish.services';
import {upgradeFunctions} from '../services/functions/upgrade.services';

export const functions = async (args?: string[]) => {
const [subCommand] = args ?? [];
Expand All @@ -17,6 +19,9 @@ export const functions = async (args?: string[]) => {
case 'build':
await build(args);
break;
case 'publish':
await publish(args);
break;
case 'upgrade':
await upgradeFunctions(args);
break;
Expand All @@ -36,6 +41,9 @@ export const helpFunctions = (args?: string[]) => {
case 'eject':
logHelpFunctionsEject(args);
break;
case 'publish':
logHelpFunctionsPublish(args);
break;
case 'upgrade':
logHelpFunctionsUpgrade(args);
break;
Expand Down
3 changes: 2 additions & 1 deletion src/constants/help.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const WHOAMI_DESCRIPTION =

export const DEV_START_DESCRIPTION = 'Start a local Internet Computer network in a container.';

export const FUNCTIONS_PUBLISH_DESCRIPTION = 'Publish a new version of your serverless functions.';
export const FUNCTIONS_UPGRADE_DESCRIPTION = 'Upgrade your serverless functions.';
export const FUNCTIONS_BUILD_DESCRIPTION = 'Build your serverless functions.';
export const FUNCTIONS_EJECT_DESCRIPTION =
Expand All @@ -42,7 +43,7 @@ export const CHANGES_REJECT_DESCRIPTION = 'Reject a change.';
export const OPTION_KEEP_STAGED = `${yellow('-k, --keep-staged')} Keep staged assets in memory after applying the change.`;
export const OPTION_HASH = `${yellow('-a, --hash')} The expected hash of all included changes (for verification).`;
export const OPTION_HELP = `${yellow('-h, --help')} Output usage information.`;

export const OPTION_SRC = `${yellow('-s, --src')} A path to a specific local gzipped WASM file to publish.`;
export const OPTIONS_UPGRADE = `${yellow('-r, --reset')} Reset to the initial state.
${yellow('-cc, --clear-chunks')} Clear any previously uploaded WASM chunks (applies if the WASM size is greater than 2MB).
${yellow('-ns, --no-snapshot')} Skip creating a snapshot before upgrading.`;
Expand Down
1 change: 1 addition & 0 deletions src/help/functions.help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const usage = `Usage: ${green('juno')} ${cyan('functions')} ${magenta('<subcomma
Subcommands:
${magenta('build')} Build your functions.
${magenta('eject')} Scaffold the necessary files for developing your serverless functions.
${magenta('publish')} Publish a new version of your functions.
${magenta('upgrade')} Upgrade your satellite's serverless functions.

Notes:
Expand Down
40 changes: 40 additions & 0 deletions src/help/functions.publish.help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {cyan, green, magenta, yellow} from 'kleur';
import {
FUNCTIONS_PUBLISH_DESCRIPTION,
NOTE_KEEP_STAGED,
OPTION_HELP,
OPTION_KEEP_STAGED,
OPTION_SRC
} from '../constants/help.constants';
import {helpOutput} from './common.help';
import {TITLE} from './help';

const usage = `Usage: ${green('juno')} ${cyan('functions')} ${magenta('publish')} ${yellow('[options]')}

Options:
${yellow('-na, --no-apply')} Submit the release as a change but do not apply it yet.
${OPTION_KEEP_STAGED}
${OPTION_SRC}
${OPTION_HELP}

Notes:

- ${NOTE_KEEP_STAGED}`;

const doc = `${FUNCTIONS_PUBLISH_DESCRIPTION}

\`\`\`
${usage}
\`\`\`
`;

const help = `${TITLE}

${FUNCTIONS_PUBLISH_DESCRIPTION}

${usage}
`;

export const logHelpFunctionsPublish = (args?: string[]) => {
console.log(helpOutput(args) === 'doc' ? doc : help);
};
16 changes: 3 additions & 13 deletions src/help/functions.upgrade.help.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {cyan, green, magenta, yellow} from 'kleur';
import {
FUNCTIONS_UPGRADE_DESCRIPTION,
NOTE_KEEP_STAGED,
OPTION_HELP,
OPTION_KEEP_STAGED,
OPTION_SRC,
OPTIONS_UPGRADE
} from '../constants/help.constants';
import {helpOutput} from './common.help';
Expand All @@ -12,18 +11,9 @@ import {TITLE} from './help';
const usage = `Usage: ${green('juno')} ${cyan('functions')} ${magenta('upgrade')} ${yellow('[options]')}

Options:
${yellow('-na, --no-apply')} Submit the upgrade as a change but do not apply it yet.
${OPTION_KEEP_STAGED}
${yellow('-i, --immediate')} Push the upgrade immediately (bypasses the change workflow).
${OPTION_HELP}

Upgrade options:
${yellow('-s, --src')} An optional local gzipped WASM file for the upgrade.
${OPTION_SRC}
${OPTIONS_UPGRADE}

Notes:

- ${NOTE_KEEP_STAGED}`;
${OPTION_HELP}`;

const doc = `${FUNCTIONS_UPGRADE_DESCRIPTION}

Expand Down
9 changes: 7 additions & 2 deletions src/help/upgrade.help.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {cyan, green, yellow} from 'kleur';
import {OPTION_HELP, OPTIONS_UPGRADE, UPGRADE_DESCRIPTION} from '../constants/help.constants';
import {
OPTION_HELP,
OPTION_SRC,
OPTIONS_UPGRADE,
UPGRADE_DESCRIPTION
} from '../constants/help.constants';
import {helpMode, helpOutput} from './common.help';
import {TITLE} from './help';
import {TARGET_OPTION_NOTE, targetOption} from './target.help';
Expand All @@ -8,7 +13,7 @@ const usage = `Usage: ${green('juno')} ${cyan('upgrade')} ${yellow('[options]')}

Options:
${targetOption('upgrade')}
${yellow('-s, --src')} An optional local gzipped WASM file for the upgrade. By default, the CDN will be used.
${OPTION_SRC}
${OPTIONS_UPGRADE}
${helpMode}
${OPTION_HELP}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,39 @@ import {
deploySatelliteWasmWithProposal,
type FilePaths,
hasArgs,
nextArg,
type UploadFileStorageWithProposal
} from '@junobuild/cli-tools';
import {red} from 'kleur';
import {dirname} from 'node:path';
import {CDN_RELEASES_FULL_PATH} from '../../../constants/functions.constants';
import {type UpgradeFunctionsParams} from '../../../types/functions';
import type {SatelliteParametersWithId} from '../../../types/satellite';
import {readWasmFileMetadata} from '../../../utils/wasm.utils';
import {assertSatelliteMemorySize} from '../../assets/deploy/deploy.assert.services';
import {type UploadFileFnParamsWithProposal} from '../../assets/deploy/deploy.execute.services';
import {clearProposalStagedAssets} from '../../changes/changes.clear.services';
import {upgradeSatelliteWithSrc} from '../../modules/upgrade/upgrade.satellite.services';

export const upgradeFunctionsWithProposal = async (params: UpgradeFunctionsParams) => {
const result = await deployWasmWithProposal(params);

if (result.result !== 'deployed') {
return;
}

console.log('');

await upgradeSatelliteWithSrc(params);
import {SATELLITE_OUTPUT} from '../../constants/dev.constants';
import {CDN_RELEASES_FULL_PATH} from '../../constants/functions.constants';
import type {SatelliteParametersWithId} from '../../types/satellite';
import {assertConfigAndLoadSatelliteContext} from '../../utils/satellite.utils';
import {readWasmFileMetadata} from '../../utils/wasm.utils';
import {assertSatelliteMemorySize} from '../assets/deploy/deploy.assert.services';
import {type UploadFileFnParamsWithProposal} from '../assets/deploy/deploy.execute.services';
import {clearProposalStagedAssets} from '../changes/changes.clear.services';

export const publish = async (args?: string[]) => {
const {satellite} = await assertConfigAndLoadSatelliteContext(args);

const srcArgs = nextArg({args, option: '-s'}) ?? nextArg({args, option: '--src'});
const src = srcArgs ?? `${SATELLITE_OUTPUT}.gz`;

await deployWasmWithProposal({
args,
src,
satellite
});
};

interface UpgradeFunctionsParams {
src: string;
satellite: SatelliteParametersWithId;
args?: string[];
}

const deployWasmWithProposal = async ({
args,
src,
Expand Down
17 changes: 17 additions & 0 deletions src/services/functions/upgrade.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {nextArg} from '@junobuild/cli-tools';
import {SATELLITE_OUTPUT} from '../../constants/dev.constants';
import {assertConfigAndLoadSatelliteContext} from '../../utils/satellite.utils';
import {upgradeSatelliteWithSrc} from '../modules/upgrade/upgrade.satellite.services';

export const upgradeFunctions = async (args?: string[]) => {
const {satellite} = await assertConfigAndLoadSatelliteContext(args);

const srcArgs = nextArg({args, option: '-s'}) ?? nextArg({args, option: '--src'});
const src = srcArgs ?? `${SATELLITE_OUTPUT}.gz`;

await upgradeSatelliteWithSrc({
args,
src,
satellite
});
};
34 changes: 0 additions & 34 deletions src/services/functions/upgrade/upgrade.services.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/types/functions.ts

This file was deleted.