dumi
Version:
📖 Documentation Generator of React Component
80 lines (79 loc) • 2.74 kB
JavaScript
// src/service/forkedDev.ts
var import_node = require("@umijs/utils/dist/node");
var import_plugin_utils = require("umi/plugin-utils");
var import_constants = require("./constants");
var import_service = require("./service");
(0, import_node.setNodeTitle)(`${import_constants.FRAMEWORK_NAME}-dev`);
(0, import_plugin_utils.setNoDeprecation)();
(async () => {
let closed = false;
try {
let onSignal = function(signal) {
receivedSignal = true;
void shutdown(signal);
};
const args = (0, import_plugin_utils.yParser)(process.argv.slice(2));
const service = new import_service.DumiService();
let startup;
let receivedSignal = false;
const signalHandlers = {};
async function shutdown(signal) {
if (closed)
return;
closed = true;
const timeout = setTimeout(() => process.exit(1), 5e3);
timeout.unref();
try {
await startup.catch((error) => {
import_plugin_utils.logger.fatal(error);
process.exitCode = 1;
});
const cleanup = receivedSignal ? [] : process.rawListeners(signal).filter((listener) => listener !== signalHandlers[signal]).map(async (listener) => listener.call(process, signal));
cleanup.push(
Promise.resolve().then(
() => service.applyPlugins({ key: "onExit", args: { signal } })
)
);
for (const result of await Promise.allSettled(cleanup)) {
if (result.status === "rejected") {
import_plugin_utils.logger.fatal(result.reason);
process.exitCode = 1;
}
}
process.exit(process.exitCode || 0);
} finally {
clearTimeout(timeout);
}
}
for (const signal of ["SIGINT", "SIGQUIT", "SIGTERM"]) {
const handler = onSignal.bind(null, signal);
signalHandlers[signal] = handler;
process.on(signal, handler);
}
process.on(
"message",
(message) => {
var _a;
if ((message == null ? void 0 : message.type) === "SHUTDOWN") {
const signal = (_a = message.payload) == null ? void 0 : _a.signal;
void shutdown(
signal === "SIGINT" || signal === "SIGQUIT" ? signal : "SIGTERM"
);
}
}
);
process.once("disconnect", () => void shutdown("SIGTERM"));
const { channel } = process;
channel == null ? void 0 : channel.unref();
startup = service.run2({ name: import_constants.DEV_COMMAND, args });
if (process.connected === false)
void shutdown("SIGTERM");
await startup;
} catch (error) {
if (closed)
return;
import_plugin_utils.logger.fatal(error);
import_plugin_utils.printHelp.exit();
process.exit(1);
}
})();