mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Fix @__PURE__ replacement not matching multiple times
Also handle subfolders
This commit is contained in:
parent
0d7c34dace
commit
17051c2b81
1 changed files with 36 additions and 22 deletions
|
@ -4,21 +4,35 @@
|
|||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
function allFilesInDir(directory): string[] {
|
||||
let results: string[] = [];
|
||||
const list = fs.readdirSync(directory);
|
||||
|
||||
list.forEach(function(file) {
|
||||
file = path.join(directory, file);
|
||||
const stat = fs.statSync(file);
|
||||
|
||||
if (stat && stat.isDirectory()) {
|
||||
results = results.concat(allFilesInDir(file));
|
||||
} else {
|
||||
results.push(file);
|
||||
}
|
||||
});
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
function adjustFiles() {
|
||||
const root = process.argv[2];
|
||||
const typeRe = /(make(Enum|MessageType))\(\n\s+".*",/g;
|
||||
|
||||
fs.readdirSync(root, { withFileTypes: true }).forEach(dirEnt => {
|
||||
const dirPath = path.join(root, dirEnt.name);
|
||||
|
||||
if (dirEnt.isDirectory()) {
|
||||
fs.readdirSync(dirPath).forEach(fileName => {
|
||||
if (fileName.endsWith(".js")) {
|
||||
const file = path.join(dirPath, fileName);
|
||||
let jsFiles = allFilesInDir(root).filter(f => f.endsWith(".js"));
|
||||
for (const file of jsFiles) {
|
||||
let contents = fs.readFileSync(file, "utf8");
|
||||
|
||||
// allow tree shaking on proto messages
|
||||
contents = contents.replace(
|
||||
"= proto3.make",
|
||||
/= proto3.make/g,
|
||||
"= /* @__PURE__ */ proto3.make",
|
||||
);
|
||||
|
||||
|
@ -29,6 +43,6 @@ fs.readdirSync(root, { withFileTypes: true }).forEach(dirEnt => {
|
|||
|
||||
fs.writeFileSync(file, contents, "utf8");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
adjustFiles();
|
||||
|
|
Loading…
Reference in a new issue