@simon_he/pi 0.0.13 → 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
@@ -79,5 +79,8 @@ export PI_SPINNER=star # loadingstyle
79
79
  - [ccommand](https://github.com/Simon-He95/ccommand)
80
80
 
81
81
 
82
+ ## License
83
+ [MIT](./LICENSE) License © 2022 [Simon He](https://github.com/Simon-He95)
84
+
82
85
  ## :coffee:
83
86
  <a href="https://github.com/Simon-He95/sponsor" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>
package/dist/index.cjs CHANGED
@@ -16,7 +16,7 @@ const process__default = /*#__PURE__*/_interopDefaultLegacy(process);
16
16
  const ora__default = /*#__PURE__*/_interopDefaultLegacy(ora);
17
17
  const fg__default = /*#__PURE__*/_interopDefaultLegacy(fg);
18
18
 
19
- const version = "0.0.13";
19
+ const version = "0.0.14";
20
20
 
21
21
  const rootPath = process__default.cwd();
22
22
  const __filename$1 = url$1.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href)));
@@ -25,8 +25,10 @@ const url = path__default.resolve(__dirname$1, "./seprateThread.mjs");
25
25
  async function pi(params, pkg) {
26
26
  const text = pkg ? `Installing ${pkg} ...
27
27
  ` : "Updating dependency ...\n";
28
- const successMsg = pkg ? `Installed ${pkg} successfully! \u{1F60A}` : "Updated dependency successfully! \u{1F60A}";
29
- const failMsg = pkg ? `Failed to install ${pkg} \u{1F62D}` : "Failed to update dependency! \u{1F62D}";
28
+ const successMsg = pkg ? `
29
+ Installed ${pkg} successfully! \u{1F60A}` : "Updated dependency successfully! \u{1F60A}";
30
+ const failMsg = pkg ? `
31
+ Failed to install ${pkg} \u{1F62D}` : "Failed to update dependency! \u{1F62D}";
30
32
  const loading_status = await loading(text);
31
33
  const { status } = await simonJsTool.useNodeWorker(url, `ni ${params}`);
32
34
  if (status === 0)
@@ -38,8 +40,10 @@ async function pi(params, pkg) {
38
40
  async function pui(params, pkg) {
39
41
  const text = `Uninstalling ${pkg} ...
40
42
  `;
41
- const successMsg = `unInstalled ${pkg} successfully! \u{1F60A}`;
42
- const failMsg = `Failed to uninstall ${pkg} \u{1F62D}`;
43
+ const successMsg = `
44
+ UnInstalled ${pkg} successfully! \u{1F60A}`;
45
+ const failMsg = `
46
+ Failed to uninstall ${pkg} \u{1F62D}`;
43
47
  if (!pkg) {
44
48
  console.log("Need to specify an uninstall package name");
45
49
  process__default.exit(1);
@@ -128,6 +132,11 @@ async function loading(text) {
128
132
  }).start();
129
133
  return result;
130
134
  }
135
+ function hasPkg() {
136
+ const url2 = path__default.resolve(rootPath, "package.json");
137
+ const { result } = simonJsTool.jsShell(`test -f "${url2}" && echo "0"|| echo "1"`, "pipe");
138
+ return result === "0";
139
+ }
131
140
  async function runner() {
132
141
  const cmd = process__default.argv[1];
133
142
  const last = cmd.lastIndexOf("/") + 1;
@@ -135,71 +144,73 @@ async function runner() {
135
144
  const argv = process__default.argv.slice(2);
136
145
  returnVersion(argv);
137
146
  const params = argv.join(" ").trim();
138
- if (isGo()) {
139
- if (exec === "pi") {
140
- const loading_status = await loading(`Installing ${params} ...
147
+ if (!hasPkg()) {
148
+ if (isGo()) {
149
+ if (exec === "pi") {
150
+ const loading_status = await loading(`Installing ${params} ...
141
151
  `);
142
- const { status } = await simonJsTool.useNodeWorker(url, `go get ${params}`);
143
- if (status === 0)
144
- loading_status.succeed("Installed successfully! \u{1F60A}");
145
- else
146
- loading_status.fail("Failed to install \u{1F62D}");
147
- } else if (exec === "pui") {
148
- const loading_status = await loading(`Uninstalling ${params} ...
152
+ const { status } = await simonJsTool.useNodeWorker(url, `go get ${params}`);
153
+ if (status === 0)
154
+ loading_status.succeed("Installed successfully! \u{1F60A}");
155
+ else
156
+ loading_status.fail("Failed to install \u{1F62D}");
157
+ } else if (exec === "pui") {
158
+ const loading_status = await loading(`Uninstalling ${params} ...
149
159
  `);
150
- const { status } = await simonJsTool.useNodeWorker(url, `go clean ${params}`);
151
- if (status === 0)
152
- loading_status.succeed("Uninstalled successfully! \u{1F60A}");
153
- else
154
- loading_status.fail("Failed to uninstall \u{1F62D}");
155
- } else if (exec === "prun") {
156
- const match = params ? params.endsWith(".go") ? [`**/${params}`] : [`**/${params}.go`, `**/${params}/main.go`] : "main.go";
157
- const target = (await fg__default(match))[0];
158
- if (!target) {
159
- console.log("No such file");
160
- process__default.exit(1);
160
+ const { status } = await simonJsTool.useNodeWorker(url, `go clean ${params}`);
161
+ if (status === 0)
162
+ loading_status.succeed("Uninstalled successfully! \u{1F60A}");
163
+ else
164
+ loading_status.fail("Failed to uninstall \u{1F62D}");
165
+ } else if (exec === "prun") {
166
+ const match = params ? params.endsWith(".go") ? [`**/${params}`] : [`**/${params}.go`, `**/${params}/main.go`] : "main.go";
167
+ const target = (await fg__default(match))[0];
168
+ if (!target) {
169
+ console.log("No such file");
170
+ process__default.exit(1);
171
+ }
172
+ simonJsTool.jsShell(`go run ${target}`);
173
+ } else if (exec === "pinit") {
174
+ simonJsTool.jsShell(`go mod init ${params}`);
175
+ } else if (exec === "pbuild") {
176
+ simonJsTool.jsShell(`go build ${params}`);
177
+ } else {
178
+ console.log("The commands is not supported");
161
179
  }
162
- simonJsTool.jsShell(`go run ${target}`);
163
- } else if (exec === "pinit") {
164
- simonJsTool.jsShell(`go mod init ${params}`);
165
- } else if (exec === "pbuild") {
166
- simonJsTool.jsShell(`go build ${params}`);
167
- } else {
168
- console.log("The commands is not supported");
180
+ process__default.exit();
169
181
  }
170
- process__default.exit();
171
- }
172
- if (isRust()) {
173
- if (exec === "pi") {
174
- const loading_status = await loading(`Installing ${params} ...
182
+ if (isRust()) {
183
+ if (exec === "pi") {
184
+ const loading_status = await loading(`Installing ${params} ...
175
185
  `);
176
- const { status } = await simonJsTool.useNodeWorker(url, `cargo install ${params}`);
177
- if (status === 0)
178
- loading_status.succeed("installed successfully! \u{1F60A}");
179
- else
180
- loading_status.fail("Failed to install \u{1F62D}");
181
- } else if (exec === "pui") {
182
- const loading_status = await loading(`Uninstalling ${params} ...
186
+ const { status } = await simonJsTool.useNodeWorker(url, `cargo install ${params}`);
187
+ if (status === 0)
188
+ loading_status.succeed("Installed successfully! \u{1F60A}");
189
+ else
190
+ loading_status.fail("Failed to install \u{1F62D}");
191
+ } else if (exec === "pui") {
192
+ const loading_status = await loading(`Uninstalling ${params} ...
183
193
  `);
184
- const { status } = await simonJsTool.useNodeWorker(url, `cargo uninstall ${params}`);
185
- if (status === 0)
186
- loading_status.succeed("Uninstalled successfully! \u{1F60A}");
187
- else
188
- loading_status.fail("Failed to uninstall \u{1F62D}");
189
- } else if (exec === "prun") {
190
- simonJsTool.jsShell(`cargo run ${params}`);
191
- } else if (exec === "pinit") {
192
- simonJsTool.jsShell(`cargo init ${params}`);
193
- } else if (exec === "pbuild") {
194
- simonJsTool.jsShell(`cargo build ${params}`);
195
- } else {
196
- console.log("The commands is not supported");
194
+ const { status } = await simonJsTool.useNodeWorker(url, `cargo uninstall ${params}`);
195
+ if (status === 0)
196
+ loading_status.succeed("Uninstalled successfully! \u{1F60A}");
197
+ else
198
+ loading_status.fail("Failed to uninstall \u{1F62D}");
199
+ } else if (exec === "prun") {
200
+ simonJsTool.jsShell(`cargo run ${params}`);
201
+ } else if (exec === "pinit") {
202
+ simonJsTool.jsShell(`cargo init ${params}`);
203
+ } else if (exec === "pbuild") {
204
+ simonJsTool.jsShell(`cargo build ${params}`);
205
+ } else {
206
+ console.log("The commands is not supported");
207
+ }
208
+ process__default.exit();
209
+ }
210
+ if (!runMap[exec]) {
211
+ console.log("The command does not exist, please execute pi -h to view the help");
212
+ return;
197
213
  }
198
- process__default.exit();
199
- }
200
- if (!runMap[exec]) {
201
- console.log("The command does not exist, please execute pi -h to view the help");
202
- return;
203
214
  }
204
215
  const pkg = argv.filter((v) => !v.startsWith("-")).join(" ");
205
216
  await installDeps();
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import { useNodeWorker, jsShell, getPkgTool } from 'simon-js-tool';
5
5
  import ora from 'ora';
6
6
  import fg from 'fast-glob';
7
7
 
8
- const version = "0.0.13";
8
+ const version = "0.0.14";
9
9
 
10
10
  const rootPath = process.cwd();
11
11
  const __filename = fileURLToPath(import.meta.url);
@@ -14,8 +14,10 @@ const url = path.resolve(__dirname, "./seprateThread.mjs");
14
14
  async function pi(params, pkg) {
15
15
  const text = pkg ? `Installing ${pkg} ...
16
16
  ` : "Updating dependency ...\n";
17
- const successMsg = pkg ? `Installed ${pkg} successfully! \u{1F60A}` : "Updated dependency successfully! \u{1F60A}";
18
- const failMsg = pkg ? `Failed to install ${pkg} \u{1F62D}` : "Failed to update dependency! \u{1F62D}";
17
+ const successMsg = pkg ? `
18
+ Installed ${pkg} successfully! \u{1F60A}` : "Updated dependency successfully! \u{1F60A}";
19
+ const failMsg = pkg ? `
20
+ Failed to install ${pkg} \u{1F62D}` : "Failed to update dependency! \u{1F62D}";
19
21
  const loading_status = await loading(text);
20
22
  const { status } = await useNodeWorker(url, `ni ${params}`);
21
23
  if (status === 0)
@@ -27,8 +29,10 @@ async function pi(params, pkg) {
27
29
  async function pui(params, pkg) {
28
30
  const text = `Uninstalling ${pkg} ...
29
31
  `;
30
- const successMsg = `unInstalled ${pkg} successfully! \u{1F60A}`;
31
- const failMsg = `Failed to uninstall ${pkg} \u{1F62D}`;
32
+ const successMsg = `
33
+ UnInstalled ${pkg} successfully! \u{1F60A}`;
34
+ const failMsg = `
35
+ Failed to uninstall ${pkg} \u{1F62D}`;
32
36
  if (!pkg) {
33
37
  console.log("Need to specify an uninstall package name");
34
38
  process.exit(1);
@@ -117,6 +121,11 @@ async function loading(text) {
117
121
  }).start();
118
122
  return result;
119
123
  }
124
+ function hasPkg() {
125
+ const url2 = path.resolve(rootPath, "package.json");
126
+ const { result } = jsShell(`test -f "${url2}" && echo "0"|| echo "1"`, "pipe");
127
+ return result === "0";
128
+ }
120
129
  async function runner() {
121
130
  const cmd = process.argv[1];
122
131
  const last = cmd.lastIndexOf("/") + 1;
@@ -124,71 +133,73 @@ async function runner() {
124
133
  const argv = process.argv.slice(2);
125
134
  returnVersion(argv);
126
135
  const params = argv.join(" ").trim();
127
- if (isGo()) {
128
- if (exec === "pi") {
129
- const loading_status = await loading(`Installing ${params} ...
136
+ if (!hasPkg()) {
137
+ if (isGo()) {
138
+ if (exec === "pi") {
139
+ const loading_status = await loading(`Installing ${params} ...
130
140
  `);
131
- const { status } = await useNodeWorker(url, `go get ${params}`);
132
- if (status === 0)
133
- loading_status.succeed("Installed successfully! \u{1F60A}");
134
- else
135
- loading_status.fail("Failed to install \u{1F62D}");
136
- } else if (exec === "pui") {
137
- const loading_status = await loading(`Uninstalling ${params} ...
141
+ const { status } = await useNodeWorker(url, `go get ${params}`);
142
+ if (status === 0)
143
+ loading_status.succeed("Installed successfully! \u{1F60A}");
144
+ else
145
+ loading_status.fail("Failed to install \u{1F62D}");
146
+ } else if (exec === "pui") {
147
+ const loading_status = await loading(`Uninstalling ${params} ...
138
148
  `);
139
- const { status } = await useNodeWorker(url, `go clean ${params}`);
140
- if (status === 0)
141
- loading_status.succeed("Uninstalled successfully! \u{1F60A}");
142
- else
143
- loading_status.fail("Failed to uninstall \u{1F62D}");
144
- } else if (exec === "prun") {
145
- const match = params ? params.endsWith(".go") ? [`**/${params}`] : [`**/${params}.go`, `**/${params}/main.go`] : "main.go";
146
- const target = (await fg(match))[0];
147
- if (!target) {
148
- console.log("No such file");
149
- process.exit(1);
149
+ const { status } = await useNodeWorker(url, `go clean ${params}`);
150
+ if (status === 0)
151
+ loading_status.succeed("Uninstalled successfully! \u{1F60A}");
152
+ else
153
+ loading_status.fail("Failed to uninstall \u{1F62D}");
154
+ } else if (exec === "prun") {
155
+ const match = params ? params.endsWith(".go") ? [`**/${params}`] : [`**/${params}.go`, `**/${params}/main.go`] : "main.go";
156
+ const target = (await fg(match))[0];
157
+ if (!target) {
158
+ console.log("No such file");
159
+ process.exit(1);
160
+ }
161
+ jsShell(`go run ${target}`);
162
+ } else if (exec === "pinit") {
163
+ jsShell(`go mod init ${params}`);
164
+ } else if (exec === "pbuild") {
165
+ jsShell(`go build ${params}`);
166
+ } else {
167
+ console.log("The commands is not supported");
150
168
  }
151
- jsShell(`go run ${target}`);
152
- } else if (exec === "pinit") {
153
- jsShell(`go mod init ${params}`);
154
- } else if (exec === "pbuild") {
155
- jsShell(`go build ${params}`);
156
- } else {
157
- console.log("The commands is not supported");
169
+ process.exit();
158
170
  }
159
- process.exit();
160
- }
161
- if (isRust()) {
162
- if (exec === "pi") {
163
- const loading_status = await loading(`Installing ${params} ...
171
+ if (isRust()) {
172
+ if (exec === "pi") {
173
+ const loading_status = await loading(`Installing ${params} ...
164
174
  `);
165
- const { status } = await useNodeWorker(url, `cargo install ${params}`);
166
- if (status === 0)
167
- loading_status.succeed("installed successfully! \u{1F60A}");
168
- else
169
- loading_status.fail("Failed to install \u{1F62D}");
170
- } else if (exec === "pui") {
171
- const loading_status = await loading(`Uninstalling ${params} ...
175
+ const { status } = await useNodeWorker(url, `cargo install ${params}`);
176
+ if (status === 0)
177
+ loading_status.succeed("Installed successfully! \u{1F60A}");
178
+ else
179
+ loading_status.fail("Failed to install \u{1F62D}");
180
+ } else if (exec === "pui") {
181
+ const loading_status = await loading(`Uninstalling ${params} ...
172
182
  `);
173
- const { status } = await useNodeWorker(url, `cargo uninstall ${params}`);
174
- if (status === 0)
175
- loading_status.succeed("Uninstalled successfully! \u{1F60A}");
176
- else
177
- loading_status.fail("Failed to uninstall \u{1F62D}");
178
- } else if (exec === "prun") {
179
- jsShell(`cargo run ${params}`);
180
- } else if (exec === "pinit") {
181
- jsShell(`cargo init ${params}`);
182
- } else if (exec === "pbuild") {
183
- jsShell(`cargo build ${params}`);
184
- } else {
185
- console.log("The commands is not supported");
183
+ const { status } = await useNodeWorker(url, `cargo uninstall ${params}`);
184
+ if (status === 0)
185
+ loading_status.succeed("Uninstalled successfully! \u{1F60A}");
186
+ else
187
+ loading_status.fail("Failed to uninstall \u{1F62D}");
188
+ } else if (exec === "prun") {
189
+ jsShell(`cargo run ${params}`);
190
+ } else if (exec === "pinit") {
191
+ jsShell(`cargo init ${params}`);
192
+ } else if (exec === "pbuild") {
193
+ jsShell(`cargo build ${params}`);
194
+ } else {
195
+ console.log("The commands is not supported");
196
+ }
197
+ process.exit();
198
+ }
199
+ if (!runMap[exec]) {
200
+ console.log("The command does not exist, please execute pi -h to view the help");
201
+ return;
186
202
  }
187
- process.exit();
188
- }
189
- if (!runMap[exec]) {
190
- console.log("The command does not exist, please execute pi -h to view the help");
191
- return;
192
203
  }
193
204
  const pkg = argv.filter((v) => !v.startsWith("-")).join(" ");
194
205
  await installDeps();
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Anthony Fu <https://github.com/antfu>
3
+ Copyright (c) 2022 Simon He
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simon_he/pi",
3
3
  "type": "module",
4
- "version": "0.0.13",
4
+ "version": "0.0.14",
5
5
  "packageManager": "pnpm@7.2.1",
6
6
  "description": "",
7
7
  "author": "Simon He",