UNPKG

@jin7942/ray

Version:

Lightweight CI/CD deployment tool powered by Docker and Git

100 lines (99 loc) 3.97 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.initConfigWizard = initConfigWizard; /** * Setting wizard */ const promises_1 = __importDefault(require("fs/promises")); const path_1 = __importDefault(require("path")); const readline_1 = __importDefault(require("readline")); const logger_1 = require("../utils/logger"); const inputHelper_1 = require("../utils/inputHelper"); /** * Prompt the user with a question and return their input. * * @param query - The question to ask. * @returns A Promise that resolves to the user's input. */ function ask(query) { const rl = readline_1.default.createInterface({ input: process.stdin, output: process.stdout, }); return new Promise((resolve) => { rl.question(query, (answer) => { rl.close(); resolve(answer.trim()); }); }); } /** * Launches a minimal interactive wizard to generate a RAY config JSON file. * * @param outputPath - File path to write the generated config (default: './ray.config.json') */ async function initConfigWizard(outputPath = './ray.config.json') { logger_1.logger.info('RAY config wizard started (minimal mode)'); const name = await (0, inputHelper_1.askValidated)('Your project name:', (input) => { return input.length > 0 ? null : 'You must enter project name'; }); const repo = await (0, inputHelper_1.askValidated)('GitHub repository URL: ', (input) => { return input.startsWith('https://') ? null : 'The GitHub repository URL is must start with https://'; }); const branch = await (0, inputHelper_1.askValidated)('Branch to deploy (default: main): ', (input) => { return input.length > 0 ? null : ''; }, 'main'); // const buildCommand = await askValidated( // 'Build command (default: npm run build): ', // (input) => { // return input.length > 0 ? null : ''; // }, // 'npm run build' // default value // ); const image = await (0, inputHelper_1.askValidated)('Docker image name: ', (input) => { return input.length > 0 ? null : 'You must enter Docker image name'; }); const containername = await (0, inputHelper_1.askValidated)('Docker container name: ', (input) => { return input.length > 0 ? null : 'You must enter Docker container name'; }); const dockerfilePath = await (0, inputHelper_1.askValidated)('Dockerfile path (default: ./Dockerfile): ', (input) => { return input.length > 0 ? null : ''; }, './Dockerfile'); const logdir = await (0, inputHelper_1.askValidated)('Log directory (default: ./logs): ', (input) => { return input.length > 0 ? null : ''; }, './logs'); const maxLogDirSizeInput = await (0, inputHelper_1.askValidated)('Max log dir size in bytes (default: 5242880): ', (input) => { const num = Number(input); return isNaN(num) || num <= 0 ? 'Must be a positive number' : null; }, '5242880'); const maxLogDirSize = Number(maxLogDirSizeInput); const logLevel = await (0, inputHelper_1.askValidated)('LogLevel: info, warn, error (default : info) ', (input) => { return input.length > 0 ? null : ''; }, 'info'); const config = { name, repo, branch, docker: { type: 'docker', image, containername, path: { dockerfile: dockerfilePath, }, }, internal: { logdir, maxLogDirSize, logLevel, }, }; const fullPath = path_1.default.resolve(outputPath); await promises_1.default.writeFile(fullPath, JSON.stringify(config, null, 2), 'utf-8'); logger_1.logger.info(`Config file created at: ${fullPath}`); }