@initx-plugin/cp 0.0.12 → 0.0.14

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
- <h1 align="center">init 🛠</h1>
1
+ <h1 align="center">initx ⚙️</h1>
2
2
 
3
- <p align="center"><code>initx</code> More convenient initialization engine</p>
3
+ <p align="center"><code>initx</code> A more convenient scripting engine</p>
4
4
 
5
5
  <pre align="center">npx <b>initx &lt;something&gt;</b></pre>
6
6
 
@@ -10,4 +10,4 @@ Copy plugin for `initx`
10
10
 
11
11
  ## Documentation
12
12
 
13
- [initx](https://github.com/imba97/initx)
13
+ [initx](https://github.com/initx-collective/initx)
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { InitxHandler, InitxOptions } from '@initx-plugin/core';
1
+ import { InitxHandler, InitxCtx } from '@initx-plugin/core';
2
2
 
3
3
  declare enum CpType {
4
4
  SSH = "ssh"
@@ -9,7 +9,7 @@ declare class CpHandler extends InitxHandler {
9
9
  matching: string;
10
10
  description: string;
11
11
  }[];
12
- handle(_options: InitxOptions, cpType: CpType, ...others: string[]): Promise<void>;
12
+ handle(_ctx: InitxCtx, cpType: CpType, ...others: string[]): Promise<void>;
13
13
  [CpType.SSH](): Promise<void>;
14
14
  private copy;
15
15
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { InitxHandler, InitxOptions } from '@initx-plugin/core';
1
+ import { InitxHandler, InitxCtx } from '@initx-plugin/core';
2
2
 
3
3
  declare enum CpType {
4
4
  SSH = "ssh"
@@ -9,7 +9,7 @@ declare class CpHandler extends InitxHandler {
9
9
  matching: string;
10
10
  description: string;
11
11
  }[];
12
- handle(_options: InitxOptions, cpType: CpType, ...others: string[]): Promise<void>;
12
+ handle(_ctx: InitxCtx, cpType: CpType, ...others: string[]): Promise<void>;
13
13
  [CpType.SSH](): Promise<void>;
14
14
  private copy;
15
15
  }
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";
@@ -26,7 +26,7 @@ class CpHandler extends InitxHandler {
26
26
  }
27
27
  ]);
28
28
  }
29
- async handle(_options, cpType, ...others) {
29
+ async handle(_ctx, cpType, ...others) {
30
30
  if (!cpType || typeof this[cpType] !== "function") {
31
31
  const typeList = CpType;
32
32
  log.error(`Please enter the copy type, Available types: ${Object.keys(typeList).map((key) => typeList[key])}`);
@@ -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.12",
4
+ "version": "0.0.14",
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.12",
28
- "@initx-plugin/utils": "0.0.12"
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.2",
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
  }