UNPKG

@launchql/core

Version:

LaunchQL Package and Migration Tools

58 lines (57 loc) 1.93 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNow = getNow; exports.generatePlan = generatePlan; exports.writePlan = writePlan; const fs_1 = __importDefault(require("fs")); /** * Get a UTC timestamp string */ function getUTCTimestamp(d = new Date()) { return (d.getUTCFullYear() + '-' + String(d.getUTCMonth() + 1).padStart(2, '0') + '-' + String(d.getUTCDate()).padStart(2, '0') + 'T' + String(d.getUTCHours()).padStart(2, '0') + ':' + String(d.getUTCMinutes()).padStart(2, '0') + ':' + String(d.getUTCSeconds()).padStart(2, '0') + 'Z'); } /** * Get a timestamp for the plan file */ function getNow() { return process.env.NODE_ENV === 'test' ? getUTCTimestamp(new Date('2017-08-11T08:11:51Z')) : getUTCTimestamp(new Date()); } /** * Generate a plan file content from structured data */ function generatePlan(options) { const { moduleName, uri, entries } = options; const now = getNow(); const planfile = [ `%syntax-version=1.0.0`, `%project=${moduleName}`, `%uri=${uri || moduleName}` ]; // Generate the plan entries entries.forEach(entry => { if (entry.dependencies && entry.dependencies.length > 0) { planfile.push(`${entry.change} [${entry.dependencies.join(' ')}] ${now} launchql <launchql@5b0c196eeb62>${entry.comment ? ` # ${entry.comment}` : ''}`); } else { planfile.push(`${entry.change} ${now} launchql <launchql@5b0c196eeb62>${entry.comment ? ` # ${entry.comment}` : ''}`); } }); return planfile.join('\n'); } /** * Write a generated plan file to disk */ function writePlan(planPath, plan) { fs_1.default.writeFileSync(planPath, plan); }