@initx-plugin/core 0.0.6 → 0.0.7

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
@@ -3,13 +3,33 @@ type MaybePromise<T> = T | Promise<T>;
3
3
  type BaseMatchers = MaybeArray<string | RegExp>;
4
4
  type TypeMatchers = Record<string, BaseMatchers>;
5
5
  type Matchers = BaseMatchers | TypeMatchers;
6
+ interface InitxOptions {
7
+ /**
8
+ * Matching string
9
+ *
10
+ * The key that was used to match the handler
11
+ */
12
+ key: string;
13
+ /**
14
+ * CLI options
15
+ *
16
+ * cac package parsed options
17
+ */
18
+ cliOptions: Record<string, any>;
19
+ /**
20
+ * Options list
21
+ *
22
+ * cli options list, like
23
+ * @example ['--global']
24
+ */
25
+ optionsList: string[];
26
+ }
6
27
  declare abstract class InitxHandler {
7
28
  abstract matchers: Matchers;
8
- abstract handle(value: string, ...others: string[]): MaybePromise<void>;
9
- abstract handle<T>(value: string, type: T, ...others: string[]): MaybePromise<void>;
10
- run(value: string, ...others: string[]): Promise<void>;
29
+ abstract handle(options: InitxOptions, ...others: string[]): MaybePromise<void>;
30
+ run(options: InitxOptions, ...others: string[]): Promise<void>;
11
31
  private isObject;
12
32
  private isPassed;
13
33
  }
14
34
 
15
- export { InitxHandler };
35
+ export { InitxHandler, type InitxOptions };
package/dist/index.d.ts CHANGED
@@ -3,13 +3,33 @@ type MaybePromise<T> = T | Promise<T>;
3
3
  type BaseMatchers = MaybeArray<string | RegExp>;
4
4
  type TypeMatchers = Record<string, BaseMatchers>;
5
5
  type Matchers = BaseMatchers | TypeMatchers;
6
+ interface InitxOptions {
7
+ /**
8
+ * Matching string
9
+ *
10
+ * The key that was used to match the handler
11
+ */
12
+ key: string;
13
+ /**
14
+ * CLI options
15
+ *
16
+ * cac package parsed options
17
+ */
18
+ cliOptions: Record<string, any>;
19
+ /**
20
+ * Options list
21
+ *
22
+ * cli options list, like
23
+ * @example ['--global']
24
+ */
25
+ optionsList: string[];
26
+ }
6
27
  declare abstract class InitxHandler {
7
28
  abstract matchers: Matchers;
8
- abstract handle(value: string, ...others: string[]): MaybePromise<void>;
9
- abstract handle<T>(value: string, type: T, ...others: string[]): MaybePromise<void>;
10
- run(value: string, ...others: string[]): Promise<void>;
29
+ abstract handle(options: InitxOptions, ...others: string[]): MaybePromise<void>;
30
+ run(options: InitxOptions, ...others: string[]): Promise<void>;
11
31
  private isObject;
12
32
  private isPassed;
13
33
  }
14
34
 
15
- export { InitxHandler };
35
+ export { InitxHandler, type InitxOptions };
package/dist/index.mjs CHANGED
@@ -1,33 +1,33 @@
1
1
  class InitxHandler {
2
- async run(value, ...others) {
2
+ async run(options, ...others) {
3
3
  if (this.isObject(this.matchers)) {
4
4
  const keys = Object.keys(this.matchers);
5
5
  for (let i = 0; i < keys.length; i++) {
6
6
  const matcher = this.matchers[keys[i]];
7
- const isPassed2 = this.isPassed(matcher, value);
7
+ const isPassed2 = this.isPassed(matcher, options.key);
8
8
  if (isPassed2) {
9
- this.handle(value, keys[i], ...others);
9
+ this.handle(options, keys[i], ...others);
10
10
  break;
11
11
  }
12
12
  }
13
13
  return;
14
14
  }
15
- const isPassed = this.isPassed(this.matchers, value);
15
+ const isPassed = this.isPassed(this.matchers, options.key);
16
16
  if (!isPassed) {
17
17
  return;
18
18
  }
19
- await this.handle(value, ...others);
19
+ await this.handle(options, ...others);
20
20
  }
21
21
  isObject(value) {
22
22
  return typeof value === "object" && value !== null && !Array.isArray(value);
23
23
  }
24
- isPassed(matchers, value) {
24
+ isPassed(matchers, key) {
25
25
  const tests = Array.isArray(matchers) ? matchers : [matchers];
26
26
  return tests.some((test) => {
27
27
  if (typeof test === "string") {
28
- return test === value;
28
+ return test === key;
29
29
  }
30
- return test.test(value);
30
+ return test.test(key);
31
31
  });
32
32
  }
33
33
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@initx-plugin/core",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "description": "core module for initx plugins",
6
6
  "author": "imba97",
7
7
  "license": "MIT",