nomi-san / balance-buff-viewer

ARAM/URF balance buff viewer plugin for Pengu Loader
MIT License
23 stars 4 forks source link

[BUG] Node throws `ENOENT` when run `cnpm crawl` #1

Closed BakaFT closed 1 year ago

BakaFT commented 1 year ago
PS E:\Repos\balance-buff-viewer> pnpm crawl

> balance-buff-viewer-plugin@13.13.2 crawl E:\Repos\balance-buff-viewer
> sucrase-node src/crawl.ts

Failed to parse fandom data. [Error: ENOENT: no such file or directory, open 'E:\Repos\balance-buff-viewer\dist\balance.json'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'E:\\Repos\\balance-buff-viewer\\dist\\balance.json'
}
 ELIFECYCLE  Command failed with exit code 1.

🤔Of course there is no dist folder before build

simple orkaround, :

diff --git a/src/crawl.ts b/src/crawl.ts
index 33ba535..0da0aef 100644
--- a/src/crawl.ts
+++ b/src/crawl.ts
@@ -107,7 +107,18 @@ async function main() {
   const data = buildBalanceBuffData(script);

   const json = JSON.stringify(data);
-  const outpath = path.join(process.cwd(), 'dist/balance.json');
+  const outdir = path.join(process.cwd(), 'dist');
+  const outpath = path.join(outdir, 'balance.json');
+
+  try {
+    await fs.mkdir(outdir);
+  } catch (err: any) {
+    if (err instanceof NodeJS.ErrnoException){
+      if (err.code !== 'EEXIST') {
+        throw err;
+      }
+    }
+  }

   await fs.writeFile(outpath, json);
 }