@initx-plugin/core 0.0.22 → 0.0.24

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/dist/index.d.mts CHANGED
@@ -1,3 +1,47 @@
1
+ type MaybeArray<T> = T | T[];
2
+ type MaybePromise<T> = T | Promise<T>;
3
+
4
+ interface MatcherCommon {
5
+ /**
6
+ * Description of the handler
7
+ *
8
+ * If multiple handlers are matched, this description will be displayed
9
+ */
10
+ description: string;
11
+ }
12
+ interface MatcherSetup {
13
+ /**
14
+ * Matching string or RegExp
15
+ *
16
+ * The key that was used to match the handler
17
+ */
18
+ matching: MaybeArray<string | RegExp>;
19
+ }
20
+ type Matcher<TMatcher> = TMatcher & MatcherCommon;
21
+ type ResultFunction<TResult, TMatcher> = (matcher: Matcher<TMatcher>, ...others: string[]) => TResult & TMatcher;
22
+ type BaseMatchers<TMatcher> = Matcher<TMatcher> & MatcherSetup;
23
+ type TypeMatchers<TMatcher> = Record<string, BaseMatchers<TMatcher>>;
24
+ type MatcherOthersDefault = Record<any, any>;
25
+ type MatcherOthers<T extends MatcherOthersDefault = MatcherOthersDefault> = T;
26
+ type Matchers<TMatcher extends MatcherOthers = MatcherOthers> = MaybeArray<BaseMatchers<TMatcher>> | TypeMatchers<TMatcher>;
27
+ declare class InitxMatcher<TResult, TMatcher extends Matcher<MatcherOthers>> {
28
+ private resultFunction;
29
+ constructor(fn: ResultFunction<TResult, TMatcher>);
30
+ match(matchers: Matchers, key: string, ...others: string[]): (TResult & TMatcher)[];
31
+ private matchBaseMatchers;
32
+ private matchArrayBaseMatchers;
33
+ private matchTypeMatchers;
34
+ private isBaseMatchers;
35
+ private isArrayBaseMatchers;
36
+ private alwaysArray;
37
+ private isObject;
38
+ private isPassed;
39
+ private omit;
40
+ private buildResultMatcher;
41
+ private buildResultFunction;
42
+ }
43
+ declare function useInitxMatcher<TResult, TMatcher extends Matcher<MatcherOthers> = Matcher<MatcherOthers>>(fn: ResultFunction<TResult, TMatcher>): InitxMatcher<TResult, TMatcher>;
44
+
1
45
  interface PackageInfo {
2
46
  root: string;
3
47
  name: string;
@@ -7,28 +51,26 @@ interface PackageInfo {
7
51
  homepage?: string;
8
52
  }
9
53
  interface InitxPluginInfo {
54
+ /**
55
+ * Plugin name
56
+ */
57
+ name: string;
58
+ /**
59
+ * Plugin root path
60
+ */
61
+ root: string;
62
+ }
63
+ interface LoadPluginResult {
10
64
  packageInfo: PackageInfo;
11
65
  instance: InitxPlugin;
12
66
  }
13
67
  type MatchedPlugin = HandlerInfo & {
14
68
  packageInfo: PackageInfo;
15
69
  };
16
- declare function loadPlugins(): Promise<InitxPluginInfo[]>;
17
- declare function matchPlugins(plugins: InitxPluginInfo[], { key, cliOptions }: InitxBaseContext, ...others: string[]): MatchedPlugin[];
70
+ declare function fetchPlugins(): Promise<InitxPluginInfo[]>;
71
+ declare function loadPlugins(): Promise<LoadPluginResult[]>;
72
+ declare function matchPlugins(plugins: LoadPluginResult[], { key, cliOptions }: InitxBaseContext, ...others: string[]): MatchedPlugin[];
18
73
 
19
- type MaybeArray<T> = T | T[];
20
- type MaybePromise<T> = T | Promise<T>;
21
- interface BaseMatchers {
22
- matching: MaybeArray<string | RegExp>;
23
- /**
24
- * Description of the handler
25
- *
26
- * If multiple handlers are matched, this description will be displayed
27
- */
28
- description: string;
29
- }
30
- type TypeMatchers = Record<string, BaseMatchers>;
31
- type Matchers = MaybeArray<BaseMatchers> | TypeMatchers;
32
74
  type PluginStore = Record<string, any>;
33
75
  interface HandlerInfo {
34
76
  handler: () => MaybePromise<void>;
@@ -61,30 +103,29 @@ interface InitxRunContext extends InitxBaseContext {
61
103
  */
62
104
  packageInfo: PackageInfo;
63
105
  }
64
- interface InitxContext<TStore extends PluginStore = PluginStore> extends InitxRunContext {
106
+ interface InitxContext<TStore extends PluginStore = PluginStore, TMatcher extends MatcherOthers<MatcherOthersDefault> = MatcherOthers<MatcherOthersDefault>> extends InitxRunContext {
65
107
  /**
66
108
  * Store
67
109
  *
68
110
  * Store data in memory, and write to disk when the program exits
69
111
  */
70
112
  store: TStore;
113
+ /**
114
+ * Matcher
115
+ *
116
+ * Matched matcher object, you can get custom fields, excluded `matching`
117
+ */
118
+ matcher: Matcher<TMatcher>;
71
119
  }
72
- declare abstract class InitxPlugin<TStore extends PluginStore = PluginStore> {
120
+ declare abstract class InitxPlugin<TStore extends PluginStore = PluginStore, TMatcher extends MatcherOthers = MatcherOthers> {
73
121
  abstract matchers: Matchers;
74
- abstract handle(options: InitxContext<TStore>, ...others: string[]): MaybePromise<void>;
122
+ abstract handle(context: InitxContext<TStore, TMatcher>, ...others: string[]): MaybePromise<void>;
75
123
  defaultStore?: TStore;
76
124
  run(context: InitxRunContext, ...others: string[]): HandlerInfo[];
77
- private matchBaseMatchers;
78
- private matchArrayBaseMatchers;
79
- private matchTypeMatchers;
80
- private isBaseMatchers;
81
- private isArrayBaseMatchers;
82
- private isObject;
83
- private isPassed;
84
125
  private executeHandle;
85
126
  }
86
127
 
87
- declare function createStore({ name }: PackageInfo, defaultStore?: Record<string, any>): any;
88
- declare function writeStore({ name }: PackageInfo): void;
128
+ declare function createStore(name: string, defaultStore?: Record<string, any>): any;
129
+ declare function writeStore(name: string): void;
89
130
 
90
- export { type HandlerInfo, type InitxBaseContext, type InitxContext, InitxPlugin, type InitxPluginInfo, type MatchedPlugin, type PackageInfo, createStore, loadPlugins, matchPlugins, writeStore };
131
+ export { type HandlerInfo, type InitxBaseContext, type InitxContext, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, type Matcher, type MatcherOthers, type MatcherOthersDefault, type Matchers, type PackageInfo, createStore, fetchPlugins, loadPlugins, matchPlugins, useInitxMatcher, writeStore };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,47 @@
1
+ type MaybeArray<T> = T | T[];
2
+ type MaybePromise<T> = T | Promise<T>;
3
+
4
+ interface MatcherCommon {
5
+ /**
6
+ * Description of the handler
7
+ *
8
+ * If multiple handlers are matched, this description will be displayed
9
+ */
10
+ description: string;
11
+ }
12
+ interface MatcherSetup {
13
+ /**
14
+ * Matching string or RegExp
15
+ *
16
+ * The key that was used to match the handler
17
+ */
18
+ matching: MaybeArray<string | RegExp>;
19
+ }
20
+ type Matcher<TMatcher> = TMatcher & MatcherCommon;
21
+ type ResultFunction<TResult, TMatcher> = (matcher: Matcher<TMatcher>, ...others: string[]) => TResult & TMatcher;
22
+ type BaseMatchers<TMatcher> = Matcher<TMatcher> & MatcherSetup;
23
+ type TypeMatchers<TMatcher> = Record<string, BaseMatchers<TMatcher>>;
24
+ type MatcherOthersDefault = Record<any, any>;
25
+ type MatcherOthers<T extends MatcherOthersDefault = MatcherOthersDefault> = T;
26
+ type Matchers<TMatcher extends MatcherOthers = MatcherOthers> = MaybeArray<BaseMatchers<TMatcher>> | TypeMatchers<TMatcher>;
27
+ declare class InitxMatcher<TResult, TMatcher extends Matcher<MatcherOthers>> {
28
+ private resultFunction;
29
+ constructor(fn: ResultFunction<TResult, TMatcher>);
30
+ match(matchers: Matchers, key: string, ...others: string[]): (TResult & TMatcher)[];
31
+ private matchBaseMatchers;
32
+ private matchArrayBaseMatchers;
33
+ private matchTypeMatchers;
34
+ private isBaseMatchers;
35
+ private isArrayBaseMatchers;
36
+ private alwaysArray;
37
+ private isObject;
38
+ private isPassed;
39
+ private omit;
40
+ private buildResultMatcher;
41
+ private buildResultFunction;
42
+ }
43
+ declare function useInitxMatcher<TResult, TMatcher extends Matcher<MatcherOthers> = Matcher<MatcherOthers>>(fn: ResultFunction<TResult, TMatcher>): InitxMatcher<TResult, TMatcher>;
44
+
1
45
  interface PackageInfo {
2
46
  root: string;
3
47
  name: string;
@@ -7,28 +51,26 @@ interface PackageInfo {
7
51
  homepage?: string;
8
52
  }
9
53
  interface InitxPluginInfo {
54
+ /**
55
+ * Plugin name
56
+ */
57
+ name: string;
58
+ /**
59
+ * Plugin root path
60
+ */
61
+ root: string;
62
+ }
63
+ interface LoadPluginResult {
10
64
  packageInfo: PackageInfo;
11
65
  instance: InitxPlugin;
12
66
  }
13
67
  type MatchedPlugin = HandlerInfo & {
14
68
  packageInfo: PackageInfo;
15
69
  };
16
- declare function loadPlugins(): Promise<InitxPluginInfo[]>;
17
- declare function matchPlugins(plugins: InitxPluginInfo[], { key, cliOptions }: InitxBaseContext, ...others: string[]): MatchedPlugin[];
70
+ declare function fetchPlugins(): Promise<InitxPluginInfo[]>;
71
+ declare function loadPlugins(): Promise<LoadPluginResult[]>;
72
+ declare function matchPlugins(plugins: LoadPluginResult[], { key, cliOptions }: InitxBaseContext, ...others: string[]): MatchedPlugin[];
18
73
 
19
- type MaybeArray<T> = T | T[];
20
- type MaybePromise<T> = T | Promise<T>;
21
- interface BaseMatchers {
22
- matching: MaybeArray<string | RegExp>;
23
- /**
24
- * Description of the handler
25
- *
26
- * If multiple handlers are matched, this description will be displayed
27
- */
28
- description: string;
29
- }
30
- type TypeMatchers = Record<string, BaseMatchers>;
31
- type Matchers = MaybeArray<BaseMatchers> | TypeMatchers;
32
74
  type PluginStore = Record<string, any>;
33
75
  interface HandlerInfo {
34
76
  handler: () => MaybePromise<void>;
@@ -61,30 +103,29 @@ interface InitxRunContext extends InitxBaseContext {
61
103
  */
62
104
  packageInfo: PackageInfo;
63
105
  }
64
- interface InitxContext<TStore extends PluginStore = PluginStore> extends InitxRunContext {
106
+ interface InitxContext<TStore extends PluginStore = PluginStore, TMatcher extends MatcherOthers<MatcherOthersDefault> = MatcherOthers<MatcherOthersDefault>> extends InitxRunContext {
65
107
  /**
66
108
  * Store
67
109
  *
68
110
  * Store data in memory, and write to disk when the program exits
69
111
  */
70
112
  store: TStore;
113
+ /**
114
+ * Matcher
115
+ *
116
+ * Matched matcher object, you can get custom fields, excluded `matching`
117
+ */
118
+ matcher: Matcher<TMatcher>;
71
119
  }
72
- declare abstract class InitxPlugin<TStore extends PluginStore = PluginStore> {
120
+ declare abstract class InitxPlugin<TStore extends PluginStore = PluginStore, TMatcher extends MatcherOthers = MatcherOthers> {
73
121
  abstract matchers: Matchers;
74
- abstract handle(options: InitxContext<TStore>, ...others: string[]): MaybePromise<void>;
122
+ abstract handle(context: InitxContext<TStore, TMatcher>, ...others: string[]): MaybePromise<void>;
75
123
  defaultStore?: TStore;
76
124
  run(context: InitxRunContext, ...others: string[]): HandlerInfo[];
77
- private matchBaseMatchers;
78
- private matchArrayBaseMatchers;
79
- private matchTypeMatchers;
80
- private isBaseMatchers;
81
- private isArrayBaseMatchers;
82
- private isObject;
83
- private isPassed;
84
125
  private executeHandle;
85
126
  }
86
127
 
87
- declare function createStore({ name }: PackageInfo, defaultStore?: Record<string, any>): any;
88
- declare function writeStore({ name }: PackageInfo): void;
128
+ declare function createStore(name: string, defaultStore?: Record<string, any>): any;
129
+ declare function writeStore(name: string): void;
89
130
 
90
- export { type HandlerInfo, type InitxBaseContext, type InitxContext, InitxPlugin, type InitxPluginInfo, type MatchedPlugin, type PackageInfo, createStore, loadPlugins, matchPlugins, writeStore };
131
+ export { type HandlerInfo, type InitxBaseContext, type InitxContext, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, type Matcher, type MatcherOthers, type MatcherOthersDefault, type Matchers, type PackageInfo, createStore, fetchPlugins, loadPlugins, matchPlugins, useInitxMatcher, writeStore };
package/dist/index.mjs CHANGED
@@ -4,17 +4,122 @@ import fs from 'fs-extra';
4
4
  import { defu } from 'defu';
5
5
  import { c } from '@initx-plugin/utils';
6
6
 
7
+ var __defProp$1 = Object.defineProperty;
8
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __publicField$1 = (obj, key, value) => {
10
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
11
+ return value;
12
+ };
13
+ class InitxMatcher {
14
+ constructor(fn) {
15
+ __publicField$1(this, "resultFunction");
16
+ this.resultFunction = fn;
17
+ }
18
+ match(matchers, key, ...others) {
19
+ if (this.isBaseMatchers(matchers)) {
20
+ return this.matchBaseMatchers(matchers, key, ...others);
21
+ }
22
+ if (this.isArrayBaseMatchers(matchers)) {
23
+ return this.matchArrayBaseMatchers(matchers, key, ...others);
24
+ }
25
+ if (this.isObject(matchers)) {
26
+ return this.matchTypeMatchers(matchers, key, ...others);
27
+ }
28
+ return [];
29
+ }
30
+ // BaseMatchers
31
+ matchBaseMatchers(matchers, key, ...others) {
32
+ if (!this.isPassed(matchers.matching, key)) {
33
+ return [];
34
+ }
35
+ return this.alwaysArray(
36
+ this.buildResultFunction(matchers, ...others)
37
+ );
38
+ }
39
+ matchArrayBaseMatchers(matchers, key, ...others) {
40
+ const handlers = [];
41
+ for (let i = 0; i < matchers.length; i++) {
42
+ const matcher = matchers[i];
43
+ const isPassed = this.isPassed(matcher.matching, key);
44
+ if (isPassed) {
45
+ handlers.push(
46
+ this.buildResultFunction(matcher, ...others)
47
+ );
48
+ }
49
+ }
50
+ return handlers;
51
+ }
52
+ matchTypeMatchers(matchers, key, ...others) {
53
+ const handlers = [];
54
+ const keys = Object.keys(matchers);
55
+ for (let i = 0; i < keys.length; i++) {
56
+ const matcher = matchers[keys[i]];
57
+ const isPassed = this.isPassed(matcher.matching, key);
58
+ if (isPassed) {
59
+ handlers.push(
60
+ this.buildResultFunction(matcher, keys[i], ...others)
61
+ );
62
+ }
63
+ }
64
+ return handlers;
65
+ }
66
+ isBaseMatchers(matchers) {
67
+ const keys = Object.keys(matchers);
68
+ const requiredKeys = ["matching", "description"];
69
+ return this.isObject(matchers) && keys.length >= 2 && requiredKeys.every((key) => keys.includes(key));
70
+ }
71
+ isArrayBaseMatchers(matchers) {
72
+ return Array.isArray(matchers) && matchers.every(this.isBaseMatchers.bind(this));
73
+ }
74
+ alwaysArray(value) {
75
+ return Array.isArray(value) ? value : [value];
76
+ }
77
+ isObject(value) {
78
+ return typeof value === "object" && value !== null && !Array.isArray(value);
79
+ }
80
+ isPassed(matchers, key) {
81
+ const tests = Array.isArray(matchers) ? matchers : [matchers];
82
+ return tests.some((test) => {
83
+ if (typeof test === "string") {
84
+ return test === key;
85
+ }
86
+ return test.test(key);
87
+ });
88
+ }
89
+ omit(obj, keys) {
90
+ const result = {};
91
+ for (const key in obj) {
92
+ if (!keys.includes(key)) {
93
+ result[key] = obj[key];
94
+ }
95
+ }
96
+ return result;
97
+ }
98
+ buildResultMatcher(matcher) {
99
+ return this.omit(matcher, ["matching"]);
100
+ }
101
+ buildResultFunction(matcher, ...others) {
102
+ const buildedMatcher = this.buildResultMatcher(matcher);
103
+ return this.resultFunction(
104
+ buildedMatcher,
105
+ ...others
106
+ );
107
+ }
108
+ }
109
+ function useInitxMatcher(fn) {
110
+ return new InitxMatcher(fn);
111
+ }
112
+
113
+ let rewritedCache = null;
7
114
  const INITX_DIR = path.resolve(homedir(), ".initx");
8
115
  const STORE_FILE_NAME = "store.json";
9
- const REWRITED_FILE_NAME = ".rewrited";
10
116
  const resolveStore = (name) => path.resolve(INITX_DIR, name, STORE_FILE_NAME);
11
- const resolveRewrited = (name) => path.resolve(INITX_DIR, name, REWRITED_FILE_NAME);
12
- function createStore({ name }, defaultStore = {}) {
117
+ function createStore(name, defaultStore = {}) {
13
118
  fs.ensureDirSync(path.resolve(INITX_DIR, name));
14
119
  const storePath = resolveStore(name);
15
120
  const generateResult = (resultData) => {
16
121
  writeJson(storePath, resultData);
17
- return useProxy(name, resultData);
122
+ return useProxy(resultData);
18
123
  };
19
124
  if (!fs.existsSync(storePath)) {
20
125
  return generateResult(defaultStore);
@@ -28,21 +133,18 @@ function createStore({ name }, defaultStore = {}) {
28
133
  }
29
134
  return generateResult(json);
30
135
  }
31
- function writeStore({ name }) {
32
- const rewritedPath = resolveRewrited(name);
33
- if (!fs.existsSync(rewritedPath)) {
136
+ function writeStore(name) {
137
+ if (!rewritedCache) {
34
138
  return;
35
139
  }
36
- const rewrited = fs.readJsonSync(rewritedPath);
37
- writeJson(resolveStore(name), rewrited);
38
- fs.removeSync(rewritedPath);
140
+ writeJson(resolveStore(name), rewritedCache);
39
141
  }
40
142
  function writeJson(path2, data) {
41
143
  fs.writeJsonSync(path2, data, {
42
144
  spaces: 2
43
145
  });
44
146
  }
45
- function useProxy(name, obj = {}) {
147
+ function useProxy(obj = {}) {
46
148
  const isPlainObject = (value) => {
47
149
  return Object.prototype.toString.call(value) === "[object Object]";
48
150
  };
@@ -57,7 +159,7 @@ function useProxy(name, obj = {}) {
57
159
  },
58
160
  set(target2, key, value) {
59
161
  const success = Reflect.set(target2, key, value);
60
- fs.writeJsonSync(resolveRewrited(name), target2);
162
+ rewritedCache = target2;
61
163
  return success;
62
164
  }
63
165
  });
@@ -76,85 +178,27 @@ class InitxPlugin {
76
178
  __publicField(this, "defaultStore");
77
179
  }
78
180
  run(context, ...others) {
79
- if (this.isBaseMatchers(this.matchers)) {
80
- return this.matchBaseMatchers(this.matchers, context, ...others);
81
- }
82
- if (this.isArrayBaseMatchers(this.matchers)) {
83
- return this.matchArrayBaseMatchers(this.matchers, context, ...others);
84
- }
85
- if (this.isObject(this.matchers)) {
86
- return this.matchTypeMatchers(this.matchers, context, ...others);
87
- }
88
- return [];
89
- }
90
- // BaseMatchers
91
- matchBaseMatchers(matchers, context, ...others) {
92
- if (!this.isPassed(matchers.matching, context.key)) {
93
- return [];
94
- }
95
- return [
96
- {
97
- handler: () => this.executeHandle(context, ...others),
98
- description: matchers.description
99
- }
100
- ];
101
- }
102
- matchArrayBaseMatchers(matchers, context, ...others) {
103
- const handlers = [];
104
- for (let i = 0; i < matchers.length; i++) {
105
- const matcher = matchers[i];
106
- const isPassed = this.isPassed(matcher.matching, context.key);
107
- if (isPassed) {
108
- handlers.push({
109
- handler: () => this.executeHandle(context, ...others),
110
- description: matcher.description
111
- });
112
- }
113
- }
114
- return handlers;
115
- }
116
- matchTypeMatchers(matchers, context, ...others) {
117
- const handlers = [];
118
- const keys = Object.keys(matchers);
119
- for (let i = 0; i < keys.length; i++) {
120
- const matcher = matchers[keys[i]];
121
- const isPassed = this.isPassed(matcher.matching, context.key);
122
- if (isPassed) {
123
- handlers.push({
124
- handler: () => this.executeHandle(context, keys[i], ...others),
125
- description: matcher.description
126
- });
127
- }
128
- }
129
- return handlers;
130
- }
131
- isBaseMatchers(matchers) {
132
- const keys = Object.keys(matchers);
133
- return this.isObject(matchers) && keys.length === 2 && keys.every((key) => key === "matching" || key === "description");
134
- }
135
- isArrayBaseMatchers(matchers) {
136
- return Array.isArray(matchers) && matchers.every(this.isBaseMatchers.bind(this));
137
- }
138
- isObject(value) {
139
- return typeof value === "object" && value !== null && !Array.isArray(value);
181
+ const initxMatcher = useInitxMatcher(
182
+ (matcher, ...others2) => ({
183
+ handler: () => this.executeHandle(context, matcher, ...others2),
184
+ description: matcher.description
185
+ })
186
+ );
187
+ const matchedHandlers = initxMatcher.match(
188
+ this.matchers,
189
+ context.key,
190
+ ...others
191
+ );
192
+ return matchedHandlers;
140
193
  }
141
- isPassed(matchers, key) {
142
- const tests = Array.isArray(matchers) ? matchers : [matchers];
143
- return tests.some((test) => {
144
- if (typeof test === "string") {
145
- return test === key;
146
- }
147
- return test.test(key);
148
- });
149
- }
150
- async executeHandle(context, ...others) {
151
- const store = createStore(context.packageInfo, this.defaultStore);
152
- await this.handle({ ...context, store }, ...others);
153
- writeStore(context.packageInfo);
194
+ async executeHandle(context, matcher, ...others) {
195
+ const store = createStore(context.packageInfo.name, this.defaultStore);
196
+ await this.handle({ ...context, matcher, store }, ...others);
197
+ writeStore(context.packageInfo.name);
154
198
  }
155
199
  }
156
200
 
157
- async function loadPlugins() {
201
+ async function fetchPlugins() {
158
202
  const { content: npmPath } = await c("npm", ["config", "get", "prefix"]);
159
203
  const nodeModules = path.join(npmPath, "node_modules");
160
204
  const communityPlugins = fs.readdirSync(nodeModules);
@@ -164,19 +208,24 @@ async function loadPlugins() {
164
208
  plugin: /^(?:@initx-plugin\/|initx-plugin-)/,
165
209
  exclude: /@initx-plugin\/(?:core|utils)$/
166
210
  };
167
- const pluginsName = [
211
+ return [
168
212
  ...officialPlugins,
169
213
  ...communityPlugins
170
214
  ].filter(
171
215
  (name) => regexps.plugin.test(name) && !regexps.exclude.test(name)
172
- );
216
+ ).map((name) => ({
217
+ name,
218
+ root: path.join(nodeModules, name)
219
+ }));
220
+ }
221
+ async function loadPlugins() {
222
+ const pluginsInfo = await fetchPlugins();
173
223
  const x = await import('importx');
174
- return Promise.all(pluginsName.map(async (dirname) => {
175
- const pluginRoot = path.join(nodeModules, dirname);
176
- const InitxPluginClass = await x.import(pluginRoot, import.meta.url).then((x2) => x2.default);
177
- const packageAll = JSON.parse(fs.readFileSync(path.join(nodeModules, dirname, "package.json"), "utf-8"));
224
+ return Promise.all(pluginsInfo.map(async ({ root }) => {
225
+ const InitxPluginClass = await x.import(root, import.meta.url).then((x2) => x2.default);
226
+ const packageAll = fs.readJsonSync(path.join(root, "package.json"));
178
227
  const packageInfo = {
179
- root: pluginRoot,
228
+ root,
180
229
  name: packageAll.name,
181
230
  version: packageAll.version,
182
231
  description: packageAll.description,
@@ -208,4 +257,4 @@ function matchPlugins(plugins, { key, cliOptions }, ...others) {
208
257
  return matchedHandlers;
209
258
  }
210
259
 
211
- export { InitxPlugin, createStore, loadPlugins, matchPlugins, writeStore };
260
+ export { InitxPlugin, createStore, fetchPlugins, loadPlugins, matchPlugins, useInitxMatcher, writeStore };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@initx-plugin/core",
3
3
  "type": "module",
4
- "version": "0.0.22",
4
+ "version": "0.0.24",
5
5
  "description": "core module for initx plugins",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/initx-collective/initx#readme",
@@ -25,7 +25,7 @@
25
25
  "defu": "^6.1.4",
26
26
  "fs-extra": "^11.2.0",
27
27
  "importx": "^0.5.0",
28
- "@initx-plugin/utils": "0.0.22"
28
+ "@initx-plugin/utils": "0.0.24"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/fs-extra": "^11.0.4"