瀏覽代碼

feat: --gen-meta arg

Sv443 1 月之前
父節點
當前提交
96944e61e4
共有 4 個文件被更改,包括 15 次插入7 次删除
  1. 6 1
      contributing.md
  2. 1 0
      rollup.config.mjs
  3. 7 6
      src/tools/post-build.ts
  4. 1 0
      src/types.ts

+ 6 - 1
contributing.md

@@ -111,12 +111,16 @@ To edit an existing translation, please follow these steps:
   You can also configure request logging and more in `.env` and `src/tools/serve.ts`, just make sure to restart the dev server after changing anything.  
     
   This command uses the local server as the assetSource, so that all changes are immediately reflected in the built userscript. Note that this also means the server needs to keep running for the userscript to work. If it's not running, you will run into weird errors because none of the necessary assets are able to be fetched.  
+  Also, no meta file will be generated, since it's not needed for local development.  
     
   Once the build is finished, a link will be printed to the console. Open it to install the userscript.
 - **`pnpm dev-cdn`**  
   Works exactly like `pnpm dev`, but uses the default CDN as the asset source.  
   Practically, this means the server doesn't have to be constantly running.  
-  But this also means that changes to the assets won't be reflected in the userscript until committed, pushed and the script is rebuilt.
+  But this also means that changes to the assets won't be reflected in the userscript until committed, pushed and the script is rebuilt.  
+  Also, no meta file will be generated, since it's not needed for local development.  
+    
+  Once the build is finished, a link will be printed to the console. Open it to install the userscript.
 - **`pnpm build-prod`**  
   Builds the userscript for production for all hosts with their respective options already set.  
   Outputs the files using a suffix predefined in the `package.json` file.  
@@ -129,6 +133,7 @@ To edit an existing translation, please follow these steps:
   - `--config-host=<value>` - The host to build for. Can be either `github` (default), `greasyfork` or `openuserjs`
   - `--config-assetSource=<value>` - Where to get the resource files from. Can be either `local`, `jsdelivr` (default) or `github`
   - `--config-suffix=<value>` - Suffix to add just before the `.user.js` extension. Defaults to an empty string
+  - `--config-gen-meta=<value>` - Whether or not to generate the `.meta.js` file, containing only the userscript header. Can be either `true` (default) or `false`
     
   Shorthand commands:
   - `pnpm build-prod-base` - Used for building for production, targets the main branch and the public asset source.  

+ 1 - 0
rollup.config.mjs

@@ -30,6 +30,7 @@ export default (/**@type {import("./src/types.js").RollupArgs}*/ args) => (async
     host: args["config-host"] ?? "github",
     assetSource: args["config-assetSource"] ?? "jsdelivr",
     suffix: args["config-suffix"] ?? "",
+    meta: args["config-gen-meta"] ?? "false",
   };
   const passCliArgsStr = Object.entries(passCliArgs).map(([key, value]) => `--${key}=${value}`).join(" ");
 

+ 7 - 6
src/tools/post-build.ts

@@ -45,6 +45,7 @@ const branch = getCliArg<CliArg<"config-branch">>("branch", (mode === "productio
 const host = getCliArg<CliArg<"config-host">>("host", "github");
 const assetSource = getCliArg<CliArg<"config-assetSource">>("assetSource", "jsdelivr");
 const suffix = getCliArg<CliArg<"config-suffix">>("suffix", "");
+const genMeta = getCliArg<CliArg<"config-gen-meta">>("meta", "true") === "true";
 
 const envPort = Number(env.DEV_SERVER_PORT);
 /** HTTP port of the dev server */
@@ -121,11 +122,9 @@ ${resourcesDirectives ? "\n" + resourcesDirectives : ""}\
 ${requireDirectives ? "\n" + requireDirectives : ""}\
 ${devDirectives ? "\n" + devDirectives : ""}
 // ==/UserScript==
-`;
-
-  const footer = `/*
-▄▄▄                    ▄   ▄▄▄▄▄▄   ▄
-█  █ ▄▄▄ █   █   ▄▄▄ ▄ ▄█ █  █  █▀▄▀█
+/*
+▄▄▄      ▄   ▄         ▄   ▄▄▄▄▄▄   ▄
+█  █ ▄▄▄ █   █   ▄█▄ ▄ ▄█ █  █  █▀▄▀█
 █▀▀▄ █▄█ █▀  █▀  █▄█ █▀  █   █  █   █
 █▄▄▀ ▀▄▄ ▀▄▄ ▀▄▄ ▀▄▄ █   █   █  █   █
 
@@ -133,7 +132,9 @@ ${devDirectives ? "\n" + devDirectives : ""}
 I welcome every contribution on GitHub!
   https://github.com/Sv443/BetterYTM
 */
+`;
 
+  const footer = `
 /* Disclaimer: I am not affiliated with or endorsed by YouTube, Google, Alphabet, Genius or anyone else */
 /* C&D this 🖕 */
 `;
@@ -167,7 +168,7 @@ I welcome every contribution on GitHub!
     // write userscript
     await writeFile(scriptPath, finalUserscript);
     // write meta file
-    await writeFile(join(rootPath, distFolderPath, userscriptMetaFile), header);
+    genMeta && await writeFile(join(rootPath, distFolderPath, userscriptMetaFile), header);
 
     ringBell && stdout.write("\u0007");
 

+ 1 - 0
src/types.ts

@@ -29,6 +29,7 @@ export type RollupArgs = Partial<{
   "config-host": "greasyfork" | "github" | "openuserjs";
   "config-assetSource": "local" | "github" | "jsdelivr";
   "config-suffix": string;
+  "config-gen-meta": "true" | "false";
 }>;
 
 // I know TS enums are impure but it doesn't really matter here, plus imo they are cooler than pure enums anyway