From 207e5d30323d327a3621c8fa2c7065cce0feadea Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Wed, 4 Jun 2025 07:02:20 +0200 Subject: [PATCH 1/2] feat: split upgrade to publish --- src/commands/functions.ts | 10 +++- src/constants/help.constants.ts | 1 + src/help/functions.help.ts | 1 + src/help/functions.publish.help.ts | 38 +++++++++++++++ src/help/functions.upgrade.help.ts | 15 +----- ...oposal.services.ts => publish.services.ts} | 46 +++++++++++-------- src/services/functions/upgrade.services.ts | 17 +++++++ .../functions/upgrade/upgrade.services.ts | 34 -------------- src/types/functions.ts | 7 --- 9 files changed, 95 insertions(+), 74 deletions(-) create mode 100644 src/help/functions.publish.help.ts rename src/services/functions/{upgrade/upgrade.with-proposal.services.ts => publish.services.ts} (72%) create mode 100644 src/services/functions/upgrade.services.ts delete mode 100644 src/services/functions/upgrade/upgrade.services.ts delete mode 100644 src/types/functions.ts diff --git a/src/commands/functions.ts b/src/commands/functions.ts index ab9d2adc..b55c6cb5 100644 --- a/src/commands/functions.ts +++ b/src/commands/functions.ts @@ -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 ?? []; @@ -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; @@ -36,6 +41,9 @@ export const helpFunctions = (args?: string[]) => { case 'eject': logHelpFunctionsEject(args); break; + case 'publish': + logHelpFunctionsPublish(args); + break; case 'upgrade': logHelpFunctionsUpgrade(args); break; diff --git a/src/constants/help.constants.ts b/src/constants/help.constants.ts index 1399b80f..bc3e100d 100644 --- a/src/constants/help.constants.ts +++ b/src/constants/help.constants.ts @@ -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 = diff --git a/src/help/functions.help.ts b/src/help/functions.help.ts index 98870db1..32c135aa 100644 --- a/src/help/functions.help.ts +++ b/src/help/functions.help.ts @@ -8,6 +8,7 @@ const usage = `Usage: ${green('juno')} ${cyan('functions')} ${magenta(' { + console.log(helpOutput(args) === 'doc' ? doc : help); +}; diff --git a/src/help/functions.upgrade.help.ts b/src/help/functions.upgrade.help.ts index 29be2b78..c9aa1248 100644 --- a/src/help/functions.upgrade.help.ts +++ b/src/help/functions.upgrade.help.ts @@ -1,9 +1,7 @@ import {cyan, green, magenta, yellow} from 'kleur'; import { FUNCTIONS_UPGRADE_DESCRIPTION, - NOTE_KEEP_STAGED, OPTION_HELP, - OPTION_KEEP_STAGED, OPTIONS_UPGRADE } from '../constants/help.constants'; import {helpOutput} from './common.help'; @@ -12,18 +10,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. + ${yellow('-s, --src')} A path to a specific local gzipped WASM file for the upgrade. ${OPTIONS_UPGRADE} - -Notes: - -- ${NOTE_KEEP_STAGED}`; + ${OPTION_HELP}`; const doc = `${FUNCTIONS_UPGRADE_DESCRIPTION} diff --git a/src/services/functions/upgrade/upgrade.with-proposal.services.ts b/src/services/functions/publish.services.ts similarity index 72% rename from src/services/functions/upgrade/upgrade.with-proposal.services.ts rename to src/services/functions/publish.services.ts index 09999756..1b77d524 100644 --- a/src/services/functions/upgrade/upgrade.with-proposal.services.ts +++ b/src/services/functions/publish.services.ts @@ -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, diff --git a/src/services/functions/upgrade.services.ts b/src/services/functions/upgrade.services.ts new file mode 100644 index 00000000..217950a2 --- /dev/null +++ b/src/services/functions/upgrade.services.ts @@ -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 + }); +}; diff --git a/src/services/functions/upgrade/upgrade.services.ts b/src/services/functions/upgrade/upgrade.services.ts deleted file mode 100644 index d9630a73..00000000 --- a/src/services/functions/upgrade/upgrade.services.ts +++ /dev/null @@ -1,34 +0,0 @@ -import {hasArgs, nextArg} from '@junobuild/cli-tools'; -import {SATELLITE_OUTPUT} from '../../../constants/dev.constants'; -import {type UpgradeFunctionsParams} from '../../../types/functions'; -import {assertConfigAndLoadSatelliteContext} from '../../../utils/satellite.utils'; -import {upgradeSatelliteWithSrc} from '../../modules/upgrade/upgrade.satellite.services'; -import {upgradeFunctionsWithProposal} from './upgrade.with-proposal.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`; - - const immediate = hasArgs({args, options: ['-i', '--immediate']}); - - if (immediate) { - await upgradeImmediate({ - args, - src, - satellite - }); - return; - } - - await upgradeFunctionsWithProposal({ - args, - src, - satellite - }); -}; - -const upgradeImmediate = async (params: UpgradeFunctionsParams) => { - await upgradeSatelliteWithSrc(params); -}; diff --git a/src/types/functions.ts b/src/types/functions.ts deleted file mode 100644 index 5b82e081..00000000 --- a/src/types/functions.ts +++ /dev/null @@ -1,7 +0,0 @@ -import {type SatelliteParametersWithId} from './satellite'; - -export interface UpgradeFunctionsParams { - src: string; - satellite: SatelliteParametersWithId; - args?: string[]; -} From 5cb039b66a95e5c6b314b5122ce06b96887a8594 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Wed, 4 Jun 2025 07:08:45 +0200 Subject: [PATCH 2/2] feat: src option --- src/constants/help.constants.ts | 2 +- src/help/functions.publish.help.ts | 4 +++- src/help/functions.upgrade.help.ts | 3 ++- src/help/upgrade.help.ts | 9 +++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/constants/help.constants.ts b/src/constants/help.constants.ts index bc3e100d..f2187c24 100644 --- a/src/constants/help.constants.ts +++ b/src/constants/help.constants.ts @@ -43,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.`; diff --git a/src/help/functions.publish.help.ts b/src/help/functions.publish.help.ts index 3d4983e6..e185943a 100644 --- a/src/help/functions.publish.help.ts +++ b/src/help/functions.publish.help.ts @@ -3,7 +3,8 @@ import { FUNCTIONS_PUBLISH_DESCRIPTION, NOTE_KEEP_STAGED, OPTION_HELP, - OPTION_KEEP_STAGED + OPTION_KEEP_STAGED, + OPTION_SRC } from '../constants/help.constants'; import {helpOutput} from './common.help'; import {TITLE} from './help'; @@ -13,6 +14,7 @@ const usage = `Usage: ${green('juno')} ${cyan('functions')} ${magenta('publish') 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: diff --git a/src/help/functions.upgrade.help.ts b/src/help/functions.upgrade.help.ts index c9aa1248..1aafe8a7 100644 --- a/src/help/functions.upgrade.help.ts +++ b/src/help/functions.upgrade.help.ts @@ -2,6 +2,7 @@ import {cyan, green, magenta, yellow} from 'kleur'; import { FUNCTIONS_UPGRADE_DESCRIPTION, OPTION_HELP, + OPTION_SRC, OPTIONS_UPGRADE } from '../constants/help.constants'; import {helpOutput} from './common.help'; @@ -10,7 +11,7 @@ import {TITLE} from './help'; const usage = `Usage: ${green('juno')} ${cyan('functions')} ${magenta('upgrade')} ${yellow('[options]')} Options: - ${yellow('-s, --src')} A path to a specific local gzipped WASM file for the upgrade. + ${OPTION_SRC} ${OPTIONS_UPGRADE} ${OPTION_HELP}`; diff --git a/src/help/upgrade.help.ts b/src/help/upgrade.help.ts index 7754f8b1..a1e40d9e 100644 --- a/src/help/upgrade.help.ts +++ b/src/help/upgrade.help.ts @@ -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'; @@ -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}