@initx-plugin/core 0.0.6 → 0.0.8

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.cjs ADDED
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ class InitxHandler {
4
+ run(options, ...others) {
5
+ const handlers = [];
6
+ if (!Array.isArray(this.matchers) && this.matchers.matching && this.matchers.description && this.isPassed(this.matchers.matching, options.key)) {
7
+ handlers.push({
8
+ handler: () => this.handle(options, ...others),
9
+ description: this.matchers.description
10
+ });
11
+ return handlers;
12
+ }
13
+ if (this.isObject(this.matchers)) {
14
+ const keys = Object.keys(this.matchers);
15
+ for (let i = 0; i < keys.length; i++) {
16
+ const matcher = this.matchers[keys[i]];
17
+ const isPassed = this.isPassed(matcher.matching, options.key);
18
+ if (isPassed) {
19
+ handlers.push({
20
+ handler: () => this.handle(options, keys[i], ...others),
21
+ description: matcher.description
22
+ });
23
+ break;
24
+ }
25
+ }
26
+ return handlers;
27
+ }
28
+ for (let i = 0; i < this.matchers.length; i++) {
29
+ const matcher = this.matchers[i];
30
+ const isPassed = this.isPassed(matcher.matching, options.key);
31
+ if (isPassed) {
32
+ handlers.push({
33
+ handler: () => this.handle(options, ...others),
34
+ description: matcher.description
35
+ });
36
+ }
37
+ }
38
+ return handlers;
39
+ }
40
+ isObject(value) {
41
+ return typeof value === "object" && value !== null && !Array.isArray(value);
42
+ }
43
+ isPassed(matchers, key) {
44
+ const tests = Array.isArray(matchers) ? matchers : [matchers];
45
+ return tests.some((test) => {
46
+ if (typeof test === "string") {
47
+ return test === key;
48
+ }
49
+ return test.test(key);
50
+ });
51
+ }
52
+ }
53
+
54
+ exports.InitxHandler = InitxHandler;
@@ -0,0 +1,47 @@
1
+ type MaybeArray<T> = T | T[];
2
+ type MaybePromise<T> = T | Promise<T>;
3
+ interface BaseMatchers {
4
+ matching: MaybeArray<string | RegExp>;
5
+ /**
6
+ * Description of the handler
7
+ *
8
+ * If multiple handlers are matched, this description will be displayed
9
+ */
10
+ description: string;
11
+ }
12
+ type TypeMatchers = Record<string, BaseMatchers>;
13
+ type Matchers = MaybeArray<BaseMatchers> | TypeMatchers;
14
+ interface HandlerInfo {
15
+ handler: () => MaybePromise<void>;
16
+ description: string;
17
+ }
18
+ interface InitxOptions {
19
+ /**
20
+ * Matching string
21
+ *
22
+ * The key that was used to match the handler
23
+ */
24
+ key: string;
25
+ /**
26
+ * CLI options
27
+ *
28
+ * cac package parsed options
29
+ */
30
+ cliOptions: Record<string, any>;
31
+ /**
32
+ * Options list
33
+ *
34
+ * cli options list, like
35
+ * @example ['--global']
36
+ */
37
+ optionsList: string[];
38
+ }
39
+ declare abstract class InitxHandler {
40
+ abstract matchers: Matchers;
41
+ abstract handle(options: InitxOptions, ...others: string[]): MaybePromise<void>;
42
+ run(options: InitxOptions, ...others: string[]): HandlerInfo[];
43
+ private isObject;
44
+ private isPassed;
45
+ }
46
+
47
+ export { InitxHandler, type InitxOptions };
package/dist/index.d.mts CHANGED
@@ -1,15 +1,47 @@
1
1
  type MaybeArray<T> = T | T[];
2
2
  type MaybePromise<T> = T | Promise<T>;
3
- type BaseMatchers = MaybeArray<string | RegExp>;
3
+ interface BaseMatchers {
4
+ matching: MaybeArray<string | RegExp>;
5
+ /**
6
+ * Description of the handler
7
+ *
8
+ * If multiple handlers are matched, this description will be displayed
9
+ */
10
+ description: string;
11
+ }
4
12
  type TypeMatchers = Record<string, BaseMatchers>;
5
- type Matchers = BaseMatchers | TypeMatchers;
13
+ type Matchers = MaybeArray<BaseMatchers> | TypeMatchers;
14
+ interface HandlerInfo {
15
+ handler: () => MaybePromise<void>;
16
+ description: string;
17
+ }
18
+ interface InitxOptions {
19
+ /**
20
+ * Matching string
21
+ *
22
+ * The key that was used to match the handler
23
+ */
24
+ key: string;
25
+ /**
26
+ * CLI options
27
+ *
28
+ * cac package parsed options
29
+ */
30
+ cliOptions: Record<string, any>;
31
+ /**
32
+ * Options list
33
+ *
34
+ * cli options list, like
35
+ * @example ['--global']
36
+ */
37
+ optionsList: string[];
38
+ }
6
39
  declare abstract class InitxHandler {
7
40
  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>;
41
+ abstract handle(options: InitxOptions, ...others: string[]): MaybePromise<void>;
42
+ run(options: InitxOptions, ...others: string[]): HandlerInfo[];
11
43
  private isObject;
12
44
  private isPassed;
13
45
  }
14
46
 
15
- export { InitxHandler };
47
+ export { InitxHandler, type InitxOptions };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,47 @@
1
1
  type MaybeArray<T> = T | T[];
2
2
  type MaybePromise<T> = T | Promise<T>;
3
- type BaseMatchers = MaybeArray<string | RegExp>;
3
+ interface BaseMatchers {
4
+ matching: MaybeArray<string | RegExp>;
5
+ /**
6
+ * Description of the handler
7
+ *
8
+ * If multiple handlers are matched, this description will be displayed
9
+ */
10
+ description: string;
11
+ }
4
12
  type TypeMatchers = Record<string, BaseMatchers>;
5
- type Matchers = BaseMatchers | TypeMatchers;
13
+ type Matchers = MaybeArray<BaseMatchers> | TypeMatchers;
14
+ interface HandlerInfo {
15
+ handler: () => MaybePromise<void>;
16
+ description: string;
17
+ }
18
+ interface InitxOptions {
19
+ /**
20
+ * Matching string
21
+ *
22
+ * The key that was used to match the handler
23
+ */
24
+ key: string;
25
+ /**
26
+ * CLI options
27
+ *
28
+ * cac package parsed options
29
+ */
30
+ cliOptions: Record<string, any>;
31
+ /**
32
+ * Options list
33
+ *
34
+ * cli options list, like
35
+ * @example ['--global']
36
+ */
37
+ optionsList: string[];
38
+ }
6
39
  declare abstract class InitxHandler {
7
40
  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>;
41
+ abstract handle(options: InitxOptions, ...others: string[]): MaybePromise<void>;
42
+ run(options: InitxOptions, ...others: string[]): HandlerInfo[];
11
43
  private isObject;
12
44
  private isPassed;
13
45
  }
14
46
 
15
- export { InitxHandler };
47
+ export { InitxHandler, type InitxOptions };
package/dist/index.mjs CHANGED
@@ -1,33 +1,50 @@
1
1
  class InitxHandler {
2
- async run(value, ...others) {
2
+ run(options, ...others) {
3
+ const handlers = [];
4
+ if (!Array.isArray(this.matchers) && this.matchers.matching && this.matchers.description && this.isPassed(this.matchers.matching, options.key)) {
5
+ handlers.push({
6
+ handler: () => this.handle(options, ...others),
7
+ description: this.matchers.description
8
+ });
9
+ return handlers;
10
+ }
3
11
  if (this.isObject(this.matchers)) {
4
12
  const keys = Object.keys(this.matchers);
5
13
  for (let i = 0; i < keys.length; i++) {
6
14
  const matcher = this.matchers[keys[i]];
7
- const isPassed2 = this.isPassed(matcher, value);
8
- if (isPassed2) {
9
- this.handle(value, keys[i], ...others);
15
+ const isPassed = this.isPassed(matcher.matching, options.key);
16
+ if (isPassed) {
17
+ handlers.push({
18
+ handler: () => this.handle(options, keys[i], ...others),
19
+ description: matcher.description
20
+ });
10
21
  break;
11
22
  }
12
23
  }
13
- return;
24
+ return handlers;
14
25
  }
15
- const isPassed = this.isPassed(this.matchers, value);
16
- if (!isPassed) {
17
- return;
26
+ for (let i = 0; i < this.matchers.length; i++) {
27
+ const matcher = this.matchers[i];
28
+ const isPassed = this.isPassed(matcher.matching, options.key);
29
+ if (isPassed) {
30
+ handlers.push({
31
+ handler: () => this.handle(options, ...others),
32
+ description: matcher.description
33
+ });
34
+ }
18
35
  }
19
- await this.handle(value, ...others);
36
+ return handlers;
20
37
  }
21
38
  isObject(value) {
22
39
  return typeof value === "object" && value !== null && !Array.isArray(value);
23
40
  }
24
- isPassed(matchers, value) {
41
+ isPassed(matchers, key) {
25
42
  const tests = Array.isArray(matchers) ? matchers : [matchers];
26
43
  return tests.some((test) => {
27
44
  if (typeof test === "string") {
28
- return test === value;
45
+ return test === key;
29
46
  }
30
- return test.test(value);
47
+ return test.test(key);
31
48
  });
32
49
  }
33
50
  }
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.8",
5
5
  "description": "core module for initx plugins",
6
6
  "author": "imba97",
7
7
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "keywords": [
17
17
  "initx"
18
18
  ],
19
- "main": "dist/index.mjs",
19
+ "main": "dist/index.cjs",
20
20
  "module": "dist/index.mjs",
21
21
  "types": "dist/index.d.ts",
22
22
  "files": [