@0x-jerry/x 2.6.0 → 2.7.0

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.
@@ -0,0 +1,6 @@
1
+ // package.json
2
+ var version = "2.7.0";
3
+
4
+ export {
5
+ version
6
+ };
package/dist/x.js CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ version
4
+ } from "./chunk-XHPSW76M.js";
2
5
 
3
6
  // src/x.ts
4
7
  import { sliver } from "@0x-jerry/silver";
@@ -101,12 +104,12 @@ import { bootstrap } from "global-agent";
101
104
  bootstrap({
102
105
  environmentVariableNamespace: ""
103
106
  });
104
- var ins = sliver`
105
- @help @autocompletion
107
+ sliver`
108
+ v${version} @autocompletion
106
109
 
107
- x, Some useful subcommand.
110
+ x, has some useful subcommand.
108
111
 
109
- t/template [dest path], download git repo as a template. ${defaultAction}
112
+ t/template [dest], download git repo as a template. ${defaultAction}
110
113
 
111
114
  -u --url, Git url to download with. eg. -u 0x-jerry/x, -u https://github.com/0x-jerry/x
112
115
  -b --branch, Git branch.
package/dist/xn.js CHANGED
@@ -4,6 +4,9 @@ import {
4
4
  exists,
5
5
  flagOptionToStringArray
6
6
  } from "./chunk-WA6Z2RU3.js";
7
+ import {
8
+ version
9
+ } from "./chunk-XHPSW76M.js";
7
10
 
8
11
  // src/xn.ts
9
12
  import { sliver } from "@0x-jerry/silver";
@@ -17,7 +20,7 @@ var DenoDependencyManager = class {
17
20
  return pathExists(path.join(cwd, "deno.json")) || pathExists(path.join(cwd, "deno.jsonc"));
18
21
  }
19
22
  async install(option) {
20
- await exec("deno", ["cache"]);
23
+ throw new Error("Deno project do not need to install dependencies");
21
24
  }
22
25
  async add(modules, option) {
23
26
  await exec("deno", ["add", ...modules]);
@@ -43,18 +46,24 @@ var NodeDependencyManager = class {
43
46
  await runDepManagerCommand("install");
44
47
  }
45
48
  async add(modules, option = {}) {
46
- await runDepManagerCommand("add", ...modules);
47
- if (option.type) {
49
+ const { t, types, ...otherOption } = option;
50
+ await runDepManagerCommand(
51
+ "add",
52
+ ...modules,
53
+ ...flagOptionToStringArray(otherOption)
54
+ );
55
+ if (types) {
48
56
  const typeModules = modules.map((pkg) => getTypePackageName(pkg));
49
57
  await runDepManagerCommand("add", ...typeModules, "-D");
50
58
  }
51
59
  }
52
60
  async remove(modules, option = {}) {
53
- await runDepManagerCommand(
54
- "remove",
55
- ...modules,
56
- ...flagOptionToStringArray(option)
57
- );
61
+ console.log(option);
62
+ if (option.types) {
63
+ const typeModules = modules.map((pkg) => getTypePackageName(pkg));
64
+ modules.push(...typeModules);
65
+ }
66
+ await runDepManagerCommand("remove", ...modules);
58
67
  }
59
68
  async upgrade(modules, option = {}) {
60
69
  await runDepManagerCommand(
@@ -185,51 +194,63 @@ var DepManager = class {
185
194
  ;
186
195
  (await this._getManager())?.install(option);
187
196
  }
188
- async add(modules, option) {
197
+ async add(params, option) {
189
198
  ;
190
- (await this._getManager())?.add(modules, option);
199
+ (await this._getManager())?.add(params, option);
191
200
  }
192
- async remove(modules, option) {
201
+ async remove(params, option) {
193
202
  ;
194
- (await this._getManager())?.remove(modules, option);
203
+ (await this._getManager())?.remove(params, option);
195
204
  }
196
- async upgrade(modules, option) {
205
+ async upgrade(params, option) {
197
206
  ;
198
- (await this._getManager())?.upgrade(modules, option);
207
+ (await this._getManager())?.upgrade(params, option);
199
208
  }
200
209
  };
201
210
 
202
211
  // src/xn.ts
203
212
  sliver`
204
- @help @autocompletion
213
+ v${version} @help @autocompletion
205
214
 
206
- xn, install dependency quickly, support node/deno/cargo. ${defaultAction}
215
+ xn, is a dependency manage tool, it is support node/deno/cargo. ${defaultAction}
207
216
 
208
- i/install [...modules] #stopEarly, install dependencies. ${installAction}
217
+ i/install [...modules], Install dependencies. ${installAction}
209
218
 
210
219
  -t --types @bool, install package's types too, only effect node project.
211
220
 
212
- up/upgrade [...modules] #stopEarly, upgrade dependencies. ${upgradeAction}
221
+ up/upgrade [...modules], Upgrade dependencies. ${upgradeAction}
213
222
 
214
- rm/remove <...modules> #stopEarly, remove dependencies. ${removeAction}
223
+ rm/remove <...modules>, Remove dependencies. ${removeAction}
224
+
225
+ -t --types @bool, remove package's types too, only effect node project.
215
226
  `;
216
227
  async function defaultAction() {
217
228
  await new DepManager().install();
218
229
  }
219
230
  async function installAction(_, opt) {
220
- const params = opt._;
231
+ const { params, options } = getParameters(opt);
221
232
  const installOnly = !params.length;
222
233
  if (installOnly) {
223
- await new DepManager().install(opt);
234
+ await new DepManager().install(options);
224
235
  return;
225
236
  }
226
- await new DepManager().add(params, opt);
237
+ await new DepManager().add(params, options);
227
238
  }
228
239
  async function upgradeAction(_, opt) {
229
- const params = opt._;
230
- await new DepManager().upgrade(params, opt);
240
+ const { params, options } = getParameters(opt);
241
+ await new DepManager().upgrade(params, options);
231
242
  }
232
243
  async function removeAction(_, opt) {
244
+ const { params, options } = getParameters(opt);
245
+ await new DepManager().remove(params, options);
246
+ }
247
+ function getParameters(opt) {
233
248
  const params = opt._;
234
- await new DepManager().remove(params, opt);
249
+ const otherOpt = { ...opt };
250
+ delete otherOpt._;
251
+ delete otherOpt["--"];
252
+ return {
253
+ params,
254
+ options: otherOpt
255
+ };
235
256
  }
package/dist/xr.js CHANGED
@@ -2,6 +2,9 @@
2
2
  import {
3
3
  exec
4
4
  } from "./chunk-WA6Z2RU3.js";
5
+ import {
6
+ version
7
+ } from "./chunk-XHPSW76M.js";
5
8
 
6
9
  // src/xr.ts
7
10
  import { sliver } from "@0x-jerry/silver";
@@ -142,7 +145,7 @@ async function getAvailableCommands() {
142
145
 
143
146
  // src/xr.ts
144
147
  var ins = sliver`
145
- @help @autocompletion
148
+ v${version} @help @autocompletion
146
149
 
147
150
  xr [@command:command] #stopEarly, run command quickly. ${defaultAction}
148
151
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0x-jerry/x",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/0x-jerry/x.git"
@@ -39,11 +39,10 @@
39
39
  "format": [
40
40
  "esm"
41
41
  ],
42
- "dts": true,
43
42
  "clean": true
44
43
  },
45
44
  "dependencies": {
46
- "@0x-jerry/silver": "^0.1.8",
45
+ "@0x-jerry/silver": "^1.0.1",
47
46
  "@0x-jerry/utils": "^2.4.2",
48
47
  "decompress": "^4.2.1",
49
48
  "fs-extra": "^11.2.0",
package/readme.md CHANGED
@@ -5,7 +5,82 @@ Some useful command for myself.
5
5
  ## Install
6
6
 
7
7
  ```sh
8
- npm i -g @0x-jerry/x
8
+ pnpm i -g @0x-jerry/x
9
+ ```
10
+
11
+ ## Run task `xr`
12
+
13
+ `xr` command can auto detect tasks in `package.json/scripts`, `deno.json/tasks`, and run it. you can also append any parameters.
14
+
15
+ Example: In a node project with `pnpm-lock.yaml`. And `package.json` has a script `"test": "vitest run"`
16
+
17
+ ```sh
18
+ xr test test/*.ts
19
+ # equals
20
+ vitest run test/*.ts
21
+
22
+ # you can also execute binary file in `node_modules/.bin` folder.
23
+ xr vite --port 4004
24
+ ```
25
+
26
+ Example: In a deno project with `deno.json` or `deno.jsonc`. And have a task `"dev": "deno run -A main.ts"`
27
+
28
+ ```sh
29
+ xr dev
30
+ # equals
31
+ deno run -A main.ts
32
+ ```
33
+
34
+ ## Dependency Manager `xn`
35
+
36
+ `xn` command can install modules by detect the correct tool, it detects lockfile to decide which dependency manager tools should be used.
37
+
38
+ Example: install packages in a node project with `pnpm-lock.yaml`
39
+
40
+ ```sh
41
+ xn i lodash-es
42
+ # equals
43
+ pnpm i lodash-es
44
+
45
+ xn i lodash-es -D
46
+ # equals
47
+ pnpm i lodash-es -D
48
+
49
+ # -t/--types option support install @types/xx package in one command.
50
+ xn i lodash-es --types
51
+ # equals
52
+ pnpm i lodash-es && pnpm i @types/lodash-es -D
53
+ ```
54
+
55
+ Example: remove packages in a node project with `pnpm-lock.yaml`
56
+
57
+ ```sh
58
+ xn rm lodash-es
59
+ # equals
60
+ pnpm uninstall lodash-es
61
+
62
+ xn rm lodash-es -D
63
+ # equals
64
+ pnpm uninstall lodash-es -D
65
+
66
+ # -t/--types option support remove @types/xx package in one command.
67
+ xn rm lodash-es --types
68
+ # equals
69
+ pnpm uninstall lodash-es @types/lodash-es
70
+ ```
71
+
72
+ `xn` also support rust project.
73
+
74
+ Example: in a rust project with `Cargo.toml`
75
+
76
+ ```sh
77
+ xn i log
78
+ # equals
79
+ cargo add log
80
+
81
+ xn rm log
82
+ # equals
83
+ cargo remove log
9
84
  ```
10
85
 
11
86
  ## Command Completions
package/dist/x.d.ts DELETED
@@ -1 +0,0 @@
1
- #!/usr/bin/env node
package/dist/xn.d.ts DELETED
@@ -1 +0,0 @@
1
- #!/usr/bin/env node
package/dist/xr.d.ts DELETED
@@ -1 +0,0 @@
1
- #!/usr/bin/env node