@initx-plugin/core 0.0.24 → 0.0.26
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 +21 -24
- package/dist/index.d.ts +21 -24
- package/dist/index.mjs +4 -5
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
type MaybeArray<T> = T | T[];
|
|
2
2
|
type MaybePromise<T> = T | Promise<T>;
|
|
3
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
4
|
interface MatcherSetup {
|
|
13
5
|
/**
|
|
14
6
|
* Matching string or RegExp
|
|
@@ -17,17 +9,14 @@ interface MatcherSetup {
|
|
|
17
9
|
*/
|
|
18
10
|
matching: MaybeArray<string | RegExp>;
|
|
19
11
|
}
|
|
20
|
-
type
|
|
21
|
-
type ResultFunction<TResult, TMatcher> = (matcher: Matcher<TMatcher>, ...others: string[]) => TResult & TMatcher;
|
|
22
|
-
type BaseMatchers<TMatcher> = Matcher<TMatcher> & MatcherSetup;
|
|
12
|
+
type BaseMatchers<TMatcher> = TMatcher & MatcherSetup;
|
|
23
13
|
type TypeMatchers<TMatcher> = Record<string, BaseMatchers<TMatcher>>;
|
|
24
|
-
type
|
|
25
|
-
type
|
|
26
|
-
|
|
27
|
-
declare class InitxMatcher<TResult, TMatcher extends Matcher<MatcherOthers>> {
|
|
14
|
+
type ResultFunction<TResult, TMatcher> = (matcher: TMatcher, ...others: string[]) => TResult;
|
|
15
|
+
type Matchers<TMatcher extends object = object> = MaybeArray<BaseMatchers<TMatcher>> | TypeMatchers<TMatcher>;
|
|
16
|
+
declare class InitxMatcher$1<TResult, TMatcher extends object> {
|
|
28
17
|
private resultFunction;
|
|
29
18
|
constructor(fn: ResultFunction<TResult, TMatcher>);
|
|
30
|
-
match(matchers: Matchers
|
|
19
|
+
match(matchers: Matchers<TMatcher>, key: string, ...others: string[]): TResult[];
|
|
31
20
|
private matchBaseMatchers;
|
|
32
21
|
private matchArrayBaseMatchers;
|
|
33
22
|
private matchTypeMatchers;
|
|
@@ -40,7 +29,7 @@ declare class InitxMatcher<TResult, TMatcher extends Matcher<MatcherOthers>> {
|
|
|
40
29
|
private buildResultMatcher;
|
|
41
30
|
private buildResultFunction;
|
|
42
31
|
}
|
|
43
|
-
declare function useInitxMatcher<TResult, TMatcher extends
|
|
32
|
+
declare function useInitxMatcher<TResult, TMatcher extends object = object>(fn: ResultFunction<TResult, TMatcher>): InitxMatcher$1<TResult, TMatcher>;
|
|
44
33
|
|
|
45
34
|
interface PackageInfo {
|
|
46
35
|
root: string;
|
|
@@ -71,7 +60,15 @@ declare function fetchPlugins(): Promise<InitxPluginInfo[]>;
|
|
|
71
60
|
declare function loadPlugins(): Promise<LoadPluginResult[]>;
|
|
72
61
|
declare function matchPlugins(plugins: LoadPluginResult[], { key, cliOptions }: InitxBaseContext, ...others: string[]): MatchedPlugin[];
|
|
73
62
|
|
|
74
|
-
type
|
|
63
|
+
type InitxMatcher<TMatcher extends object = object> = TMatcher & {
|
|
64
|
+
/**
|
|
65
|
+
* Description of the handler
|
|
66
|
+
*
|
|
67
|
+
* If multiple handlers are matched, this description will be displayed
|
|
68
|
+
*/
|
|
69
|
+
description: string;
|
|
70
|
+
};
|
|
71
|
+
type InitxMatchers<TMatcher extends object = object> = Matchers<InitxMatcher<TMatcher>>;
|
|
75
72
|
interface HandlerInfo {
|
|
76
73
|
handler: () => MaybePromise<void>;
|
|
77
74
|
description: string;
|
|
@@ -103,7 +100,7 @@ interface InitxRunContext extends InitxBaseContext {
|
|
|
103
100
|
*/
|
|
104
101
|
packageInfo: PackageInfo;
|
|
105
102
|
}
|
|
106
|
-
interface InitxContext<TStore extends
|
|
103
|
+
interface InitxContext<TStore extends object = object, TMatcher extends object = object> extends InitxRunContext {
|
|
107
104
|
/**
|
|
108
105
|
* Store
|
|
109
106
|
*
|
|
@@ -115,11 +112,11 @@ interface InitxContext<TStore extends PluginStore = PluginStore, TMatcher extend
|
|
|
115
112
|
*
|
|
116
113
|
* Matched matcher object, you can get custom fields, excluded `matching`
|
|
117
114
|
*/
|
|
118
|
-
matcher:
|
|
115
|
+
matcher: InitxMatcher<TMatcher>;
|
|
119
116
|
}
|
|
120
|
-
declare abstract class InitxPlugin<TStore extends
|
|
121
|
-
abstract matchers:
|
|
122
|
-
abstract handle(context: InitxContext
|
|
117
|
+
declare abstract class InitxPlugin<TStore extends object = object> {
|
|
118
|
+
abstract matchers: InitxMatchers;
|
|
119
|
+
abstract handle(context: InitxContext, ...others: string[]): MaybePromise<void>;
|
|
123
120
|
defaultStore?: TStore;
|
|
124
121
|
run(context: InitxRunContext, ...others: string[]): HandlerInfo[];
|
|
125
122
|
private executeHandle;
|
|
@@ -128,4 +125,4 @@ declare abstract class InitxPlugin<TStore extends PluginStore = PluginStore, TMa
|
|
|
128
125
|
declare function createStore(name: string, defaultStore?: Record<string, any>): any;
|
|
129
126
|
declare function writeStore(name: string): void;
|
|
130
127
|
|
|
131
|
-
export { type HandlerInfo, type InitxBaseContext, type InitxContext, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, type
|
|
128
|
+
export { type HandlerInfo, type InitxBaseContext, type InitxContext, type InitxMatchers, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, type Matchers, type PackageInfo, createStore, fetchPlugins, loadPlugins, matchPlugins, useInitxMatcher, writeStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
type MaybeArray<T> = T | T[];
|
|
2
2
|
type MaybePromise<T> = T | Promise<T>;
|
|
3
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
4
|
interface MatcherSetup {
|
|
13
5
|
/**
|
|
14
6
|
* Matching string or RegExp
|
|
@@ -17,17 +9,14 @@ interface MatcherSetup {
|
|
|
17
9
|
*/
|
|
18
10
|
matching: MaybeArray<string | RegExp>;
|
|
19
11
|
}
|
|
20
|
-
type
|
|
21
|
-
type ResultFunction<TResult, TMatcher> = (matcher: Matcher<TMatcher>, ...others: string[]) => TResult & TMatcher;
|
|
22
|
-
type BaseMatchers<TMatcher> = Matcher<TMatcher> & MatcherSetup;
|
|
12
|
+
type BaseMatchers<TMatcher> = TMatcher & MatcherSetup;
|
|
23
13
|
type TypeMatchers<TMatcher> = Record<string, BaseMatchers<TMatcher>>;
|
|
24
|
-
type
|
|
25
|
-
type
|
|
26
|
-
|
|
27
|
-
declare class InitxMatcher<TResult, TMatcher extends Matcher<MatcherOthers>> {
|
|
14
|
+
type ResultFunction<TResult, TMatcher> = (matcher: TMatcher, ...others: string[]) => TResult;
|
|
15
|
+
type Matchers<TMatcher extends object = object> = MaybeArray<BaseMatchers<TMatcher>> | TypeMatchers<TMatcher>;
|
|
16
|
+
declare class InitxMatcher$1<TResult, TMatcher extends object> {
|
|
28
17
|
private resultFunction;
|
|
29
18
|
constructor(fn: ResultFunction<TResult, TMatcher>);
|
|
30
|
-
match(matchers: Matchers
|
|
19
|
+
match(matchers: Matchers<TMatcher>, key: string, ...others: string[]): TResult[];
|
|
31
20
|
private matchBaseMatchers;
|
|
32
21
|
private matchArrayBaseMatchers;
|
|
33
22
|
private matchTypeMatchers;
|
|
@@ -40,7 +29,7 @@ declare class InitxMatcher<TResult, TMatcher extends Matcher<MatcherOthers>> {
|
|
|
40
29
|
private buildResultMatcher;
|
|
41
30
|
private buildResultFunction;
|
|
42
31
|
}
|
|
43
|
-
declare function useInitxMatcher<TResult, TMatcher extends
|
|
32
|
+
declare function useInitxMatcher<TResult, TMatcher extends object = object>(fn: ResultFunction<TResult, TMatcher>): InitxMatcher$1<TResult, TMatcher>;
|
|
44
33
|
|
|
45
34
|
interface PackageInfo {
|
|
46
35
|
root: string;
|
|
@@ -71,7 +60,15 @@ declare function fetchPlugins(): Promise<InitxPluginInfo[]>;
|
|
|
71
60
|
declare function loadPlugins(): Promise<LoadPluginResult[]>;
|
|
72
61
|
declare function matchPlugins(plugins: LoadPluginResult[], { key, cliOptions }: InitxBaseContext, ...others: string[]): MatchedPlugin[];
|
|
73
62
|
|
|
74
|
-
type
|
|
63
|
+
type InitxMatcher<TMatcher extends object = object> = TMatcher & {
|
|
64
|
+
/**
|
|
65
|
+
* Description of the handler
|
|
66
|
+
*
|
|
67
|
+
* If multiple handlers are matched, this description will be displayed
|
|
68
|
+
*/
|
|
69
|
+
description: string;
|
|
70
|
+
};
|
|
71
|
+
type InitxMatchers<TMatcher extends object = object> = Matchers<InitxMatcher<TMatcher>>;
|
|
75
72
|
interface HandlerInfo {
|
|
76
73
|
handler: () => MaybePromise<void>;
|
|
77
74
|
description: string;
|
|
@@ -103,7 +100,7 @@ interface InitxRunContext extends InitxBaseContext {
|
|
|
103
100
|
*/
|
|
104
101
|
packageInfo: PackageInfo;
|
|
105
102
|
}
|
|
106
|
-
interface InitxContext<TStore extends
|
|
103
|
+
interface InitxContext<TStore extends object = object, TMatcher extends object = object> extends InitxRunContext {
|
|
107
104
|
/**
|
|
108
105
|
* Store
|
|
109
106
|
*
|
|
@@ -115,11 +112,11 @@ interface InitxContext<TStore extends PluginStore = PluginStore, TMatcher extend
|
|
|
115
112
|
*
|
|
116
113
|
* Matched matcher object, you can get custom fields, excluded `matching`
|
|
117
114
|
*/
|
|
118
|
-
matcher:
|
|
115
|
+
matcher: InitxMatcher<TMatcher>;
|
|
119
116
|
}
|
|
120
|
-
declare abstract class InitxPlugin<TStore extends
|
|
121
|
-
abstract matchers:
|
|
122
|
-
abstract handle(context: InitxContext
|
|
117
|
+
declare abstract class InitxPlugin<TStore extends object = object> {
|
|
118
|
+
abstract matchers: InitxMatchers;
|
|
119
|
+
abstract handle(context: InitxContext, ...others: string[]): MaybePromise<void>;
|
|
123
120
|
defaultStore?: TStore;
|
|
124
121
|
run(context: InitxRunContext, ...others: string[]): HandlerInfo[];
|
|
125
122
|
private executeHandle;
|
|
@@ -128,4 +125,4 @@ declare abstract class InitxPlugin<TStore extends PluginStore = PluginStore, TMa
|
|
|
128
125
|
declare function createStore(name: string, defaultStore?: Record<string, any>): any;
|
|
129
126
|
declare function writeStore(name: string): void;
|
|
130
127
|
|
|
131
|
-
export { type HandlerInfo, type InitxBaseContext, type InitxContext, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, type
|
|
128
|
+
export { type HandlerInfo, type InitxBaseContext, type InitxContext, type InitxMatchers, InitxPlugin, type InitxPluginInfo, type LoadPluginResult, type MatchedPlugin, type Matchers, type PackageInfo, createStore, fetchPlugins, loadPlugins, matchPlugins, useInitxMatcher, writeStore };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
1
|
import { homedir } from 'node:os';
|
|
3
|
-
import
|
|
2
|
+
import path from 'node:path';
|
|
4
3
|
import { defu } from 'defu';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
5
|
import { c } from '@initx-plugin/utils';
|
|
6
6
|
|
|
7
7
|
var __defProp$1 = Object.defineProperty;
|
|
@@ -65,7 +65,7 @@ class InitxMatcher {
|
|
|
65
65
|
}
|
|
66
66
|
isBaseMatchers(matchers) {
|
|
67
67
|
const keys = Object.keys(matchers);
|
|
68
|
-
const requiredKeys = ["matching"
|
|
68
|
+
const requiredKeys = ["matching"];
|
|
69
69
|
return this.isObject(matchers) && keys.length >= 2 && requiredKeys.every((key) => keys.includes(key));
|
|
70
70
|
}
|
|
71
71
|
isArrayBaseMatchers(matchers) {
|
|
@@ -199,8 +199,7 @@ class InitxPlugin {
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
async function fetchPlugins() {
|
|
202
|
-
const { content:
|
|
203
|
-
const nodeModules = path.join(npmPath, "node_modules");
|
|
202
|
+
const { content: nodeModules } = await c("npm", ["root", "-g"]);
|
|
204
203
|
const communityPlugins = fs.readdirSync(nodeModules);
|
|
205
204
|
const officialPluginPath = path.join(nodeModules, "@initx-plugin");
|
|
206
205
|
const officialPlugins = fs.existsSync(officialPluginPath) ? fs.readdirSync(officialPluginPath).map((name) => `@initx-plugin/${name}`) : [];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@initx-plugin/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.26",
|
|
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.
|
|
28
|
+
"@initx-plugin/utils": "0.0.26"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/fs-extra": "^11.0.4"
|