@yongdall/configuration 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin.mjs ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ //#region cli/configuration/bin.mjs
3
+ console.log("@yongdall/configuration");
4
+
5
+ //#endregion
6
+ //# sourceMappingURL=bin.mjs.map
package/bin.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.mjs","names":[],"sources":["../../cli/configuration/bin.mjs"],"sourcesContent":["#!/usr/bin/env node\n\nconsole.log('@yongdall/configuration')\n"],"mappings":";;AAEA,QAAQ,IAAI,0BAA0B"}
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ import * as pathFn from "node:path";
3
+ import * as fsPromises from "node:fs/promises";
4
+ import { generateKey } from "node:crypto";
5
+ import { configRoot } from "@yongdall/root";
6
+
7
+ //#region cli/configuration/generateSalt.mjs
8
+ const path = pathFn.resolve(configRoot, "salt");
9
+ /**
10
+ *
11
+ * @param {string[]} options
12
+ * @returns {Promise<void>}
13
+ */
14
+ async function generateSalt(options) {
15
+ if (!(options.includes("--force") || options.includes("-f")) && await fsPromises.stat(path).catch(() => null)) {
16
+ console.error("salt 已经存在,如果希望重新生成,请添加 --force 参数");
17
+ console.warn("[WARN] 重新生成将会导致所有用户退出登陆,并导致所有用户密码失效");
18
+ return;
19
+ }
20
+ /** @type {Uint8Array} */
21
+ const key = await new Promise((resolve, reject) => {
22
+ generateKey("hmac", { length: 512 }, (err, key) => {
23
+ if (err) return reject(err);
24
+ resolve(key.export());
25
+ });
26
+ });
27
+ await fsPromises.writeFile(path, key);
28
+ console.error("salt 生成完成");
29
+ }
30
+ generateSalt(process.argv.slice(2));
31
+
32
+ //#endregion
33
+ export { generateSalt as default };
34
+ //# sourceMappingURL=generateSalt.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateSalt.mjs","names":[],"sources":["../../cli/configuration/generateSalt.mjs"],"sourcesContent":["#!/usr/bin/env node\nimport * as pathFn from 'node:path';\nimport * as fsPromises from 'node:fs/promises';\nimport { generateKey } from 'node:crypto';\nimport { configRoot } from '@yongdall/root';\n\nconst path = pathFn.resolve(configRoot, 'salt');\n\n/**\n * \n * @param {string[]} options \n * @returns {Promise<void>}\n */\nexport default async function generateSalt(options) {\n\tconst force = options.includes('--force') || options.includes('-f');\n\tif (!force && await fsPromises.stat(path).catch(() => null)) {\n\t\tconsole.error('salt 已经存在,如果希望重新生成,请添加 --force 参数');\n\t\tconsole.warn('[WARN] 重新生成将会导致所有用户退出登陆,并导致所有用户密码失效');\n\t\treturn;\n\t}\n\t/** @type {Uint8Array} */\n\tconst key = await new Promise((resolve, reject) => {\n\t\tgenerateKey('hmac', { length: 512 }, (err, key) => {\n\t\t\tif (err) { return reject(err); }\n\t\t\tresolve(key.export());\n\t\t});\n\t});\n\tawait fsPromises.writeFile(path, key);\n\tconsole.error('salt 生成完成');\n}\ngenerateSalt(process.argv.slice(2));\n"],"mappings":";;;;;;;AAMA,MAAM,OAAO,OAAO,QAAQ,YAAY,OAAO;;;;;;AAO/C,eAA8B,aAAa,SAAS;AAEnD,KAAI,EADU,QAAQ,SAAS,UAAU,IAAI,QAAQ,SAAS,KAAK,KACrD,MAAM,WAAW,KAAK,KAAK,CAAC,YAAY,KAAK,EAAE;AAC5D,UAAQ,MAAM,oCAAoC;AAClD,UAAQ,KAAK,sCAAsC;AACnD;;;CAGD,MAAM,MAAM,MAAM,IAAI,SAAS,SAAS,WAAW;AAClD,cAAY,QAAQ,EAAE,QAAQ,KAAK,GAAG,KAAK,QAAQ;AAClD,OAAI,IAAO,QAAO,OAAO,IAAI;AAC7B,WAAQ,IAAI,QAAQ,CAAC;IACpB;GACD;AACF,OAAM,WAAW,UAAU,MAAM,IAAI;AACrC,SAAQ,MAAM,YAAY;;AAE3B,aAAa,QAAQ,KAAK,MAAM,EAAE,CAAC"}
package/index.d.mts ADDED
@@ -0,0 +1,44 @@
1
+ import { Tenant } from "@yongdall/types";
2
+ import { assetsRoot, configRoot, projectRoot } from "@yongdall/root";
3
+
4
+ //#region cli/configuration/index.d.mts
5
+ /**
6
+ * @template {object} T
7
+ * @param {string} name
8
+ * @returns {Promise<T | null>}
9
+ */
10
+ declare function loadCfg<T extends object>(name: string): Promise<T | null>;
11
+ /** @type {Omit<Tenant, 'id'>} */
12
+ declare const tenant: Omit<Tenant, "id">;
13
+ declare const boot: object;
14
+ type Configuration = {
15
+ /**
16
+ * 启动模块
17
+ */
18
+ bootModule?: string | undefined;
19
+ /**
20
+ * 启动模块配置名称
21
+ */
22
+ bootName?: string | undefined;
23
+ /**
24
+ * 网站名称
25
+ */
26
+ title?: string | undefined;
27
+ /**
28
+ * 单用户模式
29
+ */
30
+ single?: boolean | undefined;
31
+ /**
32
+ * 插件
33
+ */
34
+ plugins?: Record<string, string | boolean> | undefined;
35
+ };
36
+ declare namespace configuration {
37
+ let bootModule: string | undefined;
38
+ let bootName: string | undefined;
39
+ let title: string | undefined;
40
+ let single: boolean | undefined;
41
+ let plugins: Record<string, string | boolean> | undefined;
42
+ }
43
+ //#endregion
44
+ export { Configuration, assetsRoot, boot, configRoot, configuration as default, loadCfg, projectRoot, tenant };
package/index.mjs ADDED
@@ -0,0 +1,38 @@
1
+ import * as pathFn from "node:path";
2
+ import * as fsPromises from "node:fs/promises";
3
+ import { assetsRoot, configRoot, configRoot as configRoot$1, configurationPath, projectRoot } from "@yongdall/root";
4
+ import loadConfiguration from "@yongdall/load-configuration";
5
+
6
+ //#region cli/configuration/index.mjs
7
+ /** @import { Tenant } from '@yongdall/types' */
8
+ /**
9
+ * @typedef {object} Configuration
10
+ * @prop {string} [bootModule] 启动模块
11
+ * @prop {string} [bootName] 启动模块配置名称
12
+ * @prop {string} [title] 网站名称
13
+ * @prop {boolean} [single] 单用户模式
14
+ * @prop {Record<string, string | boolean>} [plugins] 插件
15
+ */
16
+ /** 全局配置 */
17
+ const configuration = await loadConfiguration(configurationPath).catch(() => {}) || {};
18
+ /**
19
+ * @template {object} T
20
+ * @param {string} name
21
+ * @returns {Promise<T | null>}
22
+ */
23
+ async function loadCfg(name) {
24
+ return loadConfiguration(pathFn.resolve(configRoot$1, name));
25
+ }
26
+ /** @type {Omit<Tenant, 'id'>} */
27
+ const tenant = {
28
+ label: configuration.title || "拥道YongDall",
29
+ single: Boolean(configuration.single),
30
+ providers: await loadCfg("providers").catch(() => {}).then((v) => v || {}),
31
+ salt: await fsPromises.readFile(pathFn.resolve(configRoot$1, "salt"))
32
+ };
33
+ const boot = await loadCfg("boot") || {};
34
+ var configuration_default = configuration;
35
+
36
+ //#endregion
37
+ export { assetsRoot, boot, configRoot, configuration_default as default, loadCfg, projectRoot, tenant };
38
+ //# sourceMappingURL=index.mjs.map
package/index.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["configRoot"],"sources":["../../cli/configuration/index.mjs"],"sourcesContent":["import * as pathFn from 'node:path';\nimport * as fsPromises from 'node:fs/promises';\nimport loadConfiguration from '@yongdall/load-configuration';\nexport { projectRoot, configRoot, assetsRoot } from '@yongdall/root';\nimport { configurationPath, configRoot } from '@yongdall/root';\n/** @import { Tenant } from '@yongdall/types' */\n\n/**\n * @typedef {object} Configuration\n * @prop {string} [bootModule] 启动模块\n * @prop {string} [bootName] 启动模块配置名称\n * @prop {string} [title] 网站名称\n * @prop {boolean} [single] 单用户模式\n * @prop {Record<string, string | boolean>} [plugins] 插件\n */\n\n/** 全局配置 */\nconst configuration = /** @type {Configuration} */(\n\tawait loadConfiguration(configurationPath).catch(() => {}) || {}\n);\n\n\n/**\n * @template {object} T\n * @param {string} name \n * @returns {Promise<T | null>}\n */\nexport async function loadCfg(name) {\n\tlet path = pathFn.resolve(configRoot, name);\n\treturn loadConfiguration(path);\n}\n\n/** @type {Omit<Tenant, 'id'>} */\nexport const tenant = {\n\tlabel: configuration.title || '拥道YongDall',\n\tsingle: Boolean(configuration.single),\n\tproviders: await loadCfg('providers').catch(() => {}).then(v => /** @type {Record<string, string>} */(v || {})),\n\tsalt: await fsPromises.readFile(pathFn.resolve(configRoot, 'salt'))\n};\n\nexport const boot = await loadCfg('boot') || {};\n\nexport default configuration;\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,MAAM,gBACL,MAAM,kBAAkB,kBAAkB,CAAC,YAAY,GAAG,IAAI,EAAE;;;;;;AASjE,eAAsB,QAAQ,MAAM;AAEnC,QAAO,kBADI,OAAO,QAAQA,cAAY,KAAK,CACb;;;AAI/B,MAAa,SAAS;CACrB,OAAO,cAAc,SAAS;CAC9B,QAAQ,QAAQ,cAAc,OAAO;CACrC,WAAW,MAAM,QAAQ,YAAY,CAAC,YAAY,GAAG,CAAC,MAAK,MAA2C,KAAK,EAAE,CAAE;CAC/G,MAAM,MAAM,WAAW,SAAS,OAAO,QAAQA,cAAY,OAAO,CAAC;CACnE;AAED,MAAa,OAAO,MAAM,QAAQ,OAAO,IAAI,EAAE;AAE/C,4BAAe"}
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@yongdall/configuration",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "bin": {
6
+ "configuration.yongdall": "./bin.mjs",
7
+ "generate-salt.yongdall": "./generateSalt.mjs"
8
+ },
9
+ "main": "./index.mjs",
10
+ "imports": {
11
+ "#index": "./index.mjs"
12
+ },
13
+ "dependencies": {
14
+ "@yongdall/load-configuration": "^0.1.0",
15
+ "@yongdall/root": "^0.1.0"
16
+ },
17
+ "devDependencies": {
18
+ "@yongdall/types": "^0.1.0"
19
+ },
20
+ "exports": {
21
+ ".": "./index.mjs"
22
+ }
23
+ }