@lynx-js/rspeedy
Version:
A webpack/rspack-based frontend toolchain for Lynx
31 lines (30 loc) • 1.67 kB
JavaScript
import { __webpack_require__ } from "./src_cli_main_ts-node_child_process-node_events-node_fs-node_path-node_process.js";
import node_path from "node:path";
import { logger } from "@rsbuild/core";
import { exit as exit_exit } from "./src_cli_main_ts-node_child_process-node_events-node_fs-node_path-node_process.js";
import { createRspeedy, init } from "./1~src_cli_init_ts-src_create-rspeedy_ts.js";
import { watchFiles, getWatchedFiles } from "./1~watch.js";
const picocolors = __webpack_require__("../../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
async function dev(cwd, devOptions) {
let onBeforeRestart = [];
try {
const { rspeedyConfig, configPath, createRspeedyOptions } = await init(cwd, devOptions);
const watchedFiles = getWatchedFiles(configPath, rspeedyConfig);
await watchFiles(watchedFiles.map((filePath)=>node_path.isAbsolute(filePath) ? filePath : node_path.join(cwd, filePath)), async (filename)=>{
logger.info(`Restart because ${picocolors_default().yellow(filename)} is changed.\n`);
const cleanup = onBeforeRestart.map((f)=>f());
onBeforeRestart = [];
await Promise.all(cleanup);
await dev.call(this, cwd, devOptions);
});
const rspeedy = await createRspeedy(createRspeedyOptions);
const server = await rspeedy.createDevServer();
const { server: { close } } = await server.listen();
onBeforeRestart.push(close);
} catch (error) {
logger.error(error);
exit_exit(1);
}
}
export { dev };