@apistudio/apim-cli
Version:
CLI for API Management Products
50 lines (43 loc) • 1.8 kB
text/typescript
/**
* Copyright Super iPaaS Integration LLC, an IBM Company 2024
*/
import {showSuccess, showWarning} from '../helpers/common/message-helper.js';
import {BuildOptionsModel} from '../model/studio/command-options/build-options-model.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: string, options: BuildOptionsModel) => {
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 };