UNPKG

@equinor/fusion-framework-cli

Version:

--- title: Fusion Framework CLI ---

105 lines 4.83 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { chalk } from './utils/format.js'; import { Spinner } from './utils/spinner.js'; import { bundleApplication } from './bundle-application.js'; import { resolveAppPackage } from '../lib/app-package.js'; import { isAppRegistered, getEndpointUrl, requireToken, tagAppBundle, uploadAppBundle, loadAppManifest, } from './utils/index.js'; import { exit } from 'node:process'; import assert from 'node:assert'; export const publishApplication = (options) => __awaiter(void 0, void 0, void 0, function* () { const { tag, env, service } = options; const spinner = Spinner.Global({ prefixText: chalk.dim('Publish') }); try { spinner.info('Validating FUSION_TOKEN'); // make sure token exist requireToken(); // call service discovery with token, will throw error if failed yield getEndpointUrl('apps', env, ''); spinner.succeed('Found valid FUSION_TOKEN'); } catch (e) { const err = e; spinner.fail(chalk.bgRed(err.message)); exit(1); } const pkg = yield resolveAppPackage(); const { manifest } = yield loadAppManifest({ command: 'build', mode: 'prod' }, pkg); const { appKey } = manifest; try { spinner.info('Verifying that App is registered'); const state = { endpoint: '' }; try { state.endpoint = yield getEndpointUrl(`apps/${appKey}`, env, service); } catch (e) { const err = e; throw new Error(`Could not get endpoint from service discovery while verifying app is registered. service-discovery status: ${err.message}`); } const exist = yield isAppRegistered(state.endpoint); assert(exist, `${appKey} is not registered`); spinner.succeed(`${appKey} is registered`); } catch (e) { const err = e; spinner.fail('🙅‍♂️', chalk.bgRed(err.message)); throw err; } const bundle = 'app-bundle.zip'; /* Zip app bundle */ spinner.info('Creating zip bundle'); yield bundleApplication({ archive: bundle, outDir: 'dist', }); const state = { uploadedBundle: { version: '' }, endpoint: '', }; spinner.info(`Publishing app: "${appKey}" with tag: "${tag}"`); /* Upload app bundle */ try { spinner.info(`Uploading bundle ${chalk.yellowBright(bundle)} to appKey ${chalk.yellowBright(appKey)}`); try { state.endpoint = yield getEndpointUrl(`bundles/apps/${appKey}`, env, service); } catch (e) { const err = e; throw new Error(`Could not get endpoint from service discovery while uploading app bundle. service-discovery status: ${err.message}`); } spinner.info(`Posting bundle to => ${state.endpoint}`); state.uploadedBundle = yield uploadAppBundle(state.endpoint, bundle); spinner.succeed('✅', `Uploaded bundle: "${chalk.greenBright(bundle)}" with version: ${chalk.greenBright(state.uploadedBundle.version)}"`); } catch (e) { const err = e; spinner.fail('🙅‍♂️', chalk.bgRed(err.message)); exit(1); } try { spinner.info(`Tagging ${state.uploadedBundle.version} with ${tag}`); try { state.endpoint = yield getEndpointUrl(`apps/${appKey}/tags/${tag}`, env, service); } catch (e) { const err = e; throw new Error(`Could not get endpoint from service discovery while tagging app. service-discovery status: ${err.message}`); } const tagged = yield tagAppBundle(state.endpoint, state.uploadedBundle.version); spinner.succeed('✅', `Tagged version ${chalk.greenBright(tagged.version)} with ${chalk.greenBright(tagged.tagName)}`); } catch (e) { const err = e; spinner.fail('🙅‍♂️', chalk.bgRed(err.message)); exit(1); } spinner.succeed('⭐️', `Published app: "${chalk.greenBright(appKey)}" version: "${chalk.greenBright(state.uploadedBundle.version)}" with tagg: "${chalk.greenBright(tag)}"`); }); //# sourceMappingURL=publish-application.js.map