UNPKG

alapa

Version:

A cutting-edge web development framework designed to revolutionize the way developers build modern web applications.

54 lines (53 loc) 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateMigrations = generateMigrations; const node_child_process_1 = require("node:child_process"); const utils_1 = require("../../utils"); function generateMigrations() { // Start the process const cmd = (0, node_child_process_1.spawn)("npx", [ "typeorm-ts-node-commonjs", "migration:generate", "-d", "migration-runner/data-source.ts", "migrations/migration", ]); // Handle stdout data cmd.stdout.on("data", (data) => { utils_1.Logger.info(`stdout: ${data}`); }); // Handle stderr data (error case) cmd.stderr.on("data", (data) => { utils_1.Logger.error(`stderr: ${data}`); }); // Handle the close event when the process terminates cmd.on("close", (code) => { if (code === 0) { utils_1.Logger.success(`Migration executed successfully with exit code ${code}`); } else { utils_1.Logger.error(`Error executing migration. Process exited with code ${code}`); // Optionally, throw an error or handle the exit condition based on your application needs } }); // Handle any process errors cmd.on("error", (err) => { utils_1.Logger.error(`Failed to start process: ${err.message}`); // Handle error: You can throw, return, or gracefully handle the error }); // Optional: Handle a timeout (e.g., if the process runs too long) const timeout = setTimeout(() => { utils_1.Logger.error("Migration process timed out"); cmd.kill(); // Kill the child process if it exceeds the timeout }, 30000); // 30 seconds timeout (adjust as needed) // Clear the timeout when the process completes successfully or if it's closed for any reason cmd.on("close", () => { clearTimeout(timeout); }); // Optional: Handle SIGINT (Ctrl+C) or other terminations process.on("SIGINT", () => { utils_1.Logger.log("Process interrupted. Killing the migration process..."); cmd.kill(); // Kill the child process on interruption process.exit(1); // Exit the current process with failure status }); }