Browse Source

feat: readme generation, unfinished

Sv443 1 year ago
parent
commit
0401949522
3 changed files with 84 additions and 32 deletions
  1. 11 32
      README.md
  2. 1 0
      package.json
  3. 72 0
      src/tools/gen-readme.ts

+ 11 - 32
README.md

@@ -1,15 +1,8 @@
-<div style="text-align: center;" align="center">
-
-<h1><img src="./assets/logo/logo_128.png" width="96" height="96" /><br>BetterYTM</h1>
+<h1><img src="https://raw.githubusercontent.com/Sv443/BetterYTM/main/assets/logo/logo_128.png" width="96" height="96" /><br>BetterYTM</h1>
 
 ### Lots of configurable layout and user experience improvements for YouTube Music
 Supported Languages: 🇺🇸 English, 🇩🇪 German, 🇪🇸 Spanish, 🇫🇷 French, 🇮🇳 Hindi, 🇯🇵 Japanese, 🇵🇹 Portuguese, 🇨🇳 Chinese
 
-[**Features**](#features) • [**Installation**](#installation) • [**Support**](#support) • [**Plugins**](#plugins) • [**Development**](#development) • [**Attributions**](#attributions) • [**Disclaimers**](#disclaimers)
-  
----
-
-</div>
 <br>
 
 ### Features:
@@ -32,15 +25,14 @@ All of these can be toggled and configured in the configuration menu.
   
 ... and these are just the notable features, there are many more smaller improvements and bugfixes!
 
-<br><br>
+<br>
 
 To toggle and configure features, after installing the userscript, click the "BetterYTM" text under the logo to open the configuration menu.  
 Alternatively or if you disabled the watermark, you can open it through the popover menu opened by clicking your avatar in the top right corner.  
   
-> [!NOTE]  
-> My work relies on donations, so if you like this userscript please consider [supporting development ❤️](https://github.com/sponsors/Sv443)
+My work relies on donations, so if you like this userscript please consider [supporting development ❤️](https://github.com/sponsors/Sv443)
 
-<br><br><br>
+<br><br>
 
 ## Installation:
 <b>
@@ -50,9 +42,7 @@ I really recommend ViolentMonkey: [Firefox](https://addons.mozilla.org/en-US/fir
 
 </b>
 
-Once you have the extension, click this button to install the userscript:  
-  
-<a href="https://github.com/Sv443/BetterYTM/raw/main/dist/BetterYTM.user.js" target="_blank"><img src="https://img.shields.io/badge/Install-%E2%96%BA-039e10" height="24"></a>
+Once you have the extension, click the install button at the top of this page!
 
 <br>
 
@@ -61,6 +51,7 @@ Once you have the extension, click this button to install the userscript:
 Note: the `unsafeWindow` grant is required due to limitations in some browsers, [see this issue for more info.](https://github.com/Sv443/BetterYTM/issues/18#show_issue)
 
 </sup>
+<br>
 <sup>
 
 To install the latest development build [click here](https://github.com/Sv443/BetterYTM/raw/develop/dist/BetterYTM.user.js) (note: the script will not auto-update to the next release version)
@@ -77,19 +68,11 @@ You can also join the Discord server and ask your questions there or just hang o
 
 <br><br>
 
-## Plugins:
-BetterYTM supports plugin userscripts that can be installed in parallel and can make use of BetterYTM's pre-existing API.  
-  
-Currently there are no available plugins, but you can [submit an issue using the plugin submission template](https://github.com/Sv443/BetterYTM/issues/new/choose) so it will be listed here.  
-Also refer to the [plugin creation guide](./contributing.md#developing-a-plugin-that-interfaces-with-betterytm) for more information on how to use the API to create a plugin.
-
-<br><br>
-
 ### Development:
 This project is based on my extensive template for making a userscript with TypeScript and many modern language and convenience features.  
 [Check it out here](https://github.com/Sv443/Userscript.ts) if you want to make your own userscripts!  
   
-**For information on how to contribute to this project, see [the contributing guide](./contributing.md)**
+**For information on how to contribute to this project or how to develop a plugin for BetterYTM, see [the contributing guide](https://github.com/Sv443/BetterYTM/tree/main/contributing.md)**
 
 <br><br>
 
@@ -98,27 +81,23 @@ This userscript depends on these runtime libraries:
 - [nanoevents](https://npmjs.org/package/nanoevents)
 - [@sv443-network/userutils](https://github.com/Sv443-Network/UserUtils)
   
-For development dependencies, please refer to `devDependencies` in [`package.json`](./package.json)
+For development dependencies, please refer to `devDependencies` in [`package.json`](https://github.com/Sv443/BetterYTM/tree/main/package.json)
   
 Icons:  
 - Most icons are from [Material Icons](https://fonts.google.com/icons)
-- For external icon attributions, see [`assets/external/`](assets/external/README.md)
+- For external icon attributions, see [`assets/external/`](https://github.com/Sv443/BetterYTM/tree/main/assets/external/)
 
 <br><br>
 
 ### Disclaimers:
 - I am not affiliated with or endorsed by YouTube, Google, Alphabet, Genius, or anyone else.
-- I do not own any third party icons, I just re-host them [here](./assets/external/) for better stability and availability.
+- I do not own any third party icons, I just re-host them [here](https://github.com/Sv443/BetterYTM/tree/main/assets/external/) for better stability and availability.
 - I do not intend to ever collect any data about you, everything in this script is done and stored locally on your device or on the site the script runs on.
 - I can't guarantee this software is without flaws. If something bad happens, I don't accept blame. I do however accept [bug reports and feature requests.](https://github.com/Sv443/BetterYTM/issues/new/choose)
 
 <br><br><br><br>
 
-<div align="center" style="text-align: center;">
-
 Made with ❤️ by [Sv443](https://github.com/Sv443)  
 If you like this userscript, please consider [supporting me](https://github.com/sponsors/Sv443)  
   
-© 2022 Sv443 - [AGPL-3.0](./LICENSE.txt)
-
-</div>
+© 2022 Sv443 - [AGPL-3.0](https://github.com/Sv443/BetterYTM/tree/main/LICENSE.txt)

+ 1 - 0
package.json

@@ -21,6 +21,7 @@
     "post-build": "npm run node-ts -- ./src/tools/post-build.ts",
     "tr-progress": "npm run node-ts -- ./src/tools/tr-progress.ts",
     "tr-format": "npm run node-ts -- ./src/tools/tr-format.ts",
+    "gen-readme": "npm run node-ts -- ./src/tools/gen-readme.ts",
     "node-ts": "node --no-warnings=ExperimentalWarning --enable-source-maps --loader ts-node/esm",
     "invisible": "node src/tools/run-invisible.mjs",
     "test": "npm run node-ts -- ./test.ts"

+ 72 - 0
src/tools/gen-readme.ts

@@ -0,0 +1,72 @@
+import { readFile, writeFile } from "node:fs/promises";
+import { join } from "node:path";
+import { fileURLToPath } from "node:url";
+
+const readmePath = join(fileURLToPath(import.meta.url), "../../../README.md");
+const readmeSummaryPath = join(fileURLToPath(import.meta.url), "../../../README-summary.md");
+
+async function run() {
+  const readmeFiles = [
+    {
+      path: readmePath,
+      content: await readFile(readmePath, "utf-8"),
+    },
+    {
+      path: readmeSummaryPath,
+      content: await readFile(readmeSummaryPath, "utf-8"),
+    },
+  ];
+
+  for(const { path, content } of readmeFiles) {
+    console.info(`- Generating '${path}'`);
+
+    const result = await modifyReadme(content.split(/\r?\n/gm), {
+      HEADER: genHeader,
+    });
+
+    await writeFile(readmePath, result);
+  }
+
+  console.log("\n\x1b[32mReadme files generated successfully\x1b[0m\n");
+
+  setImmediate(() => process.exit(0));
+}
+
+async function modifyReadme(readmeLines: string[], changes: Record<string, () => Promise<string>>) {
+  for(const [name, getContent] of Object.entries(changes)) {
+    const beginRegex = new RegExp(`<!--\\s?#\\{\\{${name.toUpperCase()}\\}\\}\\s?-->`, "gm");
+    const endRegex = new RegExp(`<!--\\s?#\\{\\{/${name.toUpperCase()}\\}\\}\\s?-->`, "gm");
+
+    // find line number that matches beginRegex
+    const beginLine = readmeLines.findIndex((line) => beginRegex.test(line));
+    if(beginLine === -1)
+      continue;
+
+    // find line number that matches endRegex
+    const endLine = readmeLines.findIndex((line) => endRegex.test(line));
+    if(endLine === -1)
+      throw new Error(`No end tag found for ${name.toUpperCase()}`);
+
+    // replace the content between the two lines
+    const newContent = await getContent();
+    readmeLines = [
+      ...readmeLines.slice(0, beginLine + 1),
+      newContent,
+      ...readmeLines.slice(endLine),
+    ];
+  }
+
+  return readmeLines.join("\n");
+}
+
+async function genHeader() {
+  return `\
+<h1><img src="./assets/logo/logo_128.png" width="96" height="96" /><br>BetterYTM</h1>
+
+Test
+### Lots of configurable layout and user experience improvements for YouTube Music
+Supported Languages: 🇺🇸 English, 🇩🇪 German, 🇪🇸 Spanish, 🇫🇷 French, 🇮🇳 Hindi, 🇯🇵 Japanese, 🇵🇹 Portuguese, 🇨🇳 Chinese
+`;
+}
+
+run();