UNPKG

limgen

Version:

Infrastructure as Code generator

90 lines (89 loc) 3.7 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ensureDeployCommand = exports.copyScripts = exports.collectInput = exports.inputs = exports.dependsOn = void 0; const files_1 = require("../../files"); const promises_1 = __importDefault(require("fs/promises")); const path_1 = __importDefault(require("path")); const zod_1 = require("zod"); const ejs_1 = __importDefault(require("ejs")); const dependsOn = () => { const files = [ 'components/storage-s3.ts', 'components/cdn-cloudfront.ts', 'utils/deep-merge.ts', 'utils/prefixed.ts', ]; const packages = [ '@pulumi/aws', '@pulumi/awsx', '@pulumi/pulumi', 'zod', ]; return { files, packages, }; }; exports.dependsOn = dependsOn; const inputs = () => __awaiter(void 0, void 0, void 0, function* () { return [ { name: 'outputDir', message: 'Build output directory', schema: zod_1.z.string().default('out'), } ]; }); exports.inputs = inputs; const collectInput = (cmdArgs, projectArgs) => __awaiter(void 0, void 0, void 0, function* () { let outputDir = projectArgs.outputDir; if (!outputDir || outputDir === 'unknown') { outputDir = 'out'; } return { outputDir, }; }); exports.collectInput = collectInput; function staticSiteAws(input) { return __awaiter(this, void 0, void 0, function* () { const [pulumiIndex] = yield Promise.all([ promises_1.default.readFile(path_1.default.join(__dirname, 'index.ts'), 'utf-8'), (0, exports.copyScripts)(input), (0, exports.ensureDeployCommand)(), ]); return pulumiIndex; }); } exports.default = staticSiteAws; const copyScripts = (input) => __awaiter(void 0, void 0, void 0, function* () { const scriptsPath = path_1.default.join('infrastructure', 'scripts'); yield (0, files_1.mkdirp)(scriptsPath); const result = yield ejs_1.default.renderFile(path_1.default.join(__dirname, 'scripts', 'deploy.sh.ejs.t'), input); yield promises_1.default.writeFile(path_1.default.join(scriptsPath, 'deploy.sh'), result); }); exports.copyScripts = copyScripts; const ensureDeployCommand = () => __awaiter(void 0, void 0, void 0, function* () { if (!(yield (0, files_1.fileExists)('package.json'))) { return; // we only support creating commands in package.json right now } const packageJSON = JSON.parse(yield promises_1.default.readFile('package.json', 'utf-8')); if (!packageJSON.scripts) { packageJSON.scripts = {}; } packageJSON.scripts['deploy-site'] = 'bash infrastructure/scripts/deploy.sh'; yield promises_1.default.writeFile('package.json', JSON.stringify(packageJSON, null, 2)); }); exports.ensureDeployCommand = ensureDeployCommand;