UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

59 lines (58 loc) 2.6 kB
"use strict"; var __importDefault = this && this.__importDefault || function (mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createJobCacheFromConfig = exports.createJobCacheFromCacheConfigs = void 0; const path_1 = require("path"); const getAllCacheConfigsFromConfig_1 = require("./getAllCacheConfigsFromConfig"); const slugify_1 = __importDefault(require("slugify")); const createJobCacheFromCacheConfigs = (context, caches) => { if (caches.length === 0) return undefined; const simpleCacheDefs = caches.filter(c => !("key" in c)); const advancedCacheDefs = caches.filter(c => "key" in c); // simple caches are merged together into one. This is because e.g. gitlab has a limit of 4 caches, see https://gitlab.com/gitlab-org/gitlab/-/issues/421962 const simpleCaches = simpleCacheDefs.length > 0 ? [{ key: context.name + "-default", policy: "pull-push", paths: simpleCacheDefs.flatMap(c => c.paths.map(p => { var _a; const baseDir = c.pathMode === "absolute" ? "" : (_a = c.baseDir) !== null && _a !== void 0 ? _a : context.build.dir; return (0, path_1.join)(baseDir, p); })) }] : []; const advancedCaches = advancedCacheDefs.map(({ key, paths, policy, scope, pathMode, buildDir, ...rest }) => { var _a; const baseDir = pathMode === "absolute" ? "" : buildDir !== null && buildDir !== void 0 ? buildDir : context.build.dir; const transformedKey = scope === "global" ? key : typeof key === "string" ? (scope === "buildDir" // really edge case... ? (0, slugify_1.default)(baseDir) : context.name) + "-" + key : { ...key, files: (_a = key.files) === null || _a === void 0 ? void 0 : _a.map(f => pathMode === "absolute" ? f : (0, path_1.join)(baseDir, f)) }; return { key: transformedKey, policy: policy !== null && policy !== void 0 ? policy : "pull-push", paths: pathMode === "absolute" ? paths : paths === null || paths === void 0 ? void 0 : paths.map(p => (0, path_1.join)(baseDir, p)), ...rest }; }); return [...advancedCaches, ...simpleCaches]; }; exports.createJobCacheFromCacheConfigs = createJobCacheFromCacheConfigs; /** shortcut, used in some build types */ const createJobCacheFromConfig = (context, configWithCache) => { return (0, exports.createJobCacheFromCacheConfigs)(context, (0, getAllCacheConfigsFromConfig_1.getAllCacheConfigsFromConfig)(context, configWithCache)); }; exports.createJobCacheFromConfig = createJobCacheFromConfig;