@cortexql/core
Version:
A RESTful API framework for your apps based on GraphQL type system.
83 lines • 3 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const appRootDir = require("app-root-dir");
const build_yargs_1 = require("./build.yargs");
const paths_1 = require("../../paths");
const chokidar = require("chokidar");
const child_process_1 = require("child_process");
const notify_1 = require("../utils/notify");
exports.default = (argv) => __awaiter(this, void 0, void 0, function* () {
let restarted = false;
let hasExited = false;
let hadError = false;
function getExecutable() {
let restartEnv = '';
if (restarted) {
restartEnv = ' SERVER_RESTART=true';
}
return `cross-env NODE_ENV=development CORTEXQL_COMMAND=develop${restartEnv} node -r ts-node/register -r tsconfig-paths/register ${paths_1.getRootPath()}`;
}
let child;
function restart() {
child = child_process_1.spawn(getExecutable(), [], {
shell: true,
detached: true,
cwd: appRootDir.get(),
stdio: 'inherit',
});
child.once('exit', (code, signal) => {
if (code > 0) {
notify_1.notify('✖️ An error has occured, check the terminal');
}
else {
notify_1.notify('✖️ Server has stopped on its own');
}
hasExited = true;
hadError = false;
});
}
const watcher = chokidar.watch('./**/*.ts', {
cwd: appRootDir.get(),
ignored: ['node_modules'],
}).on('change', () => {
hadError = false;
restarted = true;
console.log('\nRestarting...\n');
if (!hasExited) {
hasExited = false;
process.kill(-child.pid, 'SIGKILL');
}
child.removeAllListeners();
try {
child.kill('SIGKILL');
}
catch (error) { }
restart();
});
restart();
function destroy() {
if (child !== undefined && !hasExited) {
process.kill(-child.pid, 'SIGKILL');
}
process.exit(0);
}
process.on('SIGINT', destroy);
process.on('SIGTERM', destroy);
process.on('SIGUSR2', destroy);
process.on('exit', destroy);
});
if (!module.parent) {
build_yargs_1.handler(build_yargs_1.builder().argv)
.catch(err => {
console.log(err.stack);
});
}
//# sourceMappingURL=develop.js.map