prev-cli 0.14.0 → 0.14.1
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 +50 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// src/cli.ts
|
|
4
4
|
import { parseArgs } from "util";
|
|
5
5
|
import path7 from "path";
|
|
6
|
-
import { existsSync as existsSync5, mkdirSync as mkdirSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
6
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync2, writeFileSync as writeFileSync3, rmSync as rmSync2, readFileSync as readFileSync4 } from "fs";
|
|
7
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
7
8
|
|
|
8
9
|
// src/vite/start.ts
|
|
9
10
|
import { createServer as createServer2, build as build2, preview } from "vite";
|
|
@@ -960,6 +961,21 @@ async function previewSite(rootDir, options = {}) {
|
|
|
960
961
|
}
|
|
961
962
|
|
|
962
963
|
// src/cli.ts
|
|
964
|
+
function getVersion() {
|
|
965
|
+
try {
|
|
966
|
+
let dir = path7.dirname(fileURLToPath3(import.meta.url));
|
|
967
|
+
for (let i = 0;i < 5; i++) {
|
|
968
|
+
const pkgPath = path7.join(dir, "package.json");
|
|
969
|
+
if (existsSync5(pkgPath)) {
|
|
970
|
+
const pkg = JSON.parse(readFileSync4(pkgPath, "utf-8"));
|
|
971
|
+
if (pkg.name === "prev-cli")
|
|
972
|
+
return pkg.version;
|
|
973
|
+
}
|
|
974
|
+
dir = path7.dirname(dir);
|
|
975
|
+
}
|
|
976
|
+
} catch {}
|
|
977
|
+
return "unknown";
|
|
978
|
+
}
|
|
963
979
|
var { values, positionals } = parseArgs({
|
|
964
980
|
args: process.argv.slice(2),
|
|
965
981
|
options: {
|
|
@@ -967,7 +983,8 @@ var { values, positionals } = parseArgs({
|
|
|
967
983
|
days: { type: "string", short: "d" },
|
|
968
984
|
cwd: { type: "string", short: "c" },
|
|
969
985
|
include: { type: "string", short: "i", multiple: true },
|
|
970
|
-
help: { type: "boolean", short: "h" }
|
|
986
|
+
help: { type: "boolean", short: "h" },
|
|
987
|
+
version: { type: "boolean", short: "v" }
|
|
971
988
|
},
|
|
972
989
|
allowPositionals: true
|
|
973
990
|
});
|
|
@@ -982,7 +999,8 @@ Usage:
|
|
|
982
999
|
prev build [options] Build for production
|
|
983
1000
|
prev preview [options] Preview production build
|
|
984
1001
|
prev create [name] Create preview in previews/<name>/ (default: "example")
|
|
985
|
-
prev
|
|
1002
|
+
prev clearcache Clear Vite cache (.vite directory)
|
|
1003
|
+
prev clean [options] Remove old prev-cli caches
|
|
986
1004
|
|
|
987
1005
|
Options:
|
|
988
1006
|
-c, --cwd <path> Set working directory
|
|
@@ -990,6 +1008,7 @@ Options:
|
|
|
990
1008
|
-i, --include <dir> Include dot-prefixed directory (can use multiple times)
|
|
991
1009
|
-d, --days <days> Cache age threshold for clean (default: 30)
|
|
992
1010
|
-h, --help Show this help message
|
|
1011
|
+
-v, --version Show version number
|
|
993
1012
|
|
|
994
1013
|
Previews:
|
|
995
1014
|
Previews must be in the previews/ directory at your project root.
|
|
@@ -1033,6 +1052,27 @@ Examples:
|
|
|
1033
1052
|
prev clean -d 7 Remove caches older than 7 days
|
|
1034
1053
|
`);
|
|
1035
1054
|
}
|
|
1055
|
+
function clearViteCache(rootDir2) {
|
|
1056
|
+
const viteCacheDir = path7.join(rootDir2, ".vite");
|
|
1057
|
+
const nodeModulesVite = path7.join(rootDir2, "node_modules", ".vite");
|
|
1058
|
+
let cleared = 0;
|
|
1059
|
+
if (existsSync5(viteCacheDir)) {
|
|
1060
|
+
rmSync2(viteCacheDir, { recursive: true });
|
|
1061
|
+
cleared++;
|
|
1062
|
+
console.log(` ✓ Removed .vite/`);
|
|
1063
|
+
}
|
|
1064
|
+
if (existsSync5(nodeModulesVite)) {
|
|
1065
|
+
rmSync2(nodeModulesVite, { recursive: true });
|
|
1066
|
+
cleared++;
|
|
1067
|
+
console.log(` ✓ Removed node_modules/.vite/`);
|
|
1068
|
+
}
|
|
1069
|
+
if (cleared === 0) {
|
|
1070
|
+
console.log(" No Vite cache found");
|
|
1071
|
+
} else {
|
|
1072
|
+
console.log(`
|
|
1073
|
+
Cleared ${cleared} cache director${cleared === 1 ? "y" : "ies"}`);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1036
1076
|
function createPreview(rootDir2, name) {
|
|
1037
1077
|
const previewDir = path7.join(rootDir2, "previews", name);
|
|
1038
1078
|
if (existsSync5(previewDir)) {
|
|
@@ -1178,6 +1218,10 @@ export default function App() {
|
|
|
1178
1218
|
`);
|
|
1179
1219
|
}
|
|
1180
1220
|
async function main() {
|
|
1221
|
+
if (values.version) {
|
|
1222
|
+
console.log(`prev-cli v${getVersion()}`);
|
|
1223
|
+
process.exit(0);
|
|
1224
|
+
}
|
|
1181
1225
|
if (values.help) {
|
|
1182
1226
|
printHelp();
|
|
1183
1227
|
process.exit(0);
|
|
@@ -1204,6 +1248,9 @@ async function main() {
|
|
|
1204
1248
|
const previewName = positionals[1] || "example";
|
|
1205
1249
|
createPreview(rootDir, previewName);
|
|
1206
1250
|
break;
|
|
1251
|
+
case "clearcache":
|
|
1252
|
+
clearViteCache(rootDir);
|
|
1253
|
+
break;
|
|
1207
1254
|
default:
|
|
1208
1255
|
console.error(`Unknown command: ${command}`);
|
|
1209
1256
|
printHelp();
|