Sfoglia il codice sorgente

ref: restructure stuff & add ts-node to post-build

Sv443 1 anno fa
parent
commit
a05617d897
8 ha cambiato i file con 31 aggiunte e 19 eliminazioni
  1. 0 1
      .gitignore
  2. 2 2
      dist/BetterYTM.user.js
  3. 7 0
      dist/BetterYTM.user.js.LICENSE.txt
  4. 3 0
      dist/README.md
  5. 2 1
      package.json
  6. 12 11
      src/tools/post-build.ts
  7. 2 1
      tsconfig.json
  8. 3 3
      webpack.config.js

+ 0 - 1
.gitignore

@@ -1,3 +1,2 @@
 node_modules/
 test.js
-*.LICENSE.txt

+ 2 - 2
BetterYTM.user.js → dist/BetterYTM.user.js

@@ -18,8 +18,8 @@
 // @connect         youtube.com
 // @connect         github.com
 // @connect         githubusercontent.com
-// @downloadURL     https://github.com/Sv443/BetterYTM/raw/main/BetterYTM.user.js
-// @updateURL       https://github.com/Sv443/BetterYTM/raw/main/BetterYTM.user.js
+// @downloadURL     https://github.com/Sv443/BetterYTM/raw/main/dist/BetterYTM.user.js
+// @updateURL       https://github.com/Sv443/BetterYTM/raw/main/dist/BetterYTM.user.js
 // ==/UserScript==
 /*
  ▄▄▄                    ▄   ▄▄▄▄▄▄   ▄

+ 7 - 0
dist/BetterYTM.user.js.LICENSE.txt

@@ -0,0 +1,7 @@
+/**
+ * A simple and lightweight EventEmitter by TypeScript for Node.js or Browsers.
+ *
+ * @author billjs
+ * @see https://github.com/billjs/event-emitter
+ * @license MIT(https://opensource.org/licenses/MIT)
+ */

+ 3 - 0
dist/README.md

@@ -0,0 +1,3 @@
+The contents of this folder were auto-generated by webpack.  
+  
+To go back to the main page [click here.](../README.md)

+ 2 - 1
package.json

@@ -6,6 +6,7 @@
   "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1",
     "build": "webpack",
+    "post-build": "ts-node ./src/tools/post-build.ts",
     "serve": "http-server -s -c 5 -p 8710 .",
     "watch": "nodemon --exec \"npm run build && npm run serve\"",
     "lint": "eslint ."
@@ -62,4 +63,4 @@
       "dev/*"
     ]
   }
-}
+}

+ 12 - 11
tools/post-build.js → src/tools/post-build.ts

@@ -1,20 +1,21 @@
-const { readFile, writeFile, stat } = require("fs/promises");
-const package = require("../package.json");
+import { readFile, writeFile, stat } from "fs/promises";
+import pkg from "../../package.json";
+import { join } from "path";
 
 const userscriptName = "BetterYTM.user.js";
-const url = package.repository.url.replace("git+", "").replace(".git", "");
-const scriptUrl = package.repository.url.replace("git+", "").replace(".git", "") + "/raw/main/" + userscriptName;
+const url = pkg.repository.url.replace("git+", "").replace(".git", "");
+const scriptUrl = pkg.repository.url.replace("git+", "").replace(".git", "") + "/raw/main/dist/" + userscriptName;
 
 const header = `// ==UserScript==
 // @name            BetterYTM
-// @homepageURL     ${package.homepage}
+// @homepageURL     ${pkg.homepage}
 // @namespace       ${url}
-// @version         ${package.version}
+// @version         ${pkg.version}
 // @description     Improvements for YouTube Music
 // @description:de  Verbesserungen für YouTube Music
-// @license         ${package.license}
-// @author          ${package.author.name}
-// @copyright       ${package.author.name} <${package.author.email}>
+// @license         ${pkg.license}
+// @author          ${pkg.author.name}
+// @copyright       ${pkg.author.name} <${pkg.author.email}>
 // @match           https://music.youtube.com/*
 // @match           https://www.youtube.com/*
 // @icon            https://raw.githubusercontent.com/Sv443/BetterYTM/main/resources/icon/v2.1_200.png
@@ -43,10 +44,10 @@ const header = `// ==UserScript==
 
 (async () => {
   try {
-    const path = `./${userscriptName}`;
+    const path = join(__dirname, `../../dist/${userscriptName}`);
     const input = String(await readFile(path));
     await writeFile(path, `${header}\n${input}${input.endsWith("\n") ? "" : "\n"}`);
-    console.info("\nSuccessfully added the userscript header");
+    console.info("Successfully added the userscript header");
     console.info(`\nFinal size is ${((await stat(path)).size / 1000).toFixed(2)} KB`);
   }
   catch(err) {

+ 2 - 1
tsconfig.json

@@ -3,16 +3,17 @@
     "module": "NodeNext",
     "target": "ES2016",
     "outDir": ".",
-    "allowJs": true,
     "lib": [
       "DOM",
       "DOM.Iterable"
     ],
+    "allowJs": true,
     "allowSyntheticDefaultImports": true,
     "baseUrl": ".",
     "esModuleInterop": true,
     "forceConsistentCasingInFileNames": true,
     "isolatedModules": true,
+    "resolveJsonModule": true,
     "rootDir": ".",
     "skipLibCheck": true,
     "sourceMap": true,

+ 3 - 3
webpack.config.js

@@ -1,4 +1,4 @@
-const path = require("path");
+const { join } = require("path");
 const { exec } = require("child_process");
 
 module.exports = {
@@ -35,7 +35,7 @@ module.exports = {
     {
       apply: (compiler) => {
         compiler.hooks.afterEmit.tap("AfterEmitPlugin", () => {
-          exec("node ./tools/post-build.js", (_err, stdout, stderr) => {
+          exec("npm run post-build", (_err, stdout, stderr) => {
             stdout && process.stdout.write(`${stdout}\n`);
             stderr && process.stderr.write(`${stderr}\n`);
           });
@@ -48,6 +48,6 @@ module.exports = {
   },
   output: {
     filename: "BetterYTM.user.js",
-    path: path.resolve(__dirname),
+    path: join(__dirname, "/dist"),
   },
 };