prev-cli 0.24.1 → 0.24.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +55 -8
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -882,12 +882,21 @@ async function createViteConfig(options) {
|
|
|
882
882
|
base: base || "/",
|
|
883
883
|
customLogger: createFriendlyLogger(),
|
|
884
884
|
logLevel: mode === "production" ? "silent" : "info",
|
|
885
|
+
envDir: cliRoot2,
|
|
886
|
+
envPrefix: "PREV_",
|
|
885
887
|
plugins: [
|
|
886
888
|
mdx({
|
|
887
889
|
remarkPlugins: [remarkGfm],
|
|
888
890
|
rehypePlugins: [rehypeHighlight],
|
|
889
891
|
providerImportSource: "@mdx-js/react",
|
|
890
|
-
|
|
892
|
+
include: [
|
|
893
|
+
path8.join(rootDir, "**/*.md"),
|
|
894
|
+
path8.join(rootDir, "**/*.mdx")
|
|
895
|
+
],
|
|
896
|
+
exclude: [
|
|
897
|
+
"**/node_modules/**",
|
|
898
|
+
"**/.git/**"
|
|
899
|
+
]
|
|
891
900
|
}),
|
|
892
901
|
react(),
|
|
893
902
|
createConfigPlugin(config),
|
|
@@ -1088,7 +1097,11 @@ async function createViteConfig(options) {
|
|
|
1088
1097
|
main: path8.join(srcRoot2, "theme/index.html")
|
|
1089
1098
|
}
|
|
1090
1099
|
}
|
|
1091
|
-
}
|
|
1100
|
+
},
|
|
1101
|
+
assetsInclude: [
|
|
1102
|
+
"**/node_modules/**/*.md",
|
|
1103
|
+
"**/node_modules/**/*.mdx"
|
|
1104
|
+
]
|
|
1092
1105
|
};
|
|
1093
1106
|
}
|
|
1094
1107
|
|
|
@@ -1178,11 +1191,11 @@ function clearCache(rootDir) {
|
|
|
1178
1191
|
}
|
|
1179
1192
|
function setupKeyboardShortcuts(rootDir, url, quit) {
|
|
1180
1193
|
if (!process.stdin.isTTY)
|
|
1181
|
-
return;
|
|
1194
|
+
return () => {};
|
|
1182
1195
|
process.stdin.setRawMode(true);
|
|
1183
1196
|
process.stdin.resume();
|
|
1184
1197
|
process.stdin.setEncoding("utf8");
|
|
1185
|
-
|
|
1198
|
+
const handler = (key) => {
|
|
1186
1199
|
switch (key.toLowerCase()) {
|
|
1187
1200
|
case "o":
|
|
1188
1201
|
openBrowser(url);
|
|
@@ -1198,7 +1211,15 @@ function setupKeyboardShortcuts(rootDir, url, quit) {
|
|
|
1198
1211
|
quit();
|
|
1199
1212
|
break;
|
|
1200
1213
|
}
|
|
1201
|
-
}
|
|
1214
|
+
};
|
|
1215
|
+
process.stdin.on("data", handler);
|
|
1216
|
+
return () => {
|
|
1217
|
+
process.stdin.off("data", handler);
|
|
1218
|
+
if (process.stdin.isTTY) {
|
|
1219
|
+
process.stdin.setRawMode(false);
|
|
1220
|
+
}
|
|
1221
|
+
process.stdin.pause();
|
|
1222
|
+
};
|
|
1202
1223
|
}
|
|
1203
1224
|
async function startDev(rootDir, options = {}) {
|
|
1204
1225
|
const port = options.port ?? await getRandomPort();
|
|
@@ -1215,11 +1236,37 @@ async function startDev(rootDir, options = {}) {
|
|
|
1215
1236
|
printWelcome("dev");
|
|
1216
1237
|
server.printUrls();
|
|
1217
1238
|
printReady();
|
|
1218
|
-
|
|
1219
|
-
|
|
1239
|
+
let isShuttingDown = false;
|
|
1240
|
+
let cleanupStdin = () => {};
|
|
1241
|
+
const shutdown = async (signal) => {
|
|
1242
|
+
if (isShuttingDown)
|
|
1243
|
+
return;
|
|
1244
|
+
isShuttingDown = true;
|
|
1245
|
+
if (signal) {
|
|
1246
|
+
console.log(`
|
|
1247
|
+
Received ${signal}, shutting down...`);
|
|
1248
|
+
} else {
|
|
1249
|
+
console.log(`
|
|
1220
1250
|
Shutting down...`);
|
|
1221
|
-
|
|
1251
|
+
}
|
|
1252
|
+
cleanupStdin();
|
|
1253
|
+
const closePromise = server.close();
|
|
1254
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
1255
|
+
setTimeout(() => {
|
|
1256
|
+
console.log(" Force closing (timeout)...");
|
|
1257
|
+
resolve();
|
|
1258
|
+
}, 3000);
|
|
1259
|
+
});
|
|
1260
|
+
await Promise.race([closePromise, timeoutPromise]);
|
|
1222
1261
|
process.exit(0);
|
|
1262
|
+
};
|
|
1263
|
+
cleanupStdin = setupKeyboardShortcuts(rootDir, url, () => shutdown());
|
|
1264
|
+
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
1265
|
+
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
1266
|
+
process.on("uncaughtException", (err) => {
|
|
1267
|
+
console.error(`
|
|
1268
|
+
Uncaught exception:`, err.message);
|
|
1269
|
+
shutdown("uncaughtException");
|
|
1223
1270
|
});
|
|
1224
1271
|
return server;
|
|
1225
1272
|
}
|