@xx-in/tools 0.0.3 → 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/README.md +5 -5
- package/dist/cli.js +142 -52
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -65,13 +65,13 @@ npm run publish:npm:registry
|
|
|
65
65
|
- **`open [path]`**:文件管理器目录打开工具。
|
|
66
66
|
- 在系统内置文件管理器中打开指定目录。若未提供参数,则默认打开当前的工作目录。
|
|
67
67
|
|
|
68
|
-
### 2.
|
|
68
|
+
### 2. 本地工具安装管理
|
|
69
69
|
|
|
70
|
-
- **`install <path>`**:macOS 本地工具安装器。
|
|
71
|
-
- 支持安装单个可执行文件,以及 `.tar.gz`、`.tgz`、`.tar.xz`、`.txz`、`.tar` 压缩包。
|
|
70
|
+
- **`install <path>`**:macOS / Windows 本地工具安装器。
|
|
71
|
+
- 支持安装单个可执行文件,以及 `.zip`、`.tar.gz`、`.tgz`、`.tar.xz`、`.txz`、`.tar` 压缩包。
|
|
72
72
|
- 自动安装到 `~/.xx-tools/apps/`,并在 `~/.xx-tools/bin/` 创建终端命令入口。
|
|
73
|
-
-
|
|
74
|
-
- **`uninstall <package>`**:macOS 本地工具卸载器。
|
|
73
|
+
- macOS 下会自动写入 Shell 配置;Windows 下会自动写入当前用户 PATH,后续即可在终端中直接调用已安装工具。
|
|
74
|
+
- **`uninstall <package>`**:macOS / Windows 本地工具卸载器。
|
|
75
75
|
- 按安装名卸载工具,同时删除安装目录和终端命令入口。
|
|
76
76
|
|
|
77
77
|
### 3. 压缩与解压
|
package/dist/cli.js
CHANGED
|
@@ -7,7 +7,7 @@ import process4 from "process";
|
|
|
7
7
|
// package.json
|
|
8
8
|
var package_default = {
|
|
9
9
|
name: "@xx-in/tools",
|
|
10
|
-
version: "0.0.
|
|
10
|
+
version: "0.0.5",
|
|
11
11
|
description: "A command-line tool to run in any system",
|
|
12
12
|
license: "MIT",
|
|
13
13
|
type: "module",
|
|
@@ -21,7 +21,7 @@ var package_default = {
|
|
|
21
21
|
build: "tsup",
|
|
22
22
|
dev: "tsup --watch",
|
|
23
23
|
prepublishOnly: "npm run build",
|
|
24
|
-
|
|
24
|
+
publish: "npm publish --access public",
|
|
25
25
|
"publish:npm:registry": "npm --registry=https://registry.npmjs.org/ publish --access public"
|
|
26
26
|
},
|
|
27
27
|
engines: {
|
|
@@ -72,7 +72,7 @@ _xx() {
|
|
|
72
72
|
'create:\u9012\u5F52\u521B\u5EFA\u6587\u4EF6\u6216\u76EE\u5F55'
|
|
73
73
|
'format:\u4F7F\u7528 Prettier \u683C\u5F0F\u5316\u4EE3\u7801'
|
|
74
74
|
'help:\u663E\u793A\u6307\u5B9A\u547D\u4EE4\u7684\u5E2E\u52A9\u4FE1\u606F'
|
|
75
|
-
'install:macOS \u672C\u5730\u5DE5\u5177\u5B89\u88C5\u5668 (\u652F\u6301\u53EF\u6267\u884C\u6587\u4EF6\
|
|
75
|
+
'install:macOS/Windows \u672C\u5730\u5DE5\u5177\u5B89\u88C5\u5668 (\u652F\u6301\u53EF\u6267\u884C\u6587\u4EF6\u3001zip\u3001tar \u5305)'
|
|
76
76
|
'ip:\u672C\u5730\u6D3B\u8DC3\u7F51\u5361\u53CA\u7F51\u5173\u4FA6\u6D4B'
|
|
77
77
|
'list:\u5217\u51FA\u76EE\u5F55\u4E2D\u7684\u6240\u6709\u6587\u4EF6\u548C\u76EE\u5F55\uFF08\u542B\u9690\u85CF\u9879\uFF09'
|
|
78
78
|
'move:\u79FB\u52A8\u6216\u91CD\u547D\u540D\u6587\u4EF6\u53CA\u76EE\u5F55'
|
|
@@ -82,7 +82,7 @@ _xx() {
|
|
|
82
82
|
'remove:\u5B89\u5168\u5730\u5C06\u6307\u5B9A\u7684\u6587\u4EF6\u6216\u76EE\u5F55\u79FB\u81F3\u7CFB\u7EDF\u56DE\u6536\u7AD9\uFF08\u652F\u6301\u901A\u914D\u7B26\u53CA\u591A\u9009\uFF09'
|
|
83
83
|
'search:\u9012\u5F52\u641C\u7D22\u76EE\u5F55\u4E0B\u5305\u542B\u6307\u5B9A\u5173\u952E\u8BCD\u7684\u6587\u4EF6\u6216\u76EE\u5F55'
|
|
84
84
|
'translate:\u7EC8\u7AEF\u7FFB\u8BD1\u5DE5\u5177'
|
|
85
|
-
'uninstall:macOS \u672C\u5730\u5DE5\u5177\u5378\u8F7D\u5668\uFF08\u79FB\u9664\u5B89\u88C5\u76EE\u5F55\u548C\u7EC8\u7AEF\u547D\u4EE4\u5165\u53E3\uFF09'
|
|
85
|
+
'uninstall:macOS/Windows \u672C\u5730\u5DE5\u5177\u5378\u8F7D\u5668\uFF08\u79FB\u9664\u5B89\u88C5\u76EE\u5F55\u548C\u7EC8\u7AEF\u547D\u4EE4\u5165\u53E3\uFF09'
|
|
86
86
|
'unzip:\u89E3\u538B ZIP \u538B\u7F29\u5305'
|
|
87
87
|
'upgrade:\u81EA\u52A8\u66F4\u65B0 xx \u547D\u4EE4\u884C\u5DE5\u5177\u81F3\u6700\u65B0\u7248\u672C'
|
|
88
88
|
'zip:\u81EA\u52A8\u8FC7\u6EE4\u5E76\u6253\u5305\u4E3A ZIP'
|
|
@@ -104,6 +104,10 @@ _xx() {
|
|
|
104
104
|
_arguments \\
|
|
105
105
|
'*:Target Path:_files'
|
|
106
106
|
;;
|
|
107
|
+
install)
|
|
108
|
+
_arguments \\
|
|
109
|
+
'*:Install Package:_files'
|
|
110
|
+
;;
|
|
107
111
|
help)
|
|
108
112
|
local -a sub_cmds
|
|
109
113
|
sub_cmds=(
|
|
@@ -111,7 +115,7 @@ _xx() {
|
|
|
111
115
|
'copy:\u590D\u5236\u6587\u4EF6\u6216\u76EE\u5F55\uFF08\u652F\u6301\u9012\u5F52\u590D\u5236\uFF09'
|
|
112
116
|
'create:\u9012\u5F52\u521B\u5EFA\u6587\u4EF6\u6216\u76EE\u5F55'
|
|
113
117
|
'format:\u4F7F\u7528 Prettier \u683C\u5F0F\u5316\u4EE3\u7801'
|
|
114
|
-
'install:macOS \u672C\u5730\u5DE5\u5177\u5B89\u88C5\u5668 (\u652F\u6301\u53EF\u6267\u884C\u6587\u4EF6\
|
|
118
|
+
'install:macOS/Windows \u672C\u5730\u5DE5\u5177\u5B89\u88C5\u5668 (\u652F\u6301\u53EF\u6267\u884C\u6587\u4EF6\u3001zip\u3001tar \u5305)'
|
|
115
119
|
'ip:\u672C\u5730\u6D3B\u8DC3\u7F51\u5361\u53CA\u7F51\u5173\u4FA6\u6D4B'
|
|
116
120
|
'list:\u5217\u51FA\u76EE\u5F55\u4E2D\u7684\u6240\u6709\u6587\u4EF6\u548C\u76EE\u5F55\uFF08\u542B\u9690\u85CF\u9879\uFF09'
|
|
117
121
|
'move:\u79FB\u52A8\u6216\u91CD\u547D\u540D\u6587\u4EF6\u53CA\u76EE\u5F55'
|
|
@@ -121,7 +125,7 @@ _xx() {
|
|
|
121
125
|
'remove:\u5B89\u5168\u5730\u5C06\u6307\u5B9A\u7684\u6587\u4EF6\u6216\u76EE\u5F55\u79FB\u81F3\u7CFB\u7EDF\u56DE\u6536\u7AD9\uFF08\u652F\u6301\u901A\u914D\u7B26\u53CA\u591A\u9009\uFF09'
|
|
122
126
|
'search:\u9012\u5F52\u641C\u7D22\u76EE\u5F55\u4E0B\u5305\u542B\u6307\u5B9A\u5173\u952E\u8BCD\u7684\u6587\u4EF6\u6216\u76EE\u5F55'
|
|
123
127
|
'translate:\u7EC8\u7AEF\u7FFB\u8BD1\u5DE5\u5177'
|
|
124
|
-
'uninstall:macOS \u672C\u5730\u5DE5\u5177\u5378\u8F7D\u5668\uFF08\u79FB\u9664\u5B89\u88C5\u76EE\u5F55\u548C\u7EC8\u7AEF\u547D\u4EE4\u5165\u53E3\uFF09'
|
|
128
|
+
'uninstall:macOS/Windows \u672C\u5730\u5DE5\u5177\u5378\u8F7D\u5668\uFF08\u79FB\u9664\u5B89\u88C5\u76EE\u5F55\u548C\u7EC8\u7AEF\u547D\u4EE4\u5165\u53E3\uFF09'
|
|
125
129
|
'unzip:\u89E3\u538B ZIP \u538B\u7F29\u5305'
|
|
126
130
|
'upgrade:\u81EA\u52A8\u66F4\u65B0 xx \u547D\u4EE4\u884C\u5DE5\u5177\u81F3\u6700\u65B0\u7248\u672C'
|
|
127
131
|
'zip:\u81EA\u52A8\u8FC7\u6EE4\u5E76\u6253\u5305\u4E3A ZIP'
|
|
@@ -160,7 +164,7 @@ _xx() {
|
|
|
160
164
|
;;
|
|
161
165
|
uninstall)
|
|
162
166
|
_arguments \\
|
|
163
|
-
'*:
|
|
167
|
+
'*:Installed App:'
|
|
164
168
|
;;
|
|
165
169
|
unzip)
|
|
166
170
|
_arguments \\
|
|
@@ -253,6 +257,10 @@ _xx_completion() {
|
|
|
253
257
|
COMPREPLY=( $(compgen -W "\${sub_opts}" -- \${cur}) )
|
|
254
258
|
return 0
|
|
255
259
|
;;
|
|
260
|
+
install|uninstall)
|
|
261
|
+
COMPREPLY=( $(compgen -f -- "\${cur}") )
|
|
262
|
+
return 0
|
|
263
|
+
;;
|
|
256
264
|
upgrade)
|
|
257
265
|
local sub_opts="-r --registry"
|
|
258
266
|
COMPREPLY=( $(compgen -W "\${sub_opts}" -- \${cur}) )
|
|
@@ -770,13 +778,38 @@ import { resolve as resolve4, join as join5, basename as basename3 } from "path"
|
|
|
770
778
|
|
|
771
779
|
// utils/macos-apps.ts
|
|
772
780
|
import fs5 from "fs/promises";
|
|
773
|
-
import { basename as basename2, extname, join as join4 } from "path";
|
|
781
|
+
import { basename as basename2, delimiter, extname, join as join4 } from "path";
|
|
774
782
|
import pc5 from "picocolors";
|
|
783
|
+
|
|
784
|
+
// utils/archive.ts
|
|
785
|
+
import AdmZip from "adm-zip";
|
|
786
|
+
import * as tar from "tar";
|
|
787
|
+
import { mkdir } from "fs/promises";
|
|
788
|
+
async function compressZip(sourceDir, outputPath) {
|
|
789
|
+
const zip = new AdmZip();
|
|
790
|
+
zip.addLocalFolder(sourceDir);
|
|
791
|
+
zip.writeZip(outputPath);
|
|
792
|
+
}
|
|
793
|
+
async function uncompressZip(src, destDir) {
|
|
794
|
+
await mkdir(destDir, { recursive: true });
|
|
795
|
+
const zip = new AdmZip(src);
|
|
796
|
+
zip.extractAllTo(destDir, true);
|
|
797
|
+
}
|
|
798
|
+
async function uncompressTar(src, destDir) {
|
|
799
|
+
await mkdir(destDir, { recursive: true });
|
|
800
|
+
await tar.x({ file: src, cwd: destDir });
|
|
801
|
+
}
|
|
802
|
+
async function uncompressTgz(src, destDir) {
|
|
803
|
+
await mkdir(destDir, { recursive: true });
|
|
804
|
+
await tar.x({ file: src, gzip: true, cwd: destDir });
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
// utils/macos-apps.ts
|
|
775
808
|
var APP_DIR_NAME = ".xx-tools";
|
|
776
809
|
var PATH_MARKER_BEGIN = "# >>> xx-tools path >>>";
|
|
777
810
|
var PATH_MARKER_END = "# <<< xx-tools path <<<";
|
|
778
811
|
function getHomeDir() {
|
|
779
|
-
return process.env["HOME"] || process.cwd();
|
|
812
|
+
return process.env["HOME"] || process.env["USERPROFILE"] || process.cwd();
|
|
780
813
|
}
|
|
781
814
|
function getToolsRootDir() {
|
|
782
815
|
return join4(getHomeDir(), APP_DIR_NAME);
|
|
@@ -790,9 +823,11 @@ function getBinDir() {
|
|
|
790
823
|
function getManifestPath(appName) {
|
|
791
824
|
return join4(getAppsDir(), appName, ".xx-manifest.json");
|
|
792
825
|
}
|
|
793
|
-
function
|
|
794
|
-
if (process.platform !== "darwin") {
|
|
795
|
-
console.error(
|
|
826
|
+
function ensureSupportedDesktopOS() {
|
|
827
|
+
if (process.platform !== "darwin" && process.platform !== "win32") {
|
|
828
|
+
console.error(
|
|
829
|
+
pc5.red("\u274C \u5F53\u524D install/uninstall \u4EC5\u652F\u6301 macOS \u548C Windows\u3002")
|
|
830
|
+
);
|
|
796
831
|
return false;
|
|
797
832
|
}
|
|
798
833
|
return true;
|
|
@@ -815,6 +850,10 @@ function getPreferredProfiles() {
|
|
|
815
850
|
return Array.from(new Set(profiles));
|
|
816
851
|
}
|
|
817
852
|
async function ensureBinDirOnPath() {
|
|
853
|
+
if (process.platform === "win32") {
|
|
854
|
+
await ensureWindowsBinDirOnPath();
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
818
857
|
const pathBlock = `${PATH_MARKER_BEGIN}
|
|
819
858
|
export PATH="$HOME/${APP_DIR_NAME}/bin:$PATH"
|
|
820
859
|
${PATH_MARKER_END}`;
|
|
@@ -836,7 +875,43 @@ ${PATH_MARKER_END}`;
|
|
|
836
875
|
}
|
|
837
876
|
}
|
|
838
877
|
}
|
|
878
|
+
async function ensureWindowsBinDirOnPath() {
|
|
879
|
+
const binDir = getBinDir();
|
|
880
|
+
const currentUserPath = process.env["Path"] || process.env["PATH"] || "";
|
|
881
|
+
const alreadyInCurrentEnv = currentUserPath.split(delimiter).some((item) => item.trim().toLowerCase() === binDir.toLowerCase());
|
|
882
|
+
const script = [
|
|
883
|
+
"$binDir = [System.IO.Path]::GetFullPath($args[0])",
|
|
884
|
+
"$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')",
|
|
885
|
+
"if ([string]::IsNullOrWhiteSpace($userPath)) { $userPath = '' }",
|
|
886
|
+
"$items = $userPath -split ';' | Where-Object { $_ -and $_.Trim() -ne '' }",
|
|
887
|
+
"$exists = $items | Where-Object { $_.Trim().ToLower() -eq $binDir.ToLower() }",
|
|
888
|
+
"if (-not $exists) {",
|
|
889
|
+
' $newPath = if ($userPath) { "$binDir;$userPath" } else { $binDir }',
|
|
890
|
+
" [Environment]::SetEnvironmentVariable('Path', $newPath, 'User')",
|
|
891
|
+
" Write-Output 'UPDATED'",
|
|
892
|
+
"} else {",
|
|
893
|
+
" Write-Output 'UNCHANGED'",
|
|
894
|
+
"}"
|
|
895
|
+
].join(" ");
|
|
896
|
+
const { success, stdout } = await runCommand("powershell", [
|
|
897
|
+
"-NoProfile",
|
|
898
|
+
"-Command",
|
|
899
|
+
script,
|
|
900
|
+
binDir
|
|
901
|
+
]);
|
|
902
|
+
if (success) {
|
|
903
|
+
const output = decodeOutput(stdout).trim();
|
|
904
|
+
if (output.includes("UPDATED")) {
|
|
905
|
+
console.log(pc5.green(`\u2714 \u5DF2\u5199\u5165\u7528\u6237 PATH: ${binDir}`));
|
|
906
|
+
} else if (!alreadyInCurrentEnv) {
|
|
907
|
+
console.log(pc5.dim(`\u2796 \u7528\u6237 PATH \u4E2D\u5DF2\u5B58\u5728: ${binDir}`));
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
}
|
|
839
911
|
function getShellReloadCommand() {
|
|
912
|
+
if (process.platform === "win32") {
|
|
913
|
+
return "\u91CD\u65B0\u6253\u5F00 PowerShell \u6216 CMD";
|
|
914
|
+
}
|
|
840
915
|
const shell = process.env["SHELL"] || "";
|
|
841
916
|
if (shell.includes("zsh")) {
|
|
842
917
|
return "source ~/.zshrc";
|
|
@@ -878,10 +953,18 @@ async function findExecutablesRecursively(rootDir) {
|
|
|
878
953
|
}
|
|
879
954
|
if (!entry.isFile()) continue;
|
|
880
955
|
const stat = await fs5.stat(fullPath);
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
956
|
+
if (process.platform === "win32") {
|
|
957
|
+
if (!/\.(exe|cmd|bat|ps1)$/i.test(entry.name)) {
|
|
958
|
+
continue;
|
|
959
|
+
}
|
|
960
|
+
} else {
|
|
961
|
+
const isExecutable = stat.mode ? (stat.mode & 73) !== 0 : false;
|
|
962
|
+
if (!isExecutable) continue;
|
|
963
|
+
if (/\.(dylib|so|a|o|txt|md|json|yaml|yml|ts|js|c|h|sh)$/i.test(
|
|
964
|
+
entry.name
|
|
965
|
+
)) {
|
|
966
|
+
continue;
|
|
967
|
+
}
|
|
885
968
|
}
|
|
886
969
|
matches.push(fullPath);
|
|
887
970
|
}
|
|
@@ -893,11 +976,34 @@ async function createLinks(appName, executablePaths) {
|
|
|
893
976
|
const binDir = getBinDir();
|
|
894
977
|
const linkNames = [];
|
|
895
978
|
for (const executablePath of executablePaths) {
|
|
896
|
-
const
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
979
|
+
const executableBaseName = basename2(executablePath);
|
|
980
|
+
if (process.platform === "win32") {
|
|
981
|
+
const commandName = basename2(
|
|
982
|
+
executableBaseName,
|
|
983
|
+
extname(executableBaseName)
|
|
984
|
+
);
|
|
985
|
+
const cmdPath = join4(binDir, `${commandName}.cmd`);
|
|
986
|
+
const ps1Path = join4(binDir, `${commandName}.ps1`);
|
|
987
|
+
const quotedExecutable = executablePath.replace(/"/g, '""');
|
|
988
|
+
await fs5.rm(cmdPath, { force: true });
|
|
989
|
+
await fs5.rm(ps1Path, { force: true });
|
|
990
|
+
await fs5.writeFile(
|
|
991
|
+
cmdPath,
|
|
992
|
+
`@echo off\r
|
|
993
|
+
"${quotedExecutable}" %*\r
|
|
994
|
+
`,
|
|
995
|
+
"utf-8"
|
|
996
|
+
);
|
|
997
|
+
await fs5.writeFile(ps1Path, `& "${quotedExecutable}" @args
|
|
998
|
+
`, "utf-8");
|
|
999
|
+
linkNames.push(commandName);
|
|
1000
|
+
} else {
|
|
1001
|
+
const linkName = executableBaseName;
|
|
1002
|
+
const linkPath = join4(binDir, linkName);
|
|
1003
|
+
await fs5.rm(linkPath, { force: true });
|
|
1004
|
+
await fs5.symlink(executablePath, linkPath);
|
|
1005
|
+
linkNames.push(linkName);
|
|
1006
|
+
}
|
|
901
1007
|
}
|
|
902
1008
|
if (linkNames.length > 0) {
|
|
903
1009
|
console.log(
|
|
@@ -927,7 +1033,12 @@ async function removeInstalledApp(appName) {
|
|
|
927
1033
|
const manifest = await readManifest(appName);
|
|
928
1034
|
if (!manifest) return false;
|
|
929
1035
|
for (const linkName of manifest.links) {
|
|
930
|
-
|
|
1036
|
+
if (process.platform === "win32") {
|
|
1037
|
+
await fs5.rm(join4(getBinDir(), `${linkName}.cmd`), { force: true });
|
|
1038
|
+
await fs5.rm(join4(getBinDir(), `${linkName}.ps1`), { force: true });
|
|
1039
|
+
} else {
|
|
1040
|
+
await fs5.rm(join4(getBinDir(), linkName), { force: true });
|
|
1041
|
+
}
|
|
931
1042
|
console.log(pc5.green(`\u2714 \u5DF2\u79FB\u9664\u7EC8\u7AEF\u547D\u4EE4: ${linkName}`));
|
|
932
1043
|
}
|
|
933
1044
|
await fs5.rm(manifest.installDir, { recursive: true, force: true });
|
|
@@ -944,6 +1055,10 @@ async function listInstalledApps() {
|
|
|
944
1055
|
}
|
|
945
1056
|
async function extractArchiveToDir(archivePath, destDir) {
|
|
946
1057
|
const lower = archivePath.toLowerCase();
|
|
1058
|
+
if (lower.endsWith(".zip")) {
|
|
1059
|
+
await uncompressZip(archivePath, destDir);
|
|
1060
|
+
return true;
|
|
1061
|
+
}
|
|
947
1062
|
let args;
|
|
948
1063
|
if (lower.endsWith(".tar.gz") || lower.endsWith(".tgz")) {
|
|
949
1064
|
args = ["-xzf", archivePath, "-C", destDir];
|
|
@@ -1016,9 +1131,9 @@ async function installArchive(absPath) {
|
|
|
1016
1131
|
}
|
|
1017
1132
|
function registerInstallCommand(program2) {
|
|
1018
1133
|
program2.command("install [path]").description(
|
|
1019
|
-
"macOS \u672C\u5730\u5DE5\u5177\u5B89\u88C5\u5668\uFF08\u652F\u6301\u53EF\u6267\u884C\u6587\u4EF6\u3001.tar.gz\u3001.tgz\u3001.tar.xz\u3001.txz\u3001.tar\uFF09"
|
|
1134
|
+
"macOS/Windows \u672C\u5730\u5DE5\u5177\u5B89\u88C5\u5668\uFF08\u652F\u6301\u53EF\u6267\u884C\u6587\u4EF6\u3001.zip\u3001.tar.gz\u3001.tgz\u3001.tar.xz\u3001.txz\u3001.tar\uFF09"
|
|
1020
1135
|
).action(async (target) => {
|
|
1021
|
-
if (!
|
|
1136
|
+
if (!ensureSupportedDesktopOS()) return;
|
|
1022
1137
|
if (!target) {
|
|
1023
1138
|
console.error(pc6.red("\u274C \u8BF7\u63D0\u4F9B\u6709\u6548\u7684\u672C\u5730\u6587\u4EF6\u8DEF\u5F84\u3002"));
|
|
1024
1139
|
return;
|
|
@@ -1037,7 +1152,7 @@ function registerInstallCommand(program2) {
|
|
|
1037
1152
|
await ensureToolDirectories();
|
|
1038
1153
|
await ensureBinDirOnPath();
|
|
1039
1154
|
const lowerPath = target.toLowerCase();
|
|
1040
|
-
if (lowerPath.endsWith(".tar.gz") || lowerPath.endsWith(".tgz") || lowerPath.endsWith(".tar.xz") || lowerPath.endsWith(".txz") || lowerPath.endsWith(".tar")) {
|
|
1155
|
+
if (lowerPath.endsWith(".zip") || lowerPath.endsWith(".tar.gz") || lowerPath.endsWith(".tgz") || lowerPath.endsWith(".tar.xz") || lowerPath.endsWith(".txz") || lowerPath.endsWith(".tar")) {
|
|
1041
1156
|
await installArchive(absPath);
|
|
1042
1157
|
} else {
|
|
1043
1158
|
await installBinary(absPath);
|
|
@@ -1928,8 +2043,8 @@ function registerTanslateCommand(program2) {
|
|
|
1928
2043
|
// commands/uninstall.ts
|
|
1929
2044
|
import pc16 from "picocolors";
|
|
1930
2045
|
function registerUninstallCommand(program2) {
|
|
1931
|
-
program2.command("uninstall <package>").description("macOS \u672C\u5730\u5DE5\u5177\u5378\u8F7D\u5668\uFF08\u79FB\u9664\u5B89\u88C5\u76EE\u5F55\u548C\u7EC8\u7AEF\u547D\u4EE4\u5165\u53E3\uFF09").action(async (pkg) => {
|
|
1932
|
-
if (!
|
|
2046
|
+
program2.command("uninstall <package>").description("macOS/Windows \u672C\u5730\u5DE5\u5177\u5378\u8F7D\u5668\uFF08\u79FB\u9664\u5B89\u88C5\u76EE\u5F55\u548C\u7EC8\u7AEF\u547D\u4EE4\u5165\u53E3\uFF09").action(async (pkg) => {
|
|
2047
|
+
if (!ensureSupportedDesktopOS()) return;
|
|
1933
2048
|
if (!pkg) {
|
|
1934
2049
|
console.error(pc16.red("\u274C \u8BF7\u63D0\u4F9B\u8981\u5378\u8F7D\u7684\u5E94\u7528\u540D\u3002"));
|
|
1935
2050
|
return;
|
|
@@ -1962,31 +2077,6 @@ function registerUninstallCommand(program2) {
|
|
|
1962
2077
|
import fs13 from "fs/promises";
|
|
1963
2078
|
import pc17 from "picocolors";
|
|
1964
2079
|
import { join as join8, basename as basename6, extname as extname2, resolve as resolve11 } from "path";
|
|
1965
|
-
|
|
1966
|
-
// utils/archive.ts
|
|
1967
|
-
import AdmZip from "adm-zip";
|
|
1968
|
-
import * as tar from "tar";
|
|
1969
|
-
import { mkdir } from "fs/promises";
|
|
1970
|
-
async function compressZip(sourceDir, outputPath) {
|
|
1971
|
-
const zip = new AdmZip();
|
|
1972
|
-
zip.addLocalFolder(sourceDir);
|
|
1973
|
-
zip.writeZip(outputPath);
|
|
1974
|
-
}
|
|
1975
|
-
async function uncompressZip(src, destDir) {
|
|
1976
|
-
await mkdir(destDir, { recursive: true });
|
|
1977
|
-
const zip = new AdmZip(src);
|
|
1978
|
-
zip.extractAllTo(destDir, true);
|
|
1979
|
-
}
|
|
1980
|
-
async function uncompressTar(src, destDir) {
|
|
1981
|
-
await mkdir(destDir, { recursive: true });
|
|
1982
|
-
await tar.x({ file: src, cwd: destDir });
|
|
1983
|
-
}
|
|
1984
|
-
async function uncompressTgz(src, destDir) {
|
|
1985
|
-
await mkdir(destDir, { recursive: true });
|
|
1986
|
-
await tar.x({ file: src, gzip: true, cwd: destDir });
|
|
1987
|
-
}
|
|
1988
|
-
|
|
1989
|
-
// commands/unzip.ts
|
|
1990
2080
|
async function uncompressRar(src, dest) {
|
|
1991
2081
|
const hasUnrar = isCommandAvailable("unrar");
|
|
1992
2082
|
if (hasUnrar) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xx-in/tools",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "A command-line tool to run in any system",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"build": "tsup",
|
|
15
15
|
"dev": "tsup --watch",
|
|
16
16
|
"prepublishOnly": "npm run build",
|
|
17
|
-
"publish
|
|
17
|
+
"publish": "npm publish --access public",
|
|
18
18
|
"publish:npm:registry": "npm --registry=https://registry.npmjs.org/ publish --access public"
|
|
19
19
|
},
|
|
20
20
|
"engines": {
|