@equinor/fusion-framework-cli
Version:
--- title: Fusion Framework CLI ---
77 lines • 3.55 kB
JavaScript
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 nodeFs from 'node:fs';
import { writeFile } from 'node:fs/promises';
import assert from 'node:assert';
import { SemVer, parse as parseSemver } from 'semver';
import { chalk, formatPath } from './utils/format.js';
import { Spinner } from './utils/spinner.js';
import { loadAppManifest } from './utils/load-manifest.js';
import { loadPackage } from './utils/load-package.js';
import { dirname } from 'node:path';
// TODO why do we do this??? can`t backend parse semver?
export const normalizeVersion = (version) => {
const semverVersion = parseSemver(version);
assert(semverVersion instanceof SemVer, 'expected version in AppManifest to be SemVer');
const { major, minor, patch } = semverVersion;
return { major, minor, patch };
};
export const createAppManifest = (options) => __awaiter(void 0, void 0, void 0, function* () {
Spinner.Global({ prefixText: chalk.dim('app manifest') });
const manifest = yield createManifest(options);
if (options === null || options === void 0 ? void 0 : options.outputFile) {
yield writeManifestToDisk(manifest, options.outputFile);
}
else {
console.log(JSON.stringify(manifest, undefined, 2));
}
return manifest;
});
export const createBuildManifest = (options) => __awaiter(void 0, void 0, void 0, function* () {
Spinner.Global({ prefixText: chalk.dim('build manifest') });
const { build } = yield createManifest(options);
if (options === null || options === void 0 ? void 0 : options.outputFile) {
yield writeManifestToDisk(build, options.outputFile);
}
else {
console.log(JSON.stringify(build, undefined, 2));
}
return build;
});
const writeManifestToDisk = (content, outputFile) => __awaiter(void 0, void 0, void 0, function* () {
const spinner = Spinner.Clone();
spinner.start(`Exporting manifest to ${formatPath(outputFile)}`);
try {
const dir = dirname(outputFile).trim();
if (!nodeFs.existsSync(dirname(outputFile))) {
nodeFs.mkdirSync(dir, { recursive: true });
}
yield writeFile(outputFile, JSON.stringify(content));
spinner.succeed();
}
catch (err) {
spinner.fail();
throw err;
}
});
const createManifest = (options) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b;
const pkg = yield loadPackage();
const env = {
command: (_a = options === null || options === void 0 ? void 0 : options.command) !== null && _a !== void 0 ? _a : 'build',
mode: (_b = process.env.NODE_ENV) !== null && _b !== void 0 ? _b : 'development',
root: pkg.root,
};
const { manifest } = yield loadAppManifest(env, pkg, {
file: options === null || options === void 0 ? void 0 : options.configFile,
});
return manifest;
});
//# sourceMappingURL=create-export-manifest.js.map