-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprepare.dist.js
37 lines (30 loc) · 1.33 KB
/
prepare.dist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { readdir, stat, readFile, writeFile } from "fs/promises";
import { fileURLToPath } from "url";
import { join, dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const searchPath = join(__dirname, "dist");
async function replaceTextInFiles(searchString, replaceString, directory) {
try {
const files = await readdir(directory);
for (const file of files) {
const filePath = join(directory, file);
const stats = await stat(filePath);
if (stats.isDirectory()) {
await replaceTextInFiles(searchString, replaceString, filePath); // Recursively search subdirectories
} else if (stats.isFile() && file.endsWith(".js")) {
let data = await readFile(filePath, "utf8");
if (data.includes(searchString)) {
data = data.replace(new RegExp(searchString, "g"), replaceString);
await writeFile(filePath, data, "utf8");
console.log(`Updated file: ${filePath}`);
}
}
}
} catch (err) {
console.error("Error:", err);
}
}
// Replace related paths to vueless.config.js and web-types.json in npm package source.
await replaceTextInFiles(`"../../vueless.config.js"`, `"../../../vueless.config.js"`, searchPath);
await replaceTextInFiles(`"../../web-types.json"`, `"../web-types.json"`, searchPath);