@initx-plugin/cp 0.0.5

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 imba97 <https://github.com/imba97>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ <h1 align="center">init 🛠</h1>
2
+
3
+ <p align="center"><code>initx</code> More convenient initialization tool</p>
4
+
5
+ <pre align="center">npx <b>initx &lt;something&gt;</b></pre>
6
+
7
+ ## @initx-plugin/cp
8
+
9
+ Copy some text to clipboard
10
+
11
+ ## Documentation
12
+
13
+ [initx](https://github.com/imba97/initx)
@@ -0,0 +1,14 @@
1
+ import { InitxHandler } from '@initx-plugin/types';
2
+
3
+ declare enum CpType {
4
+ SSH = "ssh"
5
+ }
6
+
7
+ declare class CpHandler extends InitxHandler {
8
+ matchers: string[];
9
+ handle(_command: string, cpType: CpType, ...rest: string[]): Promise<void>;
10
+ [CpType.SSH](): Promise<void>;
11
+ private copy;
12
+ }
13
+
14
+ export { CpHandler };
@@ -0,0 +1,14 @@
1
+ import { InitxHandler } from '@initx-plugin/types';
2
+
3
+ declare enum CpType {
4
+ SSH = "ssh"
5
+ }
6
+
7
+ declare class CpHandler extends InitxHandler {
8
+ matchers: string[];
9
+ handle(_command: string, cpType: CpType, ...rest: string[]): Promise<void>;
10
+ [CpType.SSH](): Promise<void>;
11
+ private copy;
12
+ }
13
+
14
+ export { CpHandler };
package/dist/index.mjs ADDED
@@ -0,0 +1,72 @@
1
+ import os from 'node:os';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { resolve } from 'node:path';
4
+ import { copy } from 'copy-paste';
5
+ import { log } from '@initx-plugin/utils';
6
+
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) => {
11
+ if (typeof test === "string") {
12
+ return test === value;
13
+ }
14
+ return test.test(value);
15
+ });
16
+ if (!passed) {
17
+ return;
18
+ }
19
+ await this.handle(value, ...rest);
20
+ }
21
+ }
22
+
23
+ var CpType = /* @__PURE__ */ ((CpType2) => {
24
+ CpType2["SSH"] = "ssh";
25
+ return CpType2;
26
+ })(CpType || {});
27
+
28
+ var __defProp = Object.defineProperty;
29
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
30
+ var __publicField = (obj, key, value) => {
31
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
+ return value;
33
+ };
34
+ class CpHandler extends InitxHandler {
35
+ constructor() {
36
+ super(...arguments);
37
+ __publicField(this, "matchers", ["cp"]);
38
+ }
39
+ async handle(_command, cpType, ...rest) {
40
+ if (!cpType || typeof this[cpType] !== "function") {
41
+ return;
42
+ }
43
+ if (!Array.isArray(rest)) {
44
+ rest = [];
45
+ }
46
+ this[cpType](...rest);
47
+ }
48
+ async [CpType.SSH]() {
49
+ const sshDir = resolve(os.homedir(), ".ssh");
50
+ const publicKeyPath = resolve(sshDir, "id_rsa.pub");
51
+ if (!existsSync(publicKeyPath)) {
52
+ log.error(`SSH key not found, path: ${publicKeyPath}`);
53
+ return;
54
+ }
55
+ const publicKey = readFileSync(publicKeyPath, "utf8");
56
+ await this.copy(publicKey);
57
+ log.success("Public key copied to clipboard");
58
+ }
59
+ 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
+ });
69
+ }
70
+ }
71
+
72
+ export { CpHandler };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@initx-plugin/cp",
3
+ "type": "module",
4
+ "version": "0.0.5",
5
+ "description": "initx plugin, copy some text to clipboard",
6
+ "author": "imba97",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/imba97/initx#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+ssh://git@github.com/imba97/initx"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/imba97/initx/issues"
15
+ },
16
+ "keywords": [
17
+ "initx"
18
+ ],
19
+ "main": "dist/index.mjs",
20
+ "module": "dist/index.mjs",
21
+ "types": "dist/index.d.ts",
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "dependencies": {
26
+ "copy-paste": "^1.5.3",
27
+ "@initx-plugin/utils": "0.0.5"
28
+ },
29
+ "devDependencies": {
30
+ "@types/copy-paste": "^1.1.33",
31
+ "@initx-plugin/types": "0.0.5"
32
+ },
33
+ "scripts": {
34
+ "stub": "unbuild --stub",
35
+ "build": "unbuild"
36
+ }
37
+ }