UNPKG

@apistudio/apim-cli

Version:

CLI for API Management Products

45 lines (44 loc) 1.83 kB
/** * Copyright Super iPaaS Integration LLC, an IBM Company 2024 */ import { showSuccess, showWarning } from '../helpers/common/message-helper.js'; import { buildAssets, buildProjects, getOutputPath } from './helpers/build-action-helper.js'; import { convertAdmToJsZip } from '../converters/adm-to-jszip-convertor.js'; import { IGNORE_NAMES_OPT, IGNORE_PROJECT_ARG, BUILD_SUCCESSFUL, FILE_OVERWRITTEN, CREATED_BUILD_ZIP, OUTPUT_DIR_PATH_TO_BE_CREATED } from '../constants/message-constants.js'; import { createBuildZip, normalizePath } from '../helpers/common/fs-helper.js'; import { setupDebugManager } from './test-action.js'; import { BUILD } from '../constants/app-constants.js'; const buildAction = async (projects, options) => { const localDir = options.localDir; let outputPath; let zipBuffer; const debug = options.debug; setupDebugManager(debug); if (options.output) { outputPath = options.output; } else { outputPath = normalizePath(`${process.cwd()}/`) + `${await getOutputPath(projects, options.all, options.names, BUILD)}`; } if (options.names && !options.all) { zipBuffer = await buildAssets(options.names, localDir, projects); } else { if (projects && options.all) { showWarning(IGNORE_PROJECT_ARG); } if (options.names && options.all) { showWarning(IGNORE_NAMES_OPT); } zipBuffer = await buildProjects(options.all, localDir, projects); } if (await createBuildZip(await convertAdmToJsZip(zipBuffer), outputPath)) { showSuccess(BUILD_SUCCESSFUL); if (options.output) { showWarning(OUTPUT_DIR_PATH_TO_BE_CREATED); } showWarning(FILE_OVERWRITTEN); showSuccess(CREATED_BUILD_ZIP + outputPath); } }; export { buildAction };