@yongdall/configuration 0.1.0 → 0.2.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 +8 -1
- package/index.mjs +14 -4
- 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,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] | null>}
|
|
9
|
+
*/
|
|
10
|
+
declare function loadCfgWithPath<T extends object>(name: string): Promise<[string, T | null] | 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] | 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] | 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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yongdall/configuration",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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.2.0",
|
|
16
|
+
"@yongdall/root": "^0.2.0"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
|
-
"@yongdall/
|
|
19
|
+
"@yongdall/cli-parse": "^0.2.0",
|
|
20
|
+
"@yongdall/types": "^0.2.0"
|
|
19
21
|
},
|
|
20
22
|
"exports": {
|
|
21
23
|
".": "./index.mjs"
|