UNPKG

@launchql/cli

Version:
91 lines (90 loc) 3.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const types_1 = require("@launchql/types"); const core_1 = require("@launchql/core"); const server_utils_1 = require("@launchql/server-utils"); const child_process_1 = require("child_process"); const core_2 = require("@launchql/core"); exports.default = async (argv, prompter, _options) => { const pgEnv = (0, types_1.getPgEnvOptions)(); const log = new server_utils_1.Logger('cli'); const questions = [ { type: 'text', name: 'database', message: 'Database name', required: true }, { name: 'yes', type: 'confirm', message: 'Are you sure you want to proceed?', required: true } ]; let { database, yes, recursive, createdb, cwd } = await prompter.prompt(argv, questions); if (!yes) { log.info('Operation cancelled.'); return; } cwd = cwd || process.cwd(); log.debug(`Using current directory: ${cwd}`); const project = new core_2.LaunchQLProject(cwd); if (createdb) { log.info(`Creating database ${database}...`); (0, child_process_1.execSync)(`createdb ${database}`, { env: (0, types_1.getSpawnEnvWithPg)(pgEnv) }); } const options = (0, types_1.getEnvOptions)({ pg: { database } }); if (recursive) { const modules = await project.getModules(); const moduleNames = modules.map(mod => mod.getModuleName()); if (!moduleNames.length) { log.error('No modules found in the specified directory.'); prompter.close(); throw types_1.errors.NOT_FOUND({}, 'No modules found in the specified directory.'); } const { project: selectedProject } = await prompter.prompt(argv, [ { type: 'autocomplete', name: 'project', message: 'Choose a project to deploy', options: moduleNames, required: true } ]); const selected = modules.find(mod => mod.getModuleName() === selectedProject); if (!selected) { throw new Error(`Module ${selectedProject} not found`); } const dir = selected.getModulePath(); log.success(`Deploying project ${selectedProject} from ${dir} to database ${database}...`); if (argv.fast) { await (0, core_1.deployFast)({ opts: options, database, dir, name: selectedProject, usePlan: true, cache: false }); } else { await (0, core_1.deploy)(options, selectedProject, database, dir); } log.success('Deployment complete.'); } else { log.info(`Running: sqitch deploy db:pg:${database}`); (0, child_process_1.execSync)(`sqitch deploy db:pg:${database}`, { env: (0, types_1.getSpawnEnvWithPg)(pgEnv) }); log.success('Deployment complete.'); } return argv; };