@starship-ci/generator
Version:
Kubernetes manifest generator for Starship deployments
103 lines (102 loc) • 3.79 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ScriptManager = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
class ScriptManager {
packageRoot;
configDir;
constructor(packageRoot, configDir) {
// Default to the generator package root (where scripts/ directory is located)
// __dirname is src/, so we go up one level to get to the package root
this.packageRoot = packageRoot || path.resolve(__dirname, '..');
this.configDir = configDir;
}
/**
* Load a script from the filesystem
*/
loadScript(scriptPath) {
let fullScriptPath;
// Try config-relative path first (for test configs and custom scripts)
if (this.configDir) {
fullScriptPath = path.resolve(this.configDir, scriptPath);
if (fs.existsSync(fullScriptPath)) {
return fs.readFileSync(fullScriptPath, 'utf8');
}
}
// Fall back to package root relative path (for default scripts)
fullScriptPath = path.resolve(this.packageRoot, scriptPath);
if (!fs.existsSync(fullScriptPath)) {
const searchPaths = [
this.configDir ? path.resolve(this.configDir, scriptPath) : null,
path.resolve(this.packageRoot, scriptPath)
].filter(Boolean);
throw new Error(`Script not found: ${scriptPath}. Searched in: ${searchPaths.join(', ')}`);
}
return fs.readFileSync(fullScriptPath, 'utf8');
}
/**
* Get script content based on Script config
*/
getScriptContent(scriptConfig) {
if (scriptConfig.data) {
// Use inline script data
return scriptConfig.data;
}
if (scriptConfig.file) {
// Load from file
return this.loadScript(scriptConfig.file);
}
throw new Error('Script must have either file or data property');
}
/**
* Get all available script files
*/
getAvailableScripts() {
const scriptsDir = path.join(this.packageRoot, 'scripts');
if (!fs.existsSync(scriptsDir)) {
return [];
}
return fs
.readdirSync(scriptsDir)
.filter((file) => file.endsWith('.sh'))
.sort();
}
/**
* Check if a script file exists
*/
scriptExists(scriptPath) {
const fullScriptPath = path.resolve(this.packageRoot, scriptPath);
return fs.existsSync(fullScriptPath);
}
/**
* Get the full path to a script
*/
getScriptPath(scriptPath) {
return path.resolve(this.packageRoot, scriptPath);
}
}
exports.ScriptManager = ScriptManager;