@initx-plugin/cp 0.0.5 → 0.0.6

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,4 +1,4 @@
1
- import { InitxHandler } from '@initx-plugin/types';
1
+ import { InitxHandler } from '@initx-plugin/core';
2
2
 
3
3
  declare enum CpType {
4
4
  SSH = "ssh"
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { InitxHandler } from '@initx-plugin/types';
1
+ import { InitxHandler } from '@initx-plugin/core';
2
2
 
3
3
  declare enum CpType {
4
4
  SSH = "ssh"
package/dist/index.mjs CHANGED
@@ -1,22 +1,40 @@
1
1
  import os from 'node:os';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
3
  import { resolve } from 'node:path';
4
- import { copy } from 'copy-paste';
4
+ import clipboard from 'clipboardy';
5
5
  import { log } from '@initx-plugin/utils';
6
6
 
7
7
  class InitxHandler {
8
- async run(value, ...rest) {
9
- const tests = Array.isArray(this.matchers) ? this.matchers : [this.matchers];
10
- const passed = tests.some((test) => {
8
+ async run(value, ...others) {
9
+ if (this.isObject(this.matchers)) {
10
+ const keys = Object.keys(this.matchers);
11
+ for (let i = 0; i < keys.length; i++) {
12
+ const matcher = this.matchers[keys[i]];
13
+ const isPassed2 = this.isPassed(matcher, value);
14
+ if (isPassed2) {
15
+ this.handle(value, keys[i], ...others);
16
+ break;
17
+ }
18
+ }
19
+ return;
20
+ }
21
+ const isPassed = this.isPassed(this.matchers, value);
22
+ if (!isPassed) {
23
+ return;
24
+ }
25
+ await this.handle(value, ...others);
26
+ }
27
+ isObject(value) {
28
+ return typeof value === "object" && value !== null && !Array.isArray(value);
29
+ }
30
+ isPassed(matchers, value) {
31
+ const tests = Array.isArray(matchers) ? matchers : [matchers];
32
+ return tests.some((test) => {
11
33
  if (typeof test === "string") {
12
34
  return test === value;
13
35
  }
14
36
  return test.test(value);
15
37
  });
16
- if (!passed) {
17
- return;
18
- }
19
- await this.handle(value, ...rest);
20
38
  }
21
39
  }
22
40
 
@@ -53,19 +71,11 @@ class CpHandler extends InitxHandler {
53
71
  return;
54
72
  }
55
73
  const publicKey = readFileSync(publicKeyPath, "utf8");
56
- await this.copy(publicKey);
74
+ this.copy(publicKey);
57
75
  log.success("Public key copied to clipboard");
58
76
  }
59
77
  copy(content) {
60
- return new Promise((resolve, reject) => {
61
- copy(content, (err) => {
62
- if (err) {
63
- reject(err);
64
- return;
65
- }
66
- resolve(true);
67
- });
68
- });
78
+ clipboard.writeSync(content);
69
79
  }
70
80
  }
71
81
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@initx-plugin/cp",
3
3
  "type": "module",
4
- "version": "0.0.5",
4
+ "version": "0.0.6",
5
5
  "description": "initx plugin, copy some text to clipboard",
6
6
  "author": "imba97",
7
7
  "license": "MIT",
@@ -23,12 +23,12 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
- "copy-paste": "^1.5.3",
27
- "@initx-plugin/utils": "0.0.5"
26
+ "clipboardy": "^4.0.0",
27
+ "@initx-plugin/utils": "0.0.6"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/copy-paste": "^1.1.33",
31
- "@initx-plugin/types": "0.0.5"
31
+ "@initx-plugin/core": "0.0.6"
32
32
  },
33
33
  "scripts": {
34
34
  "stub": "unbuild --stub",