@yongdall/configuration 0.2.0 → 0.4.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/index.d.mts +5 -12
- package/index.mjs +22 -15
- package/index.mjs.map +1 -1
- package/package.json +5 -5
package/index.d.mts
CHANGED
|
@@ -2,6 +2,8 @@ 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
|
+
declare function loadProjectConfiguration(): Promise<Configuration>;
|
|
6
|
+
declare function loadProjectConfigurationPath(): Promise<string>;
|
|
5
7
|
/**
|
|
6
8
|
* @template {object} T
|
|
7
9
|
* @param {string} name
|
|
@@ -14,10 +16,8 @@ declare function loadCfgWithPath<T extends object>(name: string): Promise<[strin
|
|
|
14
16
|
* @returns {Promise<T | null>}
|
|
15
17
|
*/
|
|
16
18
|
declare function loadCfg<T extends object>(name: string): Promise<T | null>;
|
|
17
|
-
declare
|
|
18
|
-
|
|
19
|
-
declare const tenant: Omit<Tenant, "id">;
|
|
20
|
-
declare const boot: object;
|
|
19
|
+
declare function loadTenant(): Promise<Omit<Tenant, "id">>;
|
|
20
|
+
declare function loadBoot(): Promise<object>;
|
|
21
21
|
type Configuration = {
|
|
22
22
|
/**
|
|
23
23
|
* 启动模块
|
|
@@ -40,12 +40,5 @@ type Configuration = {
|
|
|
40
40
|
*/
|
|
41
41
|
plugins?: Record<string, string | boolean> | undefined;
|
|
42
42
|
};
|
|
43
|
-
declare namespace configuration {
|
|
44
|
-
let bootModule: string | undefined;
|
|
45
|
-
let bootName: string | undefined;
|
|
46
|
-
let title: string | undefined;
|
|
47
|
-
let single: boolean | undefined;
|
|
48
|
-
let plugins: Record<string, string | boolean> | undefined;
|
|
49
|
-
}
|
|
50
43
|
//#endregion
|
|
51
|
-
export { Configuration, assetsRoot,
|
|
44
|
+
export { Configuration, assetsRoot, configRoot, loadBoot, loadCfg, loadCfgWithPath, loadProjectConfiguration, loadProjectConfigurationPath, loadTenant, projectRoot };
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
|
|
3
|
+
import { assetsRoot, configRoot, configRoot as configRoot$1, configurationPath, projectRoot } from "@yongdall/root";
|
|
4
4
|
import loadConfiguration, { loadConfigurationWithPath } from "@yongdall/load-configuration";
|
|
5
5
|
|
|
6
6
|
//#region cli/configuration/index.mjs
|
|
@@ -13,10 +13,16 @@ import loadConfiguration, { loadConfigurationWithPath } from "@yongdall/load-con
|
|
|
13
13
|
* @prop {boolean} [single] 单用户模式
|
|
14
14
|
* @prop {Record<string, string | boolean>} [plugins] 插件
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
/** @type {Promise<[string, object | null]?>?} */
|
|
17
|
+
let projectConfigurationPromise = null;
|
|
18
|
+
async function loadProjectConfiguration() {
|
|
19
|
+
projectConfigurationPromise ||= loadConfigurationWithPath(configurationPath).catch(() => null);
|
|
20
|
+
return projectConfigurationPromise.then((r) => r?.[1] || {});
|
|
21
|
+
}
|
|
22
|
+
async function loadProjectConfigurationPath() {
|
|
23
|
+
projectConfigurationPromise ||= loadConfigurationWithPath(configurationPath).catch(() => null);
|
|
24
|
+
return projectConfigurationPromise.then((r) => r?.[0] || configurationPath);
|
|
25
|
+
}
|
|
20
26
|
/**
|
|
21
27
|
* @template {object} T
|
|
22
28
|
* @param {string} name
|
|
@@ -33,16 +39,17 @@ async function loadCfgWithPath(name) {
|
|
|
33
39
|
async function loadCfg(name) {
|
|
34
40
|
return loadConfiguration(pathFn.resolve(configRoot$1, name));
|
|
35
41
|
}
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
async function loadTenant() {
|
|
43
|
+
const configuration = await loadProjectConfiguration();
|
|
44
|
+
return {
|
|
45
|
+
label: configuration.title || "拥道YongDall",
|
|
46
|
+
single: Boolean(configuration.single),
|
|
47
|
+
providers: await loadCfg("providers").catch(() => {}).then((v) => v || {}),
|
|
48
|
+
salt: await fsPromises.readFile(pathFn.resolve(configRoot$1, "salt"))
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const loadBoot = async () => await loadCfg("boot") || {};
|
|
45
52
|
|
|
46
53
|
//#endregion
|
|
47
|
-
export { assetsRoot,
|
|
54
|
+
export { assetsRoot, configRoot, loadBoot, loadCfg, loadCfgWithPath, loadProjectConfiguration, loadProjectConfigurationPath, loadTenant, projectRoot };
|
|
48
55
|
//# sourceMappingURL=index.mjs.map
|
package/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 */\
|
|
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 */\n\n/** @type {Promise<[string, object | null]?>?} */\nlet projectConfigurationPromise = null;\nexport async function loadProjectConfiguration() {\n\tprojectConfigurationPromise ||= loadConfigurationWithPath(linkPath).catch(() => null);\n\treturn projectConfigurationPromise.then(r => /** @type {Configuration} */(r?.[1] || {}));\n}\nexport async function loadProjectConfigurationPath() {\n\tprojectConfigurationPromise ||= loadConfigurationWithPath(linkPath).catch(() => null);\n\treturn projectConfigurationPromise.then(r => r?.[0] || linkPath);\n}\n\n/**\n * @template {object} T\n * @param {string} name \n * @returns {Promise<[string, T | null] | 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\nexport async function loadTenant() {\n\tconst configuration = await loadProjectConfiguration();\n\t/** @type {Omit<Tenant, 'id'>} */\n\tconst tenant = {\n\t\tlabel: configuration.title || '拥道YongDall',\n\t\tsingle: Boolean(configuration.single),\n\t\tproviders: await loadCfg('providers').catch(() => { }).then(v => /** @type {Record<string, string>} */(v || {})),\n\t\tsalt: await fsPromises.readFile(pathFn.resolve(configRoot, 'salt'))\n\t};\n\treturn tenant;\n}\n\nexport const loadBoot = async () => await loadCfg('boot') || {};\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,IAAI,8BAA8B;AAClC,eAAsB,2BAA2B;AAChD,iCAAgC,0BAA0BA,kBAAS,CAAC,YAAY,KAAK;AACrF,QAAO,4BAA4B,MAAK,MAAkC,IAAI,MAAM,EAAE,CAAE;;AAEzF,eAAsB,+BAA+B;AACpD,iCAAgC,0BAA0BA,kBAAS,CAAC,YAAY,KAAK;AACrF,QAAO,4BAA4B,MAAK,MAAK,IAAI,MAAMA,kBAAS;;;;;;;AAQjE,eAAsB,gBAAgB,MAAM;AAE3C,QAAO,0BADI,OAAO,QAAQC,cAAY,KAAK,CACL;;;;;;;AASvC,eAAsB,QAAQ,MAAM;AAEnC,QAAO,kBADI,OAAO,QAAQA,cAAY,KAAK,CACb;;AAG/B,eAAsB,aAAa;CAClC,MAAM,gBAAgB,MAAM,0BAA0B;AAQtD,QANe;EACd,OAAO,cAAc,SAAS;EAC9B,QAAQ,QAAQ,cAAc,OAAO;EACrC,WAAW,MAAM,QAAQ,YAAY,CAAC,YAAY,GAAI,CAAC,MAAK,MAA2C,KAAK,EAAE,CAAE;EAChH,MAAM,MAAM,WAAW,SAAS,OAAO,QAAQA,cAAY,OAAO,CAAC;EACnE;;AAIF,MAAa,WAAW,YAAY,MAAM,QAAQ,OAAO,IAAI,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yongdall/configuration",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"configuration.yongdall": "./bin.mjs",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"#index": "./index.mjs"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@yongdall/load-configuration": "^0.
|
|
16
|
-
"@yongdall/root": "^0.
|
|
15
|
+
"@yongdall/load-configuration": "^0.4.0",
|
|
16
|
+
"@yongdall/root": "^0.4.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@yongdall/cli-parse": "^0.
|
|
20
|
-
"@yongdall/types": "^0.
|
|
19
|
+
"@yongdall/cli-parse": "^0.4.0",
|
|
20
|
+
"@yongdall/types": "^0.4.0"
|
|
21
21
|
},
|
|
22
22
|
"exports": {
|
|
23
23
|
".": "./index.mjs"
|