UNPKG

@equinor/fusion-framework-cli

Version:

--- title: Fusion Framework CLI ---

50 lines 2.56 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 AdmZip from 'adm-zip'; import { dirname, resolve } from 'node:path'; import { mkdir } from 'node:fs/promises'; import { chalk, formatByteSize, formatPath } from './utils/format.js'; import { Spinner } from './utils/spinner.js'; import { buildApplication } from './build-application.js'; import { createBuildManifest } from './create-export-manifest.js'; import { fileExistsSync } from '../lib/utils/file-exists.js'; export const bundleApplication = (options) => __awaiter(void 0, void 0, void 0, function* () { const { outDir, archive } = options; const spinner = Spinner.Global({ prefixText: chalk.dim('pack') }); spinner.start('build application'); const { pkg } = yield buildApplication({ outDir }); spinner.succeed(); spinner.start('generate manifest'); const buildManifest = yield createBuildManifest({ outputFile: `${outDir}/app-manifest.json` }); spinner.succeed('generated manifest:', '\n' + JSON.stringify(buildManifest, undefined, 2)); const bundle = new AdmZip(); bundle.addLocalFolder(outDir); spinner.info(`added ./${outDir}`); const appDir = dirname(pkg.path); /* Files to add to zip package */ const addFiles = ['package.json', 'LICENSE.md', 'README.md', 'CHANGELOG.md']; for (const file of addFiles) { const filePath = resolve(appDir, file); if (fileExistsSync(filePath)) { bundle.addLocalFile(filePath); spinner.info(`added ${file}`); } else { spinner.warn(`missing ${file}`); } } spinner.start('compressing content'); if (!fileExistsSync(dirname(archive))) { yield mkdir(dirname(archive), { recursive: true }); } bundle.writeZip(archive); spinner.succeed('Bundle complete', formatPath(archive, { relative: true }), formatByteSize(archive)); }); //# sourceMappingURL=bundle-application.js.map