@yongdall/configuration 0.1.0 → 0.1.1
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/index.d.mts +8 -1
- package/index.mjs +14 -4
- package/index.mjs.map +1 -1
- package/package.json +1 -1
package/index.d.mts
CHANGED
|
@@ -2,12 +2,19 @@ import { Tenant } from "@yongdall/types";
|
|
|
2
2
|
import { assetsRoot, configRoot, projectRoot } from "@yongdall/root";
|
|
3
3
|
|
|
4
4
|
//#region cli/configuration/index.d.mts
|
|
5
|
+
/**
|
|
6
|
+
* @template {object} T
|
|
7
|
+
* @param {string} name
|
|
8
|
+
* @returns {Promise<[string, T] | null>}
|
|
9
|
+
*/
|
|
10
|
+
declare function loadCfgWithPath<T extends object>(name: string): Promise<[string, T] | null>;
|
|
5
11
|
/**
|
|
6
12
|
* @template {object} T
|
|
7
13
|
* @param {string} name
|
|
8
14
|
* @returns {Promise<T | null>}
|
|
9
15
|
*/
|
|
10
16
|
declare function loadCfg<T extends object>(name: string): Promise<T | null>;
|
|
17
|
+
declare const configurationPath: string;
|
|
11
18
|
/** @type {Omit<Tenant, 'id'>} */
|
|
12
19
|
declare const tenant: Omit<Tenant, "id">;
|
|
13
20
|
declare const boot: object;
|
|
@@ -41,4 +48,4 @@ declare namespace configuration {
|
|
|
41
48
|
let plugins: Record<string, string | boolean> | undefined;
|
|
42
49
|
}
|
|
43
50
|
//#endregion
|
|
44
|
-
export { Configuration, assetsRoot, boot, configRoot, configuration as default, loadCfg, projectRoot, tenant };
|
|
51
|
+
export { Configuration, assetsRoot, boot, configRoot, configurationPath, configuration as default, loadCfg, loadCfgWithPath, projectRoot, tenant };
|
package/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as pathFn from "node:path";
|
|
2
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";
|
|
3
|
+
import { assetsRoot, configRoot, configRoot as configRoot$1, configurationPath as configurationPath$1, projectRoot } from "@yongdall/root";
|
|
4
|
+
import loadConfiguration, { loadConfigurationWithPath } from "@yongdall/load-configuration";
|
|
5
5
|
|
|
6
6
|
//#region cli/configuration/index.mjs
|
|
7
7
|
/** @import { Tenant } from '@yongdall/types' */
|
|
@@ -13,8 +13,18 @@ import loadConfiguration from "@yongdall/load-configuration";
|
|
|
13
13
|
* @prop {boolean} [single] 单用户模式
|
|
14
14
|
* @prop {Record<string, string | boolean>} [plugins] 插件
|
|
15
15
|
*/
|
|
16
|
+
const r = await loadConfigurationWithPath(configurationPath$1).catch(() => {});
|
|
17
|
+
const configurationPath = r?.[0] || configurationPath$1;
|
|
16
18
|
/** 全局配置 */
|
|
17
|
-
const configuration =
|
|
19
|
+
const configuration = r?.[1] || {};
|
|
20
|
+
/**
|
|
21
|
+
* @template {object} T
|
|
22
|
+
* @param {string} name
|
|
23
|
+
* @returns {Promise<[string, T] | null>}
|
|
24
|
+
*/
|
|
25
|
+
async function loadCfgWithPath(name) {
|
|
26
|
+
return loadConfigurationWithPath(pathFn.resolve(configRoot$1, name));
|
|
27
|
+
}
|
|
18
28
|
/**
|
|
19
29
|
* @template {object} T
|
|
20
30
|
* @param {string} name
|
|
@@ -34,5 +44,5 @@ const boot = await loadCfg("boot") || {};
|
|
|
34
44
|
var configuration_default = configuration;
|
|
35
45
|
|
|
36
46
|
//#endregion
|
|
37
|
-
export { assetsRoot, boot, configRoot, configuration_default as default, loadCfg, projectRoot, tenant };
|
|
47
|
+
export { assetsRoot, boot, configRoot, configurationPath, configuration_default as default, loadCfg, loadCfgWithPath, projectRoot, tenant };
|
|
38
48
|
//# sourceMappingURL=index.mjs.map
|
package/index.mjs.map
CHANGED
|
@@ -1 +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\
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["linkPath","configRoot"],"sources":["../../cli/configuration/index.mjs"],"sourcesContent":["import * as pathFn from 'node:path';\nimport * as fsPromises from 'node:fs/promises';\nimport loadConfiguration, { loadConfigurationWithPath } from '@yongdall/load-configuration';\nexport { projectRoot, configRoot, assetsRoot } from '@yongdall/root';\nimport { configurationPath as linkPath, 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 */\nconst r = await loadConfigurationWithPath(linkPath).catch(() => {})\n\nexport const configurationPath = r?.[0] || linkPath;\n/** 全局配置 */\nconst configuration = /** @type {Configuration} */(r?.[1] || {});\n\n\n\n/**\n * @template {object} T\n * @param {string} name \n * @returns {Promise<[string, T] | null>}\n */\nexport async function loadCfgWithPath(name) {\n\tlet path = pathFn.resolve(configRoot, name);\n\treturn loadConfigurationWithPath(path);\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":";;;;;;;;;;;;;;;AAeA,MAAM,IAAI,MAAM,0BAA0BA,oBAAS,CAAC,YAAY,GAAG;AAEnE,MAAa,oBAAoB,IAAI,MAAMA;;AAE3C,MAAM,gBAA6C,IAAI,MAAM,EAAE;;;;;;AAS/D,eAAsB,gBAAgB,MAAM;AAE3C,QAAO,0BADI,OAAO,QAAQC,cAAY,KAAK,CACL;;;;;;;AASvC,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"}
|