Ver Fonte

fix: gen-readme works now

Sv443 há 1 ano atrás
pai
commit
5d52d42ec2
7 ficheiros alterados com 88 adições e 25 exclusões
  1. 1 1
      .vscode/settings.json
  2. 17 2
      README-summary.md
  3. 14 12
      README.md
  4. 3 0
      assets/plugins.json
  5. 2 0
      contributing.md
  6. 1 1
      package.json
  7. 50 9
      src/tools/gen-readme.ts

+ 1 - 1
.vscode/settings.json

@@ -29,7 +29,7 @@
       "color": "white",
       "overviewRulerColor": "#44f",
     },
-    "((<!--\\s*)?#\\{\\{/?[A-Z_-]+\\}\\}(\\s*-->)?)": { // #{{SECTION}} and #{{/SECTION}}
+    "((<!--\\s*)?</?\\{\\{[A-Z_-]+\\}\\}>(\\s*-->)?)": { // <!-- <{{FOO}}> --> and <!-- </{{FOO}}> --> or <{{BAR}}> and </{{BAR}}>
       "overviewRulerColor": "#2ae",
       "backgroundColor": "#2ae",
       "color": "#002",

+ 17 - 2
README-summary.md

@@ -1,7 +1,12 @@
-<h1><img src="https://raw.githubusercontent.com/Sv443/BetterYTM/main/assets/logo/logo_128.png" width="96" height="96" /><br>BetterYTM</h1>
+<!-- <{{HEADER}}> -->
+<h1><img src="./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
+Supported Languages: 🇩🇪 German, 🇺🇸 English, 🇩🇪 German, 🇪🇸 Spanish, 🇫🇷 French, 🇮🇳 Hindi, 🇯🇵 Japanese, 🇵🇹 Portuguese, 🇨🇳 Chinese (simpl.)
+<!-- </{{HEADER}}> -->
+[**Features**](#features) • [**Installation**](#installation) • [**Plugins**](#plugins) • [**Support**](#support) • [**Development**](#development) • [**Attributions**](#attributions) • [**Disclaimers**](#disclaimers)
+  
+---
 
 <br>
 
@@ -60,6 +65,16 @@ To install the latest development build [click here](https://github.com/Sv443/Be
 
 <br><br><br>
 
+## Plugins:
+BetterYTM supports plugin userscripts that can be installed in parallel and can make use of BetterYTM's pre-existing API.  
+  
+<!-- <{{PLUGINS}}> -->
+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.
+<!-- </{{PLUGINS}}> -->
+
+<br><br>
+
 ## Support:
 If you have any questions, issues, or feature requests, please [open an issue here](https://github.com/Sv443/BetterYTM/issues/new/choose).  
 You can also join the Discord server and ask your questions there or just hang out with other community members and me:  

+ 14 - 12
README.md

@@ -1,11 +1,11 @@
 <div style="text-align: center;" align="center">
-<!-- #{{HEADER}} -->
+<!-- <{{HEADER}}> -->
 <h1><img src="./assets/logo/logo_128.png" width="96" height="96" /><br>BetterYTM</h1>
 
-### Configurable layout and user experience improvements for YouTube Music
+### Lots of configurable layout and user experience improvements for YouTube Music
 Supported Languages: 🇩🇪 German, 🇺🇸 English, 🇩🇪 German, 🇪🇸 Spanish, 🇫🇷 French, 🇮🇳 Hindi, 🇯🇵 Japanese, 🇵🇹 Portuguese, 🇨🇳 Chinese (simpl.)
-<!-- #{{/HEADER}} -->
-[**Features**](#features) • [**Installation**](#installation) • [**Support**](#support) • [**Plugins**](#plugins) • [**Development**](#development) • [**Attributions**](#attributions) • [**Disclaimers**](#disclaimers)
+<!-- </{{HEADER}}> -->
+[**Features**](#features) • [**Installation**](#installation) • [**Plugins**](#plugins) • [**Support**](#support) • [**Development**](#development) • [**Attributions**](#attributions) • [**Disclaimers**](#disclaimers)
   
 ---
 
@@ -69,19 +69,21 @@ To install the latest development build [click here](https://github.com/Sv443/Be
 
 <br><br><br>
 
-## Support:
-If you have any questions, issues, or feature requests, please [open an issue here](https://github.com/Sv443/BetterYTM/issues/new/choose).  
-You can also join the Discord server and ask your questions there or just hang out with other community members and me:  
-  
-[![Discord](https://img.shields.io/discord/565933531214118942)](https://discord.gg/aBH4uRG)
-
-<br><br>
-
 ## Plugins:
 BetterYTM supports plugin userscripts that can be installed in parallel and can make use of BetterYTM's pre-existing API.  
   
+<!-- <{{PLUGINS}}> -->
 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.
+<!-- </{{PLUGINS}}> -->
+
+<br><br>
+
+## Support:
+If you have any questions, issues, or feature requests, please [open an issue here](https://github.com/Sv443/BetterYTM/issues/new/choose).  
+You can also join the Discord server and ask your questions there or just hang out with other community members and me:  
+  
+[![Discord](https://img.shields.io/discord/565933531214118942)](https://discord.gg/aBH4uRG)
 
 <br><br>
 

+ 3 - 0
assets/plugins.json

@@ -0,0 +1,3 @@
+[
+
+]

+ 2 - 0
contributing.md

@@ -97,6 +97,8 @@ To edit an existing translation, please follow these steps:
     Used for building for experimental versions, targeting the develop branch
 - **`npm run lint`**  
   Builds the userscript with the TypeScript compiler and lints it with ESLint. Doesn't verify *all* of the functionality of the script, only syntax and TypeScript errors!
+- **`npm run gen-readme`**  
+  Updates the README files by inserting different parts of generated sections into them.
 - **`npm run tr-progress`**  
   Checks all translation files for missing strings and updates the progress table in `assets/translations/README.md`
 - **`npm run tr-format -- <arguments>`**  

+ 1 - 1
package.json

@@ -2,7 +2,7 @@
   "name": "betterytm",
   "userscriptName": "BetterYTM",
   "version": "1.1.0",
-  "description": "Configurable layout and user experience improvements for YouTube Music",
+  "description": "Lots of configurable layout and user experience improvements for YouTube Music",
   "homepage": "https://github.com/Sv443/BetterYTM",
   "main": "./src/index.ts",
   "type": "module",

+ 50 - 9
src/tools/gen-readme.ts

@@ -2,6 +2,7 @@ import { readFile, writeFile } from "node:fs/promises";
 import { join } from "node:path";
 import { fileURLToPath } from "node:url";
 import locales from "../../assets/locales.json" assert { type: "json" };
+import pluginsJson from "../../assets/plugins.json" assert { type: "json" };
 import pkg from "../../package.json" assert { type: "json" };
 
 const readmePath = join(fileURLToPath(import.meta.url), "../../../README.md");
@@ -9,8 +10,36 @@ const readmeSummaryPath = join(fileURLToPath(import.meta.url), "../../../README-
 
 const changes = {
   HEADER: genHeader,
+  PLUGINS: genPluginList,
 };
 
+type PluginObj = {
+  /** Name of the plugin */
+  pluginName: string;
+  /**
+   * Descriptions of at least en_US and optionally any other existing locale  
+   * When an unspecified locale is set, the description will default to either the base locale's value or en_US' value
+   */
+  pluginDescription: Partial<Record<keyof typeof locales, string>> & {
+    en_US: string;
+  };
+  /** Path relative to the project root */
+  pluginIconPath: string;
+  /** URL to the plugin's homepage or GitHub repo */
+  pluginUrl: string;
+  /** URL to the plugin's GreasyFork page */
+  pluginUrlGF?: string;
+  /** URL to the plugin's OpenUserJS page */
+  pluginUrlOUJS?: string;
+  /** Name of the plugin's author */
+  authorName: string;
+  /** URL to the plugin author's homepage / GitHub profile */
+  authorUrl?: string;
+};
+
+const pluginList = pluginsJson as PluginObj[];
+void ["TODO:", pluginList];
+
 async function run() {
   const readmeFiles = [
     {
@@ -37,29 +66,34 @@ async function run() {
 }
 
 async function modifyReadme(readmeLines: string[], changes: Record<string, () => Promise<string>>) {
-  const lines = [];
+  let lines = [...readmeLines];
+  let retLines = [] as string[];
   for(const [name, getContent] of Object.entries(changes)) {
-    const beginRegex = new RegExp(`<!--\\s?#\\{\\{\\s?${name.toUpperCase()}\\s?\\}\\}\\s?-->`, "gm");
-    const endRegex = new RegExp(`<!--\\s?#\\{\\{\\s?/${name.toUpperCase()}\\s?\\}\\}\\s?-->`, "gm");
+    retLines = [];
+
+    const beginRegex = new RegExp(`<!--\\s?<\\{\\{\\s?${name.toUpperCase()}\\s?\\}\\}>\\s?-->`, "gm");
+    const endRegex = new RegExp(`<!--\\s?</\\{\\{\\s?${name.toUpperCase()}\\s?\\}\\}>\\s?-->`, "gm");
 
     // find line number that matches beginRegex
-    const beginLine = readmeLines.findIndex((line) => beginRegex.test(line));
+    const beginLine = lines.findIndex((line) => beginRegex.test(line));
     if(beginLine === -1)
       continue;
 
     // find line number that matches endRegex
-    const endLine = readmeLines.findIndex((line) => endRegex.test(line));
+    const endLine = lines.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();
-    lines.push(...readmeLines.splice(0, beginLine + 1));
-    lines.push(...newContent.split(/\r?\n/gm));
-    lines.push(...readmeLines.splice(endLine - beginLine - 1));
+    retLines.push(...lines.splice(0, beginLine + 1));
+    retLines.push(...newContent.split(/\r?\n/gm));
+    retLines.push(...lines.splice(endLine - beginLine - 1));
+
+    lines = [...retLines];
   }
 
-  return lines.length > 0 ? lines.join("\n") : readmeLines.join("\n");
+  return retLines.length > 0 ? retLines.join("\n") : readmeLines.join("\n");
 }
 
 async function genHeader() {
@@ -74,4 +108,11 @@ Supported Languages: ${langStr}\
 `;
 }
 
+async function genPluginList() {
+  return `\
+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.\
+`;
+}
+
 run();