@yongdall/plugins 0.1.1 → 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/index.d.mts +14 -1
- package/index.mjs +34 -1
- package/index.mjs.map +1 -1
- package/package.json +4 -3
package/index.d.mts
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
//#region cli/plugins/index.d.mts
|
|
2
|
+
/**
|
|
3
|
+
* @template {object} T
|
|
4
|
+
* @param {string} name
|
|
5
|
+
* @param {boolean} [scriptOnly]
|
|
6
|
+
* @returns {AsyncIterableIterator<[plugin: string, config: T | null, path: string]>}
|
|
7
|
+
*/
|
|
8
|
+
declare function loadPluginProfiles<T extends object>(name: string, scriptOnly?: boolean): AsyncIterableIterator<[plugin: string, config: T | null, path: string]>;
|
|
9
|
+
/**
|
|
10
|
+
* @template {object} T
|
|
11
|
+
* @param {string} name
|
|
12
|
+
* @returns {AsyncIterableIterator<[plugin: string, config: T]>}
|
|
13
|
+
*/
|
|
14
|
+
declare function loadPluginScripts<T extends object>(name: string): AsyncIterableIterator<[plugin: string, config: T]>;
|
|
2
15
|
/** @type {Record<string, {root: string; development: boolean}>} */
|
|
3
16
|
declare const pluginRoots: Record<string, {
|
|
4
17
|
root: string;
|
|
5
18
|
development: boolean;
|
|
6
19
|
}>;
|
|
7
20
|
//#endregion
|
|
8
|
-
export { pluginRoots as default };
|
|
21
|
+
export { pluginRoots as default, loadPluginProfiles, loadPluginScripts };
|
package/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import * as pathFn from "node:path";
|
|
|
2
2
|
import * as fsPromises from "node:fs/promises";
|
|
3
3
|
import { pluginIdRegex } from "@yongdall/common";
|
|
4
4
|
import configuration, { configurationPath, loadCfgWithPath } from "@yongdall/configuration";
|
|
5
|
+
import loadConfiguration, { loadConfigurationWithPath } from "@yongdall/load-configuration";
|
|
5
6
|
|
|
6
7
|
//#region cli/plugins/index.mjs
|
|
7
8
|
/** @type {Record<string, {root: string; development: boolean}>} */
|
|
@@ -54,7 +55,39 @@ for (const [plugin, define, basePath] of await getPlugins()) {
|
|
|
54
55
|
};
|
|
55
56
|
}
|
|
56
57
|
var plugins_default = pluginRoots;
|
|
58
|
+
/**
|
|
59
|
+
* @template {object} T
|
|
60
|
+
* @param {string} name
|
|
61
|
+
* @param {boolean} [scriptOnly]
|
|
62
|
+
* @returns {AsyncIterableIterator<[plugin: string, config: T | null, path: string]>}
|
|
63
|
+
*/
|
|
64
|
+
async function* loadPluginProfiles(name, scriptOnly) {
|
|
65
|
+
for (const [plugin, { root }] of Object.entries(pluginRoots)) {
|
|
66
|
+
/** @type {[string, T | null] | null} */
|
|
67
|
+
const result = await loadConfigurationWithPath(pathFn.resolve(root, `${name}.yongdall`), scriptOnly) || await loadConfigurationWithPath(pathFn.resolve(root, `yongdall/${name}`), scriptOnly) || await loadConfigurationWithPath(pathFn.resolve(root, `${name}/yongdall`), scriptOnly);
|
|
68
|
+
if (!result) continue;
|
|
69
|
+
const [path, config] = result;
|
|
70
|
+
yield [
|
|
71
|
+
plugin,
|
|
72
|
+
config,
|
|
73
|
+
path
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* @template {object} T
|
|
79
|
+
* @param {string} name
|
|
80
|
+
* @returns {AsyncIterableIterator<[plugin: string, config: T]>}
|
|
81
|
+
*/
|
|
82
|
+
async function* loadPluginScripts(name) {
|
|
83
|
+
for (const [plugin, { root }] of Object.entries(pluginRoots)) {
|
|
84
|
+
/** @type {T | null} */
|
|
85
|
+
const result = await loadConfiguration(pathFn.resolve(root, `${name}.yongdall`), true) || await loadConfiguration(pathFn.resolve(root, `yongdall/${name}`), true) || await loadConfiguration(pathFn.resolve(root, `${name}/yongdall`), true);
|
|
86
|
+
if (result === null) continue;
|
|
87
|
+
yield [plugin, result];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
57
90
|
|
|
58
91
|
//#endregion
|
|
59
|
-
export { plugins_default as default };
|
|
92
|
+
export { plugins_default as default, loadPluginProfiles, loadPluginScripts };
|
|
60
93
|
//# sourceMappingURL=index.mjs.map
|
package/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../cli/plugins/index.mjs"],"sourcesContent":["import * as pathFn from 'node:path';\nimport * as fsPromises from 'node:fs/promises';\nimport { pluginIdRegex } from '@yongdall/common';\nimport configuration, { loadCfgWithPath, configurationPath } from '@yongdall/configuration';\n\n/** @type {Record<string, {root: string; development: boolean}>} */\nconst pluginRoots = Object.create(null);\n\n/**\n * \n * @param {string} root \n * @param {string} name \n */\nasync function findNodeModule(root, name) {\n\tfor (let basepath = root; ;) {\n\t\tconst path = pathFn.resolve(basepath, 'node_modules', name);\n\t\tconst packageJson = await fsPromises.readFile(pathFn.resolve(path, 'package.json'), 'utf-8').then(v => JSON.parse(v)).catch(() => null);\n\t\tconst version = packageJson?.version;\n\t\tif (version && typeof version === 'string') {\n\t\t\treturn path;\n\t\t}\n\t\tconst parent = pathFn.dirname(basepath);\n\t\tif (parent === basepath) { break; }\n\t\tbasepath = parent;\n\t}\n\treturn null;\n}\n/**\n * @returns {Promise<[string, string | boolean | {path?: string; development?: boolean}, string][]>}\n */\nasync function getPlugins() {\n\tconst result = await loadCfgWithPath('plugins').catch(() => { });\n\tconst [path, pluginList] = result && result[1] ? result : [configurationPath, configuration.plugins];\n\tif (!pluginList) { return []; }\n\tconst basePath = pathFn.dirname(path);\n\tif (Array.isArray(pluginList)) {\n\t\treturn pluginList.map(a => [a, true, basePath]);\n\t}\n\treturn Object.entries(pluginList).map(([a, b]) => [a, b, basePath]);\n}\n\nfor (const [plugin, define, basePath] of await getPlugins()) {\n\tif (!define) { continue; }\n\tconst r = pluginIdRegex.exec(plugin);\n\tif (!r) { throw new Error(`无效的应用名称:${plugin}`); }\n\tconst path = typeof define === 'object' && define ? define.path : define;\n\tconst development = typeof define === 'object' && define ? define.development : false;\n\tconst pluginPath = path && typeof path === 'string'\n\t\t? pathFn.resolve(basePath, path)\n\t\t: await findNodeModule(basePath, plugin);\n\tif (!pluginPath) { throw new Error(`找不到应用:${plugin}`); }\n\tpluginRoots[plugin] = { root: pluginPath, development: Boolean(development) };\n}\n\nexport default pluginRoots;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../cli/plugins/index.mjs"],"sourcesContent":["import * as pathFn from 'node:path';\nimport * as fsPromises from 'node:fs/promises';\nimport { pluginIdRegex } from '@yongdall/common';\nimport configuration, { loadCfgWithPath, configurationPath } from '@yongdall/configuration';\nimport loadConfiguration, { loadConfigurationWithPath } from '@yongdall/load-configuration';\n\n/** @type {Record<string, {root: string; development: boolean}>} */\nconst pluginRoots = Object.create(null);\n\n/**\n * \n * @param {string} root \n * @param {string} name \n */\nasync function findNodeModule(root, name) {\n\tfor (let basepath = root; ;) {\n\t\tconst path = pathFn.resolve(basepath, 'node_modules', name);\n\t\tconst packageJson = await fsPromises.readFile(pathFn.resolve(path, 'package.json'), 'utf-8').then(v => JSON.parse(v)).catch(() => null);\n\t\tconst version = packageJson?.version;\n\t\tif (version && typeof version === 'string') {\n\t\t\treturn path;\n\t\t}\n\t\tconst parent = pathFn.dirname(basepath);\n\t\tif (parent === basepath) { break; }\n\t\tbasepath = parent;\n\t}\n\treturn null;\n}\n/**\n * @returns {Promise<[string, string | boolean | {path?: string; development?: boolean}, string][]>}\n */\nasync function getPlugins() {\n\tconst result = await loadCfgWithPath('plugins').catch(() => { });\n\tconst [path, pluginList] = result && result[1] ? result : [configurationPath, configuration.plugins];\n\tif (!pluginList) { return []; }\n\tconst basePath = pathFn.dirname(path);\n\tif (Array.isArray(pluginList)) {\n\t\treturn pluginList.map(a => [a, true, basePath]);\n\t}\n\treturn Object.entries(pluginList).map(([a, b]) => [a, b, basePath]);\n}\n\nfor (const [plugin, define, basePath] of await getPlugins()) {\n\tif (!define) { continue; }\n\tconst r = pluginIdRegex.exec(plugin);\n\tif (!r) { throw new Error(`无效的应用名称:${plugin}`); }\n\tconst path = typeof define === 'object' && define ? define.path : define;\n\tconst development = typeof define === 'object' && define ? define.development : false;\n\tconst pluginPath = path && typeof path === 'string'\n\t\t? pathFn.resolve(basePath, path)\n\t\t: await findNodeModule(basePath, plugin);\n\tif (!pluginPath) { throw new Error(`找不到应用:${plugin}`); }\n\tpluginRoots[plugin] = { root: pluginPath, development: Boolean(development) };\n}\n\nexport default pluginRoots;\n\n/** \n * @template {object} T\n * @param {string} name\n * @param {boolean} [scriptOnly] \n * @returns {AsyncIterableIterator<[plugin: string, config: T | null, path: string]>}\n */\nexport async function* loadPluginProfiles(name, scriptOnly) {\n\tfor (const [plugin, { root }] of Object.entries(pluginRoots)) {\n\t\t/** @type {[string, T | null] | null} */\n\t\tconst result = await loadConfigurationWithPath(pathFn.resolve(root, `${name}.yongdall`), scriptOnly)\n\t\t\t|| await loadConfigurationWithPath(pathFn.resolve(root, `yongdall/${name}`), scriptOnly)\n\t\t\t|| await loadConfigurationWithPath(pathFn.resolve(root, `${name}/yongdall`), scriptOnly);\n\t\tif (!result) { continue; }\n\t\tconst [path, config] = result;\n\t\tyield [plugin, config, path];\n\t}\n}\n\n/** \n * @template {object} T\n * @param {string} name\n * @returns {AsyncIterableIterator<[plugin: string, config: T]>}\n */\nexport async function* loadPluginScripts(name) {\n\tfor (const [plugin, { root }] of Object.entries(pluginRoots)) {\n\t\t/** @type {T | null} */\n\t\tconst result = await loadConfiguration(pathFn.resolve(root, `${name}.yongdall`), true)\n\t\t\t|| await loadConfiguration(pathFn.resolve(root, `yongdall/${name}`), true)\n\t\t\t|| await loadConfiguration(pathFn.resolve(root, `${name}/yongdall`), true);\n\t\tif (result === null) { continue; }\n\t\tyield [plugin, result];\n\t}\n}\n"],"mappings":";;;;;;;;AAOA,MAAM,cAAc,OAAO,OAAO,KAAK;;;;;;AAOvC,eAAe,eAAe,MAAM,MAAM;AACzC,MAAK,IAAI,WAAW,QAAS;E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E;;AAG9E,sBAAe;;;;;;;AAQf,gBAAuB,mBAAmB,MAAM,YAAY;AAC3D,MAAK,MAAM,CAAC,QAAQ,EAAE,WAAW,OAAO,QAAQ,YAAY,EAAE;;EAE7D,MAAM,SAAS,MAAM,0BAA0B,OAAO,QAAQ,MAAM,GAAG,KAAK,WAAW,EAAE,WAAW,IAChG,MAAM,0BAA0B,OAAO,QAAQ,MAAM,YAAY,OAAO,EAAE,WAAW,IACrF,MAAM,0BAA0B,OAAO,QAAQ,MAAM,GAAG,KAAK,WAAW,EAAE,WAAW;AACzF,MAAI,CAAC,OAAU;EACf,MAAM,CAAC,MAAM,UAAU;AACvB,QAAM;GAAC;GAAQ;GAAQ;GAAK;;;;;;;;AAS9B,gBAAuB,kBAAkB,MAAM;AAC9C,MAAK,MAAM,CAAC,QAAQ,EAAE,WAAW,OAAO,QAAQ,YAAY,EAAE;;EAE7D,MAAM,SAAS,MAAM,kBAAkB,OAAO,QAAQ,MAAM,GAAG,KAAK,WAAW,EAAE,KAAK,IAClF,MAAM,kBAAkB,OAAO,QAAQ,MAAM,YAAY,OAAO,EAAE,KAAK,IACvE,MAAM,kBAAkB,OAAO,QAAQ,MAAM,GAAG,KAAK,WAAW,EAAE,KAAK;AAC3E,MAAI,WAAW,KAAQ;AACvB,QAAM,CAAC,QAAQ,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yongdall/plugins",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"plugins.yongdall": "./bin.mjs"
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
"#index": "./index.mjs"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@yongdall/common": "^0.
|
|
14
|
-
"@yongdall/configuration": "^0.
|
|
13
|
+
"@yongdall/common": "^0.2.0",
|
|
14
|
+
"@yongdall/configuration": "^0.2.0",
|
|
15
|
+
"@yongdall/load-configuration": "^0.2.0",
|
|
15
16
|
"yaml": "^2.5.0"
|
|
16
17
|
},
|
|
17
18
|
"exports": {
|