Browse Source

ref: condense alwaysExternalAssetPatterns into one pattern & add css to it

Sv443 1 month ago
parent
commit
bb681a6f32
4 changed files with 8 additions and 17 deletions
  1. 5 8
      .vscode/schemas/resources.schema.json
  2. 1 1
      assets/README.md
  3. 1 7
      assets/resources.json
  4. 1 1
      contributing.md

+ 5 - 8
.vscode/schemas/resources.schema.json

@@ -4,14 +4,11 @@
   "required": ["resources"],
   "description": "Contains all resources (images, fonts, stylesheets, etc.) used by BYTM.",
   "properties": {
-    "alwaysExternalAssetPatterns": {
-      "type": "array",
-      "description": "List of patterns passed to `new RegExp()` that should always be considered external assets (they won't be loaded via @resource).",
-      "items": {
-        "type": "string",
-        "format": "regex",
-        "pattern": "^.+$"
-      }
+    "externalAssetPattern": {
+      "type": "string",
+      "description": "Pattern passed to `new RegExp()` that identifies an external asset that will be loaded via fetching from the CDN instead of a locally cached @resource.",
+      "format": "regex",
+      "pattern": "^.+$"
     },
     "resources": {
       "type": "object",

+ 1 - 1
assets/README.md

@@ -43,7 +43,7 @@ The keys of the object are the locale codes (which follow the [BCP 47 standard](
 ### [`resources.json`](resources.json)
 This file contains the resources that are loaded into the runtime through the `@resource` userscript directive.  
 That includes icons, images, CSS files, fonts, translations and other assets.  
-Configure which resources will always be fetched from the external asset source (GitHub's CDN) by editing the regexp patterns in the `alwaysExternalAssetPatterns` property.  
+Configure which resources will always be fetched from the external asset source (GitHub's CDN) by editing the regexp pattern in the `externalAssetPattern` property.  
   
 Inside the file is an object under the `resources` prop, whose keys are the resource names and the values are the path to the resource or a configuration object (props are listed in the table below).  
 The path to the resource can be relative, in which case it's resolved relative to the `assets` directory.  

+ 1 - 7
assets/resources.json

@@ -1,11 +1,5 @@
 {
-  "alwaysExternalAssetPatterns": [
-    "^doc-",
-    "^font-",
-    "^icon-",
-    "^img-",
-    "^trans-"
-  ],
+  "externalAssetPattern": "^(css|doc|font|icon|img|trans)-",
   "resources": {
     "css-above_queue_btns": "style/aboveQueueBtns.css",
     "css-above_queue_btns_sticky": "style/aboveQueueBtnsSticky.css",

+ 1 - 1
contributing.md

@@ -209,7 +209,7 @@ If you need help with these, don't hesitate to reach out to me (see the top of t
   3. Add the asset to the [`assets/resources.json`](./assets/resources.json) file by following the format of the other entries.  
     If the path begins with a slash, it will start at the project root (where package.json is), otherwise it will start at the `assets` folder.  
     The path string or all values in the object of each resource will be passed through the function `resolveResourceVal()` in [`src/tools/post-build.ts`](./src/tools/post-build.ts) to resolve placeholders like `$BRANCH`. View all replacements by looking up that function.
-  4. The asset will be immediately available in the userscript after the next build and the `@resource` directive will automatically point at the locally served asset or the GitHub CDN, depending on the build mode and if the asset key matches a pattern in `alwaysExternalAssetPatterns` in the `assets/resources.json` file.
+  4. The asset will be immediately available in the userscript after the next build and the `@resource` directive will automatically point at the locally served asset or the GitHub CDN, depending on the build mode and if the asset key matches the `externalAssetPattern` in the `assets/resources.json` file.
   5. If the asset is an SVG icon, it will be included in the file `assets/spritesheet.svg` so it can be referenced without needing to be fetched every time it's used. This spritesheet needs to be committed before the build, find out why in the next step.
   6. **When committing, make sure to commit the assets first, then rebuild the userscript and make a second commit.**  
     This needs to be done because the build script at `src/tools/post-build.ts` will use the *previous* commit hash to create version-independent URLs for the assets. These will continue to work in the future, instead of pointing to an ever-changing branch where files could be moved, renamed or deleted at any time.