@catladder/cli
Version:
Panter cli tool for cloud CI/CD and DevOps
111 lines • 4.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createComponentContext = void 0;
const lodash_1 = require("lodash");
const build_1 = require("../build");
const deploy_1 = require("../deploy");
const packageManager_1 = require("../pipeline/packageManager");
const utils_1 = require("../utils");
const getEnvironment_1 = require("./getEnvironment");
const getEnvironmentContext_1 = require("./getEnvironmentContext");
const createComponentContext = async (ctx) => {
var _a;
if (!/^[a-z0-9-]+$/.test(ctx.componentName)) {
throw new Error("componentName may only contain lower case letters, numbers and -");
}
const packageManagerInfo = await (0, packageManager_1.getPackageManagerInfoForComponent)(ctx.config, ctx.componentName);
const envContext = (0, getEnvironmentContext_1.getEnvironmentContext)(ctx);
const componentConfigWithoutDefaults = envContext.envConfigRaw;
const resolvedBuildType = componentConfigWithoutDefaults.build === false
? false
: (0, build_1.isStandaloneBuildConfig)(componentConfigWithoutDefaults.build)
? componentConfigWithoutDefaults.build.type
: (_a = ctx.config.builds) === null || _a === void 0 ? void 0 : _a[componentConfigWithoutDefaults.build.from].type;
if (resolvedBuildType === undefined) {
throw new Error("build type not found, is the build config correct?");
}
const defaults = componentConfigWithoutDefaults.deploy
? {
build: resolvedBuildType &&
build_1.BUILD_TYPES[resolvedBuildType].defaults(envContext),
deploy: deploy_1.DEPLOY_TYPES[componentConfigWithoutDefaults.deploy.type].defaults(envContext),
}
: {
build: resolvedBuildType &&
build_1.BUILD_TYPES[resolvedBuildType].defaults(envContext),
deploy: {},
};
const componentConfig = (0, utils_1.mergeWithMergingArrays)(defaults, componentConfigWithoutDefaults);
const environment = await (0, getEnvironment_1.getEnvironment)(ctx);
const { deploy, build, customJobs, dir } = componentConfig;
const getComponentDirs = (mode) => {
var _a;
return [
dir,
// also copy workspace dependencies in monorepo if packages are shared and they create build artifacts
...(mode === "all"
? ((_a = packageManagerInfo.currentWorkspaceDependencies) !== null && _a !== void 0 ? _a : [])
: []),
];
};
const _getBuildContext = () => {
var _a;
if (build === false) {
return {
type: "disabled",
getComponentDirs,
dir,
};
}
if ((0, build_1.isStandaloneBuildConfig)(build)) {
return {
dir: dir,
getComponentDirs,
config: build,
buildType: build.type,
type: "standalone",
};
}
// must be shared build
const referencedBuild = (_a = ctx.config.builds) === null || _a === void 0 ? void 0 : _a[build.from];
if (!referencedBuild) {
throw new Error("build.from not found in config");
}
return {
dir: dir,
getComponentDirs,
config: build,
workspaceBuildConfig: referencedBuild,
workspaceName: build.from,
buildType: referencedBuild.type,
type: "fromWorkspace",
};
};
const buildContext = _getBuildContext();
const context = {
type: "component",
name: ctx.componentName,
env: ctx.env,
fullConfig: ctx.config,
componentConfig,
build: buildContext,
deploy: deploy
? {
config: deploy,
}
: null,
environment,
packageManagerInfo: packageManagerInfo,
pipelineType: ctx.pipelineType,
trigger: ctx.trigger,
};
const resolvedCustomJobs = (0, lodash_1.isFunction)(customJobs)
? customJobs(context)
: customJobs;
return {
...context,
customJobs: resolvedCustomJobs,
};
};
exports.createComponentContext = createComponentContext;
//# sourceMappingURL=createComponentContext.js.map