From 8e611175cac819afdc2ca7681bf95894c79bb06f Mon Sep 17 00:00:00 2001 From: Daniel Scalzi Date: Sun, 5 Jul 2020 13:51:49 -0400 Subject: [PATCH] Add support for optional vs required modules. Directories representing toggleable modules are now segemented into three subdirectories. * `required` Modules that are required. * `optionalon` Modules that are optional and enabled by default. * `optionaloff` Modules that are optional and disabled by default. Filter your files into these three directories. Files at the root directory will no longer be processed. Currently, forgemods and litemods are the only toggleable modules. For existing servers, just manually create these directories and move your files inside either of them. Generating a new server will automatically create them. --- .github/FUNDING.yml | 3 + README.md | 61 ++++++- package-lock.json | 159 ++++++++++++------ package.json | 10 +- .../struct/model/module/forgemod.struct.ts | 6 +- .../struct/model/module/litemod.struct.ts | 6 +- .../struct/model/module/module.struct.ts | 14 +- .../model/module/toggleablemodule.struct.ts | 68 ++++++++ 8 files changed, 253 insertions(+), 74 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 src/model/struct/model/module/toggleablemodule.struct.ts diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..e338313 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +github: dscalzi +patreon: dscalzi +custom: ['https://www.paypal.me/dscalzi'] diff --git a/README.md b/README.md index 9bed90f..25b103b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Nebula -Generate a distribution.json for Helios. +Generate a distribution.json for Helios. Documentation on this format can be found [here][distro.md]. ## Requirements @@ -185,8 +185,65 @@ Ex. * `files` All modules of type `File`. * `libraries` All modules of type `Library` * `forgemods` All modules of type `ForgeMod`. + * This is a directory of toggleable modules. See the note below. * `litemods` All modules of type `LiteMod`. + * This is a directory of toggleable modules. See the note below. * `TestServer-1.12.2.png` Server icon file. +#### Toggleable Modules -[dotenvnpm]: https://www.npmjs.com/package/dotenv \ No newline at end of file +If a directory represents a toggleable mod, it will have three subdirectories. You must filter your files into these three. + +* `required` Modules that are required. +* `optionalon` Modules that are optional and enabled by default. +* `optionaloff` Modules that are optional and disabled by default. + +### Additional Metadata + +To preserve metadata that cannot be inferred via file structure, two files exist. Default values will be generated when applicable. Customize to fit your needs. These values should be self explanatory. If further details are required, see the [distribution.json specification document][distro.md]. + +#### ${ROOT}/meta/distrometa.json + +Represents the additiona metadata on the distribution object. Sample: + +```json +{ + "meta": { + "rss": "", + "discord": { + "clientId": "", + "smallImageText": "", + "smallImageKey": "" + } + } +} +``` + +#### servers/${YOUR_SERVER}/servermeta.json + +Represents the additional metadata on the server object (for a YOUR_SERVER). Sample: + +```json +{ + "meta": { + "version": "1.0.0", + "name": "Test (Minecraft 1.12.2)", + "description": "Test Running Minecraft 1.12.2 (Forge v14.23.5.2854)", + "address": "localhost:25565", + "discord": { + "shortId": "1.12.2 Test Server", + "largeImageText": "1.12.2 Test Server", + "largeImageKey": "seal-circle" + }, + "mainServer": false, + "autoconnect": true + }, + "forge": { + "version": "14.23.5.2854" + } +} +``` + + +[dotenvnpm]: https://www.npmjs.com/package/dotenv +[distro.md]: https://github.com/dscalzi/HeliosLauncher/blob/master/docs/distro.md \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 96adab4..2d5aa5f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,27 +5,27 @@ "requires": true, "dependencies": { "@babel/code-frame": { - "version": "7.10.3", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.3.tgz", - "integrity": "sha512-fDx9eNW0qz0WkUeqL6tXEXzVlPh6Y5aCDEZesl0xBGA8ndRukX91Uk44ZqnkECp01NAZUdCAl+aiQNGi0k88Eg==", + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz", + "integrity": "sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==", "dev": true, "requires": { - "@babel/highlight": "^7.10.3" + "@babel/highlight": "^7.10.4" } }, "@babel/helper-validator-identifier": { - "version": "7.10.3", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.3.tgz", - "integrity": "sha512-bU8JvtlYpJSBPuj1VUmKpFGaDZuLxASky3LhaKj3bmpSTY6VWooSM8msk+Z0CZoErFye2tlABF6yDkT3FOPAXw==", + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz", + "integrity": "sha512-3U9y+43hz7ZM+rzG24Qe2mufW5KhvFg/NhnNph+i9mgCtdTCtMJuI1TMkrIUiK7Ix4PYlRF9I5dhqaLYA/ADXw==", "dev": true }, "@babel/highlight": { - "version": "7.10.3", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.3.tgz", - "integrity": "sha512-Ih9B/u7AtgEnySE2L2F0Xm0GaM729XqqLfHkalTsbjXGyqmf/6M0Cu0WpvqueUlW+xk88BHw9Nkpj49naU+vWw==", + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.4.tgz", + "integrity": "sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA==", "dev": true, "requires": { - "@babel/helper-validator-identifier": "^7.10.3", + "@babel/helper-validator-identifier": "^7.10.4", "chalk": "^2.0.0", "js-tokens": "^4.0.0" }, @@ -67,6 +67,15 @@ } } }, + "@babel/runtime-corejs3": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.10.4.tgz", + "integrity": "sha512-BFlgP2SoLO9HJX9WBwN67gHWMBhDX/eDz64Jajd6mR/UAUzqrNMm99d4qHnVaKscAElZoFiPv+JpR/Siud5lXw==", + "requires": { + "core-js-pure": "^3.0.0", + "regenerator-runtime": "^0.13.4" + } + }, "@dabh/diagnostics": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/@dabh/diagnostics/-/diagnostics-2.0.2.tgz", @@ -131,12 +140,12 @@ "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.4.0.tgz", - "integrity": "sha512-wfkpiqaEVhZIuQRmudDszc01jC/YR7gMSxa6ulhggAe/Hs0KVIuo9wzvFiDbG3JD5pRFQoqnf4m7REDsUvBnMQ==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.5.0.tgz", + "integrity": "sha512-m4erZ8AkSjoIUOf8s4k2V1xdL2c1Vy0D3dN6/jC9d7+nEqjY3gxXCkgi3gW/GAxPaA4hV8biaCoTVdQmfAeTCQ==", "dev": true, "requires": { - "@typescript-eslint/experimental-utils": "3.4.0", + "@typescript-eslint/experimental-utils": "3.5.0", "debug": "^4.1.1", "functional-red-black-tree": "^1.0.1", "regexpp": "^3.0.0", @@ -162,37 +171,46 @@ } }, "@typescript-eslint/experimental-utils": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-3.4.0.tgz", - "integrity": "sha512-rHPOjL43lOH1Opte4+dhC0a/+ks+8gOBwxXnyrZ/K4OTAChpSjP76fbI8Cglj7V5GouwVAGaK+xVwzqTyE/TPw==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-3.5.0.tgz", + "integrity": "sha512-zGNOrVi5Wz0jcjUnFZ6QUD0MCox5hBuVwemGCew2qJzUX5xPoyR+0EzS5qD5qQXL/vnQ8Eu+nv03tpeFRwLrDg==", "dev": true, "requires": { "@types/json-schema": "^7.0.3", - "@typescript-eslint/typescript-estree": "3.4.0", + "@typescript-eslint/types": "3.5.0", + "@typescript-eslint/typescript-estree": "3.5.0", "eslint-scope": "^5.0.0", "eslint-utils": "^2.0.0" } }, "@typescript-eslint/parser": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-3.4.0.tgz", - "integrity": "sha512-ZUGI/de44L5x87uX5zM14UYcbn79HSXUR+kzcqU42gH0AgpdB/TjuJy3m4ezI7Q/jk3wTQd755mxSDLhQP79KA==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-3.5.0.tgz", + "integrity": "sha512-sU07VbYB70WZHtgOjH/qfAp1+OwaWgrvD1Km1VXqRpcVxt971PMTU7gJtlrCje0M+Sdz7xKAbtiyIu+Y6QdnVA==", "dev": true, "requires": { "@types/eslint-visitor-keys": "^1.0.0", - "@typescript-eslint/experimental-utils": "3.4.0", - "@typescript-eslint/typescript-estree": "3.4.0", + "@typescript-eslint/experimental-utils": "3.5.0", + "@typescript-eslint/types": "3.5.0", + "@typescript-eslint/typescript-estree": "3.5.0", "eslint-visitor-keys": "^1.1.0" } }, + "@typescript-eslint/types": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-3.5.0.tgz", + "integrity": "sha512-Dreqb5idi66VVs1QkbAwVeDmdJG+sDtofJtKwKCZXIaBsINuCN7Jv5eDIHrS0hFMMiOvPH9UuOs4splW0iZe4Q==", + "dev": true + }, "@typescript-eslint/typescript-estree": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-3.4.0.tgz", - "integrity": "sha512-zKwLiybtt4uJb4mkG5q2t6+W7BuYx2IISiDNV+IY68VfoGwErDx/RfVI7SWL4gnZ2t1A1ytQQwZ+YOJbHHJ2rw==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-3.5.0.tgz", + "integrity": "sha512-Na71ezI6QP5WVR4EHxwcBJgYiD+Sre9BZO5iJK2QhrmRPo/42+b0no/HZIrdD1sjghzlYv7t+7Jis05M1uMxQg==", "dev": true, "requires": { + "@typescript-eslint/types": "3.5.0", + "@typescript-eslint/visitor-keys": "3.5.0", "debug": "^4.1.1", - "eslint-visitor-keys": "^1.1.0", "glob": "^7.1.6", "is-glob": "^4.0.1", "lodash": "^4.17.15", @@ -217,6 +235,15 @@ } } }, + "@typescript-eslint/visitor-keys": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-3.5.0.tgz", + "integrity": "sha512-7cTp9rcX2sz9Z+zua9MCOX4cqp5rYyFD5o8LlbSpXrMTXoRdngTtotRZEkm8+FNMHPWYFhitFK+qt/brK8BVJQ==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.1.0" + } + }, "acorn": { "version": "7.3.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.3.1.tgz", @@ -242,9 +269,9 @@ } }, "ansi-colors": { - "version": "3.2.4", - "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.4.tgz", - "integrity": "sha512-hHUXGagefjN2iRrID63xckIvotOXOojhQKWIPUZ4mNUZ9nLZW+7FMNoE1lOkEhNWYsx/7ysGIuJYCiMAA9FnrA==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", "dev": true }, "ansi-regex": { @@ -424,6 +451,11 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, + "core-js-pure": { + "version": "3.6.5", + "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.6.5.tgz", + "integrity": "sha512-lacdXOimsiD0QyNf9BC/mxivNJ/ybBGJXQFKzRekp1WTHoVUWsUHEn+2T8GJAzzIhyOuXA+gOxCVN3l+5PLPUA==" + }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -449,9 +481,12 @@ } }, "decamelize": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-3.2.0.tgz", + "integrity": "sha512-4TgkVUsmmu7oCSyGBm5FvfMoACuoh9EOidm7V5/J2X2djAwwt57qb3F2KMP2ITqODTCSwb+YRV+0Zqrv18k/hw==", + "requires": { + "xregexp": "^4.2.4" + } }, "deep-is": { "version": "0.1.3", @@ -484,12 +519,12 @@ "integrity": "sha512-AKrN98kuwOzMIdAizXGI86UFBoo26CL21UM763y1h/GMSJ4/OHU9k2YlsmBpyScFo/wbLzWQJBMCW4+IO3/+OQ==" }, "enquirer": { - "version": "2.3.5", - "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.5.tgz", - "integrity": "sha512-BNT1C08P9XD0vNg3J475yIUG+mVdp9T6towYFHUv897X0KoHBjB1shyrNmhmtHWKP17iSWgo7Gqh7BBuzLZMSA==", + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", + "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==", "dev": true, "requires": { - "ansi-colors": "^3.2.1" + "ansi-colors": "^4.1.1" } }, "escape-string-regexp": { @@ -499,9 +534,9 @@ "dev": true }, "eslint": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.3.1.tgz", - "integrity": "sha512-cQC/xj9bhWUcyi/RuMbRtC3I0eW8MH0jhRELSvpKYkWep3C6YZ2OkvcvJVUeO6gcunABmzptbXBuDoXsjHmfTA==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.4.0.tgz", + "integrity": "sha512-gU+lxhlPHu45H3JkEGgYhWhkR9wLHHEXC9FbWFnTlEkbKyZKWgWRLgf61E8zWmBuI6g5xKBph9ltg3NtZMVF8g==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", @@ -1042,9 +1077,9 @@ } }, "p-limit": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.2.tgz", - "integrity": "sha512-WGR+xHecKTr7EbUEhyLSh5Dube9JtdiG78ufaeLxTgpudf/20KqyMioIUZJAezlTIi6evxuoUs9YXc11cU+yzQ==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", "requires": { "p-try": "^2.0.0" } @@ -1121,6 +1156,11 @@ "util-deprecate": "^1.0.1" } }, + "regenerator-runtime": { + "version": "0.13.5", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz", + "integrity": "sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA==" + }, "regexpp": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz", @@ -1390,9 +1430,9 @@ "dev": true }, "typescript": { - "version": "3.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.5.tgz", - "integrity": "sha512-hSAifV3k+i6lEoCJ2k6R2Z/rp/H3+8sdmcn5NrS3/3kE7+RyZXm9aqvxWqjEXHAd8b0pShatpcdMTvEdvAJltQ==", + "version": "3.9.6", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.6.tgz", + "integrity": "sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==", "dev": true }, "universalify": { @@ -1519,18 +1559,26 @@ "mkdirp": "^0.5.1" } }, + "xregexp": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/xregexp/-/xregexp-4.3.0.tgz", + "integrity": "sha512-7jXDIFXh5yJ/orPn4SXjuVrWWoi4Cr8jfV1eHv9CixKSbU+jY4mxfrBwAuDvupPNKpMUY+FeIqsVw/JLT9+B8g==", + "requires": { + "@babel/runtime-corejs3": "^7.8.3" + } + }, "y18n": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==" }, "yargs": { - "version": "15.3.1", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.3.1.tgz", - "integrity": "sha512-92O1HWEjw27sBfgmXiixJWT5hRBp2eobqXicLtPBIDBhYB+1HpwZlXmbW2luivBJHBzki+7VyCLRtAkScbTBQA==", + "version": "15.4.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.0.tgz", + "integrity": "sha512-D3fRFnZwLWp8jVAAhPZBsmeIHY8tTsb8ItV9KaAaopmC6wde2u6Yw29JBIZHXw14kgkRnYmDgmQU4FVMDlIsWw==", "requires": { "cliui": "^6.0.0", - "decamelize": "^1.2.0", + "decamelize": "^3.2.0", "find-up": "^4.1.0", "get-caller-file": "^2.0.1", "require-directory": "^2.1.1", @@ -1539,7 +1587,7 @@ "string-width": "^4.2.0", "which-module": "^2.0.0", "y18n": "^4.0.0", - "yargs-parser": "^18.1.1" + "yargs-parser": "^18.1.2" } }, "yargs-parser": { @@ -1549,6 +1597,13 @@ "requires": { "camelcase": "^5.0.0", "decamelize": "^1.2.0" + }, + "dependencies": { + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" + } } } } diff --git a/package.json b/package.json index 8c5a1e4..97cd39e 100644 --- a/package.json +++ b/package.json @@ -30,11 +30,11 @@ "@types/node": "^12.12.47", "@types/triple-beam": "^1.3.1", "@types/yargs": "^15.0.5", - "@typescript-eslint/eslint-plugin": "^3.4.0", - "@typescript-eslint/parser": "^3.4.0", - "eslint": "^7.3.1", + "@typescript-eslint/eslint-plugin": "^3.5.0", + "@typescript-eslint/parser": "^3.5.0", + "eslint": "^7.4.0", "rimraf": "^3.0.2", - "typescript": "^3.9.5" + "typescript": "^3.9.6" }, "dependencies": { "axios": "^0.19.2", @@ -46,6 +46,6 @@ "toml": "^3.0.0", "triple-beam": "^1.3.0", "winston": "^3.3.3", - "yargs": "^15.3.1" + "yargs": "^15.4.0" } } diff --git a/src/model/struct/model/module/forgemod.struct.ts b/src/model/struct/model/module/forgemod.struct.ts index a5ac90b..8e1f2b3 100644 --- a/src/model/struct/model/module/forgemod.struct.ts +++ b/src/model/struct/model/module/forgemod.struct.ts @@ -3,10 +3,10 @@ import { Type } from 'helios-distribution-types' import { join } from 'path' import { resolve } from 'url' import { VersionSegmented } from '../../../../util/VersionSegmented' -import { ModuleStructure } from './module.struct' import { MinecraftVersion } from '../../../../util/MinecraftVersion' +import { ToggleableModuleStructure } from './toggleablemodule.struct' -export abstract class BaseForgeModStructure extends ModuleStructure implements VersionSegmented { +export abstract class BaseForgeModStructure extends ToggleableModuleStructure implements VersionSegmented { protected readonly EXAMPLE_MOD_ID = 'examplemod' @@ -22,7 +22,7 @@ export abstract class BaseForgeModStructure extends ModuleStructure implements V // eslint-disable-next-line @typescript-eslint/no-unused-vars protected async getModuleUrl(name: string, path: string, stats: Stats): Promise { - return resolve(this.baseUrl, join(this.relativeRoot, name)) + return resolve(this.baseUrl, join(this.relativeRoot, this.getActiveNamespace(), name)) } // eslint-disable-next-line @typescript-eslint/no-unused-vars protected async getModulePath(name: string, path: string, stats: Stats): Promise { diff --git a/src/model/struct/model/module/litemod.struct.ts b/src/model/struct/model/module/litemod.struct.ts index e1c0826..1c88a5d 100644 --- a/src/model/struct/model/module/litemod.struct.ts +++ b/src/model/struct/model/module/litemod.struct.ts @@ -5,9 +5,9 @@ import { join } from 'path' import { resolve } from 'url' import { capitalize } from '../../../../util/stringutils' import { LiteMod } from '../../../liteloader/litemod' -import { ModuleStructure } from './module.struct' +import { ToggleableModuleStructure } from './toggleablemodule.struct' -export class LiteModStructure extends ModuleStructure { +export class LiteModStructure extends ToggleableModuleStructure { private liteModMetadata: {[property: string]: LiteMod | undefined} = {} @@ -28,7 +28,7 @@ export class LiteModStructure extends ModuleStructure { } // eslint-disable-next-line @typescript-eslint/no-unused-vars protected async getModuleUrl(name: string, path: string, stats: Stats): Promise { - return resolve(this.baseUrl, join(this.relativeRoot, name)) + return resolve(this.baseUrl, join(this.relativeRoot, this.getActiveNamespace(), name)) } // eslint-disable-next-line @typescript-eslint/no-unused-vars protected async getModulePath(name: string, path: string, stats: Stats): Promise { diff --git a/src/model/struct/model/module/module.struct.ts b/src/model/struct/model/module/module.struct.ts index ab9c286..8e1f940 100644 --- a/src/model/struct/model/module/module.struct.ts +++ b/src/model/struct/model/module/module.struct.ts @@ -22,7 +22,7 @@ export abstract class ModuleStructure extends BaseModelStructure { public async getSpecModel(): Promise { if (this.resolvedModels == null) { - this.resolvedModels = await this._doModuleRetrieval() + this.resolvedModels = await this._doModuleRetrieval(this.containerDirectory) } return this.resolvedModels @@ -58,10 +58,6 @@ export abstract class ModuleStructure extends BaseModelStructure { id: await this.getModuleId(file, filePath), name: await this.getModuleName(file, filePath), type: this.type, - required: { - value: false, - def: false - }, artifact: { size: stats.size, MD5: createHash('md5').update(buf).digest('hex'), @@ -75,14 +71,14 @@ export abstract class ModuleStructure extends BaseModelStructure { return mdl } - private async _doModuleRetrieval(): Promise { + protected async _doModuleRetrieval(scanDirectory: string): Promise { const accumulator: Module[] = [] - if (await pathExists(this.containerDirectory)) { - const files = await readdir(this.containerDirectory) + if (await pathExists(scanDirectory)) { + const files = await readdir(scanDirectory) for (const file of files) { - const filePath = resolve(this.containerDirectory, file) + const filePath = resolve(scanDirectory, file) const stats = await lstat(filePath) if (stats.isFile()) { if(this.filter == null || this.filter(file, filePath, stats)) { diff --git a/src/model/struct/model/module/toggleablemodule.struct.ts b/src/model/struct/model/module/toggleablemodule.struct.ts new file mode 100644 index 0000000..169f8e2 --- /dev/null +++ b/src/model/struct/model/module/toggleablemodule.struct.ts @@ -0,0 +1,68 @@ +import { ModuleStructure } from './module.struct' +import { Type, Module } from 'helios-distribution-types' +import { Stats, mkdirs } from 'fs-extra' +import { resolve } from 'path' + +export enum ToggleableNamespace { + + REQUIRED = 'required', + OPTIONAL_ON = 'optionalon', + OPTIONAL_OFF = 'optionaloff' + +} + +export abstract class ToggleableModuleStructure extends ModuleStructure { + + private activeNamespace: string | undefined + + constructor( + absoluteRoot: string, + relativeRoot: string, + structRoot: string, + baseUrl: string, + protected type: Type, + protected filter?: ((name: string, path: string, stats: Stats) => boolean) + ) { + super(absoluteRoot, relativeRoot, structRoot, baseUrl, type, filter) + } + + public async init(): Promise { + await super.init() + for(const namespace of Object.values(ToggleableNamespace)) { + await mkdirs(resolve(this.containerDirectory, namespace)) + } + } + + public async getSpecModel(): Promise { + if (this.resolvedModels == null) { + + this.resolvedModels = [] + for(const value of Object.values(ToggleableNamespace)) { + this.activeNamespace = value + const models = await this._doModuleRetrieval(resolve(this.containerDirectory, value)) + models.forEach(this.getNamespaceMapper(value)) + this.resolvedModels = this.resolvedModels.concat(models) + } + this.activeNamespace = undefined + + } + + return this.resolvedModels + } + + protected getActiveNamespace(): string { + return this.activeNamespace || '' + } + + protected getNamespaceMapper(namespace: ToggleableNamespace): (x: Module) => void { + switch(namespace) { + case ToggleableNamespace.REQUIRED: + return () => { /* do nothing */ } + case ToggleableNamespace.OPTIONAL_ON: + return (x) => x.required = { value: false } + case ToggleableNamespace.OPTIONAL_OFF: + return (x) => x.required = { value: false, def: false } + } + } + +} \ No newline at end of file