Sv443 4 недель назад
Родитель
Сommit
caabcdf5dd
2 измененных файлов с 23 добавлено и 17 удалено
  1. 12 6
      eslint.config.mjs
  2. 11 11
      src/tools/post-build.ts

+ 12 - 6
eslint.config.mjs

@@ -53,12 +53,15 @@ const config = [
     },
     rules: {
       "no-unreachable": "off",
-      quotes: ["error", "double"],
-      semi: ["error", "always"],
+      "quotes": ["error", "double"],
+      "semi": ["error", "always"],
       "eol-last": ["error", "always"],
       "no-async-promise-executor": "off",
       "no-cond-assign": "off",
-      indent: ["error", 2, {
+      "no-empty": ["error", {
+        allowEmptyCatch: true,
+      }],
+      "indent": ["error", 2, {
         ignoredNodes: ["VariableDeclaration[declarations.length=0]"],
       }],
       "@typescript-eslint/no-non-null-assertion": "off",
@@ -84,11 +87,14 @@ const config = [
     files: ["**/*.js", "**/*.mjs", "**/*.cjs"],
     rules: {
       "@typescript-eslint/no-var-requires": "off",
-      quotes: ["error", "double"],
-      semi: ["error", "always"],
+      "quotes": ["error", "double"],
+      "semi": ["error", "always"],
       "eol-last": ["error", "always"],
       "no-async-promise-executor": "off",
-      indent: ["error", 2, {
+      "no-empty": ["error", {
+        allowEmptyCatch: true,
+      }],
+      "indent": ["error", 2, {
         ignoredNodes: ["VariableDeclaration[declarations.length=0]"],
       }],
       "no-unused-vars": ["warn", {

+ 11 - 11
src/tools/post-build.ts

@@ -158,7 +158,7 @@ I welcome every contribution on GitHub!
     );
 
     if(mode === "production")
-      userscript = remSourcemapComments(userscript);
+      userscript = removeSourcemapComments(userscript);
     else
       userscript = userscript.replace(/sourceMappingURL=/gm, `sourceMappingURL=http://localhost:${devServerPort}/`);
 
@@ -181,9 +181,7 @@ I welcome every contribution on GitHub!
         const buildJsonParsed = JSON.parse(String(await readFile(".build.json")));
         buildStats = (Array.isArray(buildJsonParsed) ? buildJsonParsed : []) as Partial<BuildStats>[];
       }
-      catch {
-        void 0;
-      }
+      catch {}
     }
 
     const prevBuildStats = buildStats.find((v) => v.mode === mode);
@@ -193,9 +191,9 @@ I welcome every contribution on GitHub!
       const sizeDiff = sizeKiB - prevBuildStats.sizeKiB;
       const sizeDiffTrunc = parseFloat(sizeDiff.toFixed(2));
       if(sizeDiffTrunc !== 0) {
-        const sizeDiffCol = (sizeDiff > 0 ? k.yellow : k.green)().bold;
+        const sizeCol = (sizeDiff > 0 ? k.yellow : k.green)().bold;
         const sizeDiffNum = `${(sizeDiff > 0 ? "+" : (sizeDiff !== 0 ? "-" : ""))}${Math.abs(sizeDiffTrunc)}`;
-        sizeIndicator = ` ${k.gray("(")}${sizeDiffCol(sizeDiffNum)}${k.gray(")")}`;
+        sizeIndicator = ` ${k.gray("(")}${sizeCol(sizeDiffNum)}${k.gray(")")}`;
       }
     }
 
@@ -238,7 +236,7 @@ function insertValues(userscript: string, replacements: Record<string, Stringifi
 }
 
 /** Removes sourcemapping comments */
-function remSourcemapComments(input: string) {
+function removeSourcemapComments(input: string) {
   return input
     .replace(/\/\/\s?#\s?sourceMappingURL\s?=\s?.+$/gm, "");
 }
@@ -271,7 +269,7 @@ async function exists(path: string) {
 
 /** Resolves the value of an entry in resources.json */
 function resolveResourceVal(value: string, buildNbr: string) {
-  if(!(/\$/.test(value)))
+  if(!(/\$[A-Z]+/.test(value)))
     return value;
 
   const replacements = [
@@ -280,7 +278,7 @@ function resolveResourceVal(value: string, buildNbr: string) {
     ["\\$HOST", host],
     ["\\$BUILD_NUMBER", buildNbr],
     ["\\$UID", buildUid],
-  ];
+  ] as const;
 
   return replacements.reduce((acc, [key, val]) => acc.replace(new RegExp(key, "g"), val), value);
 };
@@ -550,10 +548,12 @@ async function createSvgSpritesheet() {
       sprites.push(`<symbol id="bytm-svg-${name}">\n    ${iconSvg}\n  </symbol>`);
     }
 
-    await writeFile(resolveResourcePath("spritesheet.svg"), `\
+    await writeFile(
+      resolveResourcePath("spritesheet.svg"),
+      `\
 <svg xmlns="http://www.w3.org/2000/svg" id="bytm-svg-spritesheet" style="display: none;" inert="true">
   ${sprites.join("\n  ")}
-</svg>`
+</svg>`,
     );
   }
   catch(err) {