@initx-plugin/cp 0.0.13 → 0.0.15

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.
Files changed (3) hide show
  1. package/README.md +15 -1
  2. package/dist/index.mjs +19 -6
  3. package/package.json +29 -9
package/README.md CHANGED
@@ -8,6 +8,20 @@
8
8
 
9
9
  Copy plugin for `initx`
10
10
 
11
+ ## Usage
12
+
13
+ ```bash
14
+ npm install @initx-plugin/cp -g
15
+ ```
16
+
17
+ Copy some text to clipboard
18
+
19
+ ### SSH Public Key
20
+
21
+ ```bash
22
+ npx initx cp ssh
23
+ ```
24
+
11
25
  ## Documentation
12
26
 
13
- [initx](https://github.com/imba97/initx)
27
+ [initx](https://github.com/initx-collective/initx)
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import os from 'node:os';
2
- import { existsSync, readFileSync } from 'node:fs';
2
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
3
3
  import { resolve } from 'node:path';
4
4
  import clipboard from 'clipboardy';
5
5
  import { InitxHandler } from '@initx-plugin/core';
6
- import { log } from '@initx-plugin/utils';
6
+ import { log, inquirer } from '@initx-plugin/utils';
7
7
 
8
8
  var CpType = /* @__PURE__ */ ((CpType2) => {
9
9
  CpType2["SSH"] = "ssh";
@@ -36,14 +36,27 @@ class CpHandler extends InitxHandler {
36
36
  }
37
37
  async [CpType.SSH]() {
38
38
  const sshDir = resolve(os.homedir(), ".ssh");
39
- const publicKeyPath = resolve(sshDir, "id_rsa.pub");
40
- if (!existsSync(publicKeyPath)) {
41
- log.error(`SSH key not found, path: ${publicKeyPath}`);
39
+ if (!existsSync(sshDir)) {
40
+ log.error(`SSH directory not found, path: ${sshDir}`);
42
41
  return;
43
42
  }
43
+ const publicKeysName = readdirSync(sshDir).filter((file) => file.endsWith(".pub"));
44
+ if (publicKeysName.length === 0) {
45
+ log.error("SSH key not found");
46
+ return;
47
+ }
48
+ let publicKeyName;
49
+ if (publicKeysName.length === 1) {
50
+ const [firstKey] = publicKeysName;
51
+ publicKeyName = firstKey;
52
+ } else {
53
+ const index = await inquirer.select("Select SSH key", publicKeysName);
54
+ publicKeyName = publicKeysName[index];
55
+ }
56
+ const publicKeyPath = resolve(sshDir, publicKeyName);
44
57
  const publicKey = readFileSync(publicKeyPath, "utf8");
45
58
  this.copy(publicKey);
46
- log.success("Public key copied to clipboard");
59
+ log.success("Key copied to clipboard");
47
60
  }
48
61
  copy(content) {
49
62
  clipboard.writeSync(content);
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "name": "@initx-plugin/cp",
3
3
  "type": "module",
4
- "version": "0.0.13",
4
+ "version": "0.0.15",
5
5
  "description": "initx plugin, copy some text to clipboard",
6
6
  "author": "imba97",
7
7
  "license": "MIT",
8
- "homepage": "https://github.com/imba97/initx#readme",
8
+ "homepage": "https://github.com/initx-collective/initx-plugin-cp#readme",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+ssh://git@github.com/imba97/initx"
11
+ "url": "git@github.com:initx-collective/initx-plugin-cp.git"
12
12
  },
13
13
  "bugs": {
14
- "url": "https://github.com/imba97/initx/issues"
14
+ "url": "https://github.com/initx-collective/initx-plugin-cp/issues"
15
15
  },
16
16
  "keywords": [
17
- "initx"
17
+ "initx-plugin",
18
+ "copy"
18
19
  ],
19
20
  "main": "dist/index.mjs",
20
21
  "module": "dist/index.mjs",
@@ -23,12 +24,31 @@
23
24
  "dist"
24
25
  ],
25
26
  "dependencies": {
26
- "clipboardy": "^4.0.0",
27
- "@initx-plugin/core": "0.0.13",
28
- "@initx-plugin/utils": "0.0.13"
27
+ "@initx-plugin/core": "latest",
28
+ "@initx-plugin/utils": "latest",
29
+ "clipboardy": "^4.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "@imba97/eslint-config": "^0.0.4",
33
+ "@types/node": "^22.8.6",
34
+ "bumpp": "^9.8.0",
35
+ "eslint": "^9.13.0",
36
+ "lint-staged": "^15.2.10",
37
+ "simple-git-hooks": "^2.11.1",
38
+ "typescript": "5.5.4",
39
+ "unbuild": "^2.0.0",
40
+ "vitest": "^2.1.4"
41
+ },
42
+ "simple-git-hooks": {
43
+ "pre-commit": "pnpm lint-staged"
44
+ },
45
+ "lint-staged": {
46
+ "*": "eslint --cache --flag unstable_ts_config --fix"
29
47
  },
30
48
  "scripts": {
31
49
  "stub": "unbuild --stub",
32
- "build": "unbuild"
50
+ "build": "unbuild",
51
+ "lint": "eslint --cache --flag unstable_ts_config",
52
+ "release": "bumpp"
33
53
  }
34
54
  }