@yongdall/configuration 0.1.1 → 0.3.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/cli/generate-salt.mjs +26 -0
- package/cli/generate-salt.mjs.map +1 -0
- package/cli/yongdall.yml +4 -0
- package/createSalt.mjs +19 -0
- package/createSalt.mjs.map +1 -0
- package/generateSalt.mjs +2 -8
- package/generateSalt.mjs.map +1 -1
- package/index.d.mts +7 -14
- package/index.mjs +23 -16
- package/index.mjs.map +1 -1
- package/package.json +6 -4
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as pathFn from "node:path";
|
|
2
|
+
import * as fsPromises from "node:fs/promises";
|
|
3
|
+
import createSalt from "#createSalt";
|
|
4
|
+
import { configRoot } from "@yongdall/root";
|
|
5
|
+
|
|
6
|
+
//#region cli/configuration/cli/generate-salt.mjs
|
|
7
|
+
/** @import { Cli } from '@yongdall/cli-parse' */
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {Cli.Env} env
|
|
11
|
+
*/
|
|
12
|
+
async function generate_salt_default({ force }) {
|
|
13
|
+
const path = pathFn.resolve(configRoot, "salt");
|
|
14
|
+
if (!force && await fsPromises.stat(path).catch(() => null)) {
|
|
15
|
+
console.error("salt 已经存在,如果希望重新生成,请添加 --force 参数");
|
|
16
|
+
console.warn("[WARN] 重新生成将会导致所有用户退出登陆,并导致所有用户密码失效");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const key = await createSalt();
|
|
20
|
+
await fsPromises.writeFile(path, key);
|
|
21
|
+
console.error("salt 生成完成");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { generate_salt_default as default };
|
|
26
|
+
//# sourceMappingURL=generate-salt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-salt.mjs","names":[],"sources":["../../../cli/configuration/cli/generate-salt.mjs"],"sourcesContent":["import * as pathFn from 'node:path';\nimport * as fsPromises from 'node:fs/promises';\nimport createSalt from '#createSalt';\nimport { configRoot } from '@yongdall/root';\n/** @import { Cli } from '@yongdall/cli-parse' */\n\n/**\n * \n * @param {Cli.Env} env \n */\nexport default async function ({ force }) {\n\n\tconst path = pathFn.resolve(configRoot, 'salt');\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\tconst key = await createSalt()\n\tawait fsPromises.writeFile(path, key);\n\tconsole.error('salt 生成完成');\n}\n"],"mappings":";;;;;;;;;;;AAUA,qCAA+B,EAAE,SAAS;CAEzC,MAAM,OAAO,OAAO,QAAQ,YAAY,OAAO;AAC/C,KAAI,CAAC,SAAS,MAAM,WAAW,KAAK,KAAK,CAAC,YAAY,KAAK,EAAE;AAC5D,UAAQ,MAAM,oCAAoC;AAClD,UAAQ,KAAK,sCAAsC;AACnD;;CAED,MAAM,MAAM,MAAM,YAAY;AAC9B,OAAM,WAAW,UAAU,MAAM,IAAI;AACrC,SAAQ,MAAM,YAAY"}
|
package/cli/yongdall.yml
ADDED
package/createSalt.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { generateKey } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
//#region cli/configuration/createSalt.mjs
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @returns {Promise<Uint8Array<ArrayBuffer>>}
|
|
7
|
+
*/
|
|
8
|
+
async function createSalt() {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
generateKey("hmac", { length: 512 }, (err, key) => {
|
|
11
|
+
if (err) return reject(err);
|
|
12
|
+
resolve(key.export());
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { createSalt as default };
|
|
19
|
+
//# sourceMappingURL=createSalt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSalt.mjs","names":[],"sources":["../../cli/configuration/createSalt.mjs"],"sourcesContent":["import { generateKey } from 'node:crypto';\n\n/**\n * \n * @returns {Promise<Uint8Array<ArrayBuffer>>}\n */\nexport default async function createSalt() {\n\treturn 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}\n"],"mappings":";;;;;;;AAMA,eAA8B,aAAa;AAC1C,QAAO,IAAI,SAAS,SAAS,WAAW;AACvC,cAAY,QAAQ,EAAE,QAAQ,KAAK,GAAG,KAAK,QAAQ;AAClD,OAAI,IAAO,QAAO,OAAO,IAAI;AAC7B,WAAQ,IAAI,QAAQ,CAAC;IACpB;GACD"}
|
package/generateSalt.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import * as pathFn from "node:path";
|
|
3
3
|
import * as fsPromises from "node:fs/promises";
|
|
4
|
-
import
|
|
4
|
+
import createSalt from "#createSalt";
|
|
5
5
|
import { configRoot } from "@yongdall/root";
|
|
6
6
|
|
|
7
7
|
//#region cli/configuration/generateSalt.mjs
|
|
@@ -17,13 +17,7 @@ async function generateSalt(options) {
|
|
|
17
17
|
console.warn("[WARN] 重新生成将会导致所有用户退出登陆,并导致所有用户密码失效");
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
|
|
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
|
-
});
|
|
20
|
+
const key = await createSalt();
|
|
27
21
|
await fsPromises.writeFile(path, key);
|
|
28
22
|
console.error("salt 生成完成");
|
|
29
23
|
}
|
package/generateSalt.mjs.map
CHANGED
|
@@ -1 +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
|
|
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 createSalt from '#createSalt';\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\tconst key = await createSalt()\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;;CAED,MAAM,MAAM,MAAM,YAAY;AAC9B,OAAM,WAAW,UAAU,MAAM,IAAI;AACrC,SAAQ,MAAM,YAAY;;AAE3B,aAAa,QAAQ,KAAK,MAAM,EAAE,CAAC"}
|
package/index.d.mts
CHANGED
|
@@ -2,22 +2,22 @@ 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
|
|
8
|
-
* @returns {Promise<[string, T] | null>}
|
|
10
|
+
* @returns {Promise<[string, T | null] | null>}
|
|
9
11
|
*/
|
|
10
|
-
declare function loadCfgWithPath<T extends object>(name: string): Promise<[string, T] | null>;
|
|
12
|
+
declare function loadCfgWithPath<T extends object>(name: string): Promise<[string, T | null] | null>;
|
|
11
13
|
/**
|
|
12
14
|
* @template {object} T
|
|
13
15
|
* @param {string} name
|
|
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,14 +13,20 @@ 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
|
|
23
|
-
* @returns {Promise<[string, T] | null>}
|
|
29
|
+
* @returns {Promise<[string, T | null] | null>}
|
|
24
30
|
*/
|
|
25
31
|
async function loadCfgWithPath(name) {
|
|
26
32
|
return loadConfigurationWithPath(pathFn.resolve(configRoot$1, 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.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"configuration.yongdall": "./bin.mjs",
|
|
@@ -8,14 +8,16 @@
|
|
|
8
8
|
},
|
|
9
9
|
"main": "./index.mjs",
|
|
10
10
|
"imports": {
|
|
11
|
+
"#createSalt": "./createSalt.mjs",
|
|
11
12
|
"#index": "./index.mjs"
|
|
12
13
|
},
|
|
13
14
|
"dependencies": {
|
|
14
|
-
"@yongdall/load-configuration": "^0.
|
|
15
|
-
"@yongdall/root": "^0.
|
|
15
|
+
"@yongdall/load-configuration": "^0.3.0",
|
|
16
|
+
"@yongdall/root": "^0.3.0"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
|
-
"@yongdall/
|
|
19
|
+
"@yongdall/cli-parse": "^0.3.0",
|
|
20
|
+
"@yongdall/types": "^0.3.0"
|
|
19
21
|
},
|
|
20
22
|
"exports": {
|
|
21
23
|
".": "./index.mjs"
|