UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

57 lines (56 loc) 2.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createBuildJobArtifacts = void 0; const path_1 = require("path"); const types_1 = require("../../types"); const lodash_es_1 = require("lodash-es"); const writeDotEnv_1 = require("../base/writeDotEnv"); const uniqueAndAlphabeticalSort = arr => { return (0, lodash_es_1.uniq)(arr).sort((a, b) => a.localeCompare(b)); }; const createBuildJobArtifacts = async context => { var _a, _b; const paths = context.type === "workspace" ? (await Promise.all(context.components.map(c => getArtifactsPathForComponent(c)))).flat() : await getArtifactsPathForComponent(context, ["__build_info.json"]); const exclude = context.type === "workspace" ? (await Promise.all(context.components.map(c => getAllArtifactExcludePathsForComponent(c)))).flat() : await getAllArtifactExcludePathsForComponent(context); return { paths: uniqueAndAlphabeticalSort(paths), ...(exclude.length > 0 ? { exclude: uniqueAndAlphabeticalSort(exclude) } : {}), expire_in: "1 day", when: "always", reports: // TODO: support for junit reports in other builds context.type === "component" && (0, types_1.componentContextIsStandaloneBuild)(context) ? { junit: (_b = (_a = context.build.config.artifactsReports) === null || _a === void 0 ? void 0 : _a.junit) === null || _b === void 0 ? void 0 : _b.map(p => (0, path_1.join)(context.build.dir, p)) } : {} }; }; exports.createBuildJobArtifacts = createBuildJobArtifacts; const _getArtifactPathsForComponent = async (c, configKey, additionalPaths) => { var _a, _b; // in theory, we only need "direct", // but in some cases project may have packages in the workspace that create build artifacts, which aren't components // this highly depends on the build tool. To be safe, we get all const componentDirs = await c.build.getComponentDirs("all"); return (_b = [...(c.build.type !== "disabled" ? (_a = c.build.config[configKey]) !== null && _a !== void 0 ? _a : [] : []), ...(additionalPaths !== null && additionalPaths !== void 0 ? additionalPaths : [])]) === null || _b === void 0 ? void 0 : _b.flatMap(artifact => componentDirs.flatMap(cDir => (0, path_1.join)(cDir, artifact))); }; const getArtifactsPathForComponent = (c, additionalPaths) => { return _getArtifactPathsForComponent(c, "artifactsPaths", additionalPaths); }; const getAllArtifactExcludePathsForComponent = async c => { return [...getDotEnvPathsForComponent(c), // always exclude .env files ...(await getArtifactExcludePathsForComponent(c))]; }; const getArtifactExcludePathsForComponent = (c, additionalPaths) => { return _getArtifactPathsForComponent(c, "artifactsExcludePaths", additionalPaths); }; const getDotEnvPathsForComponent = c => { if ((0, writeDotEnv_1.componentContextNeedsBuildTimeDotEnv)(c)) { return [(0, path_1.join)(c.build.dir, ".env")]; } return []; };