zixulu 1.80.5 → 1.80.7
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/dist/index.js
CHANGED
|
@@ -6,8 +6,8 @@ import { capitalize, emailReg, getEnumEntries, getEnumKeys, getEnumValues, isNon
|
|
|
6
6
|
import { compress, execAsync, isPathLike, setDefaultOptions, spawnAsync, unzip, zip } from "soda-nodejs";
|
|
7
7
|
import inquirer_0 from "inquirer";
|
|
8
8
|
import { chdir, cwd as external_node_process_cwd, exit } from "node:process";
|
|
9
|
-
import { copyFile, mkdir, readFile, readdir, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
|
|
10
|
-
import { basename, join, parse as external_node_path_parse, resolve as external_node_path_resolve } from "node:path";
|
|
9
|
+
import { access, copyFile, mkdir, readFile, readdir, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
|
|
10
|
+
import { basename, delimiter, join, parse as external_node_path_parse, resolve as external_node_path_resolve } from "node:path";
|
|
11
11
|
import node_fetch, { Headers as external_node_fetch_Headers } from "node-fetch";
|
|
12
12
|
import semver from "semver";
|
|
13
13
|
import { checkPort } from "get-port-please";
|
|
@@ -4927,8 +4927,53 @@ const EditorExtensionCommandMap = {
|
|
|
4927
4927
|
Cursor: "cursor",
|
|
4928
4928
|
Antigravity: "antigravity"
|
|
4929
4929
|
};
|
|
4930
|
+
const editorExtensionCommandCache = new Map();
|
|
4931
|
+
async function pathExists({ path }) {
|
|
4932
|
+
try {
|
|
4933
|
+
await access(path);
|
|
4934
|
+
return true;
|
|
4935
|
+
} catch {
|
|
4936
|
+
return false;
|
|
4937
|
+
}
|
|
4938
|
+
}
|
|
4939
|
+
function quoteShellCommand({ command }) {
|
|
4940
|
+
if (!/[\s()]/.test(command)) return command;
|
|
4941
|
+
return `"${command.replace(/"/g, '\\"')}"`;
|
|
4942
|
+
}
|
|
4943
|
+
function getEditorWindowsCliCandidates({ editor }) {
|
|
4944
|
+
const command = EditorExtensionCommandMap[editor];
|
|
4945
|
+
const candidates = new Set();
|
|
4946
|
+
const localAppData = process.env.LOCALAPPDATA ?? join(homedir(), "AppData", "Local");
|
|
4947
|
+
const programFiles = process.env.ProgramFiles ?? "C:/Program Files";
|
|
4948
|
+
const programFilesX86 = process.env["ProgramFiles(x86)"] ?? "C:/Program Files (x86)";
|
|
4949
|
+
if ("Code" === editor) {
|
|
4950
|
+
candidates.add(join(localAppData, "Programs", "Microsoft VS Code", "bin", "code.cmd"));
|
|
4951
|
+
candidates.add(join(programFiles, "Microsoft VS Code", "bin", "code.cmd"));
|
|
4952
|
+
candidates.add(join(programFilesX86, "Microsoft VS Code", "bin", "code.cmd"));
|
|
4953
|
+
}
|
|
4954
|
+
if ("Cursor" === editor) {
|
|
4955
|
+
candidates.add(join(localAppData, "Programs", "Cursor", "resources", "app", "bin", "cursor.cmd"));
|
|
4956
|
+
candidates.add(join(localAppData, "Programs", "cursor", "resources", "app", "bin", "cursor.cmd"));
|
|
4957
|
+
candidates.add(join(programFiles, "Cursor", "resources", "app", "bin", "cursor.cmd"));
|
|
4958
|
+
candidates.add(join(programFilesX86, "Cursor", "resources", "app", "bin", "cursor.cmd"));
|
|
4959
|
+
}
|
|
4960
|
+
if ("Antigravity" === editor) {
|
|
4961
|
+
candidates.add(join(localAppData, "Programs", "Antigravity", "bin", "antigravity.cmd"));
|
|
4962
|
+
candidates.add(join(localAppData, "Programs", "Antigravity", "resources", "app", "bin", "antigravity.cmd"));
|
|
4963
|
+
candidates.add(join(programFiles, "Antigravity", "bin", "antigravity.cmd"));
|
|
4964
|
+
candidates.add(join(programFiles, "Antigravity", "resources", "app", "bin", "antigravity.cmd"));
|
|
4965
|
+
candidates.add(join(programFilesX86, "Antigravity", "bin", "antigravity.cmd"));
|
|
4966
|
+
candidates.add(join(programFilesX86, "Antigravity", "resources", "app", "bin", "antigravity.cmd"));
|
|
4967
|
+
}
|
|
4968
|
+
const pathDirs = process.env.PATH?.split(delimiter).filter(Boolean) ?? [];
|
|
4969
|
+
for (const dir of pathDirs){
|
|
4970
|
+
candidates.add(join(dir, `${command}.cmd`));
|
|
4971
|
+
candidates.add(join(dir, command));
|
|
4972
|
+
}
|
|
4973
|
+
return Array.from(candidates);
|
|
4974
|
+
}
|
|
4930
4975
|
async function canGetEditorExtensions({ editor }) {
|
|
4931
|
-
const command = getEditorExtensionCommand({
|
|
4976
|
+
const command = await getEditorExtensionCommand({
|
|
4932
4977
|
editor
|
|
4933
4978
|
});
|
|
4934
4979
|
try {
|
|
@@ -4938,13 +4983,32 @@ async function canGetEditorExtensions({ editor }) {
|
|
|
4938
4983
|
return false;
|
|
4939
4984
|
}
|
|
4940
4985
|
}
|
|
4941
|
-
function getEditorExtensionCommand({ editor }) {
|
|
4942
|
-
|
|
4986
|
+
async function getEditorExtensionCommand({ editor }) {
|
|
4987
|
+
const cachedCommand = editorExtensionCommandCache.get(editor);
|
|
4988
|
+
if (cachedCommand) return cachedCommand;
|
|
4989
|
+
const fallbackCommand = EditorExtensionCommandMap[editor];
|
|
4990
|
+
if ("win32" !== process.platform) {
|
|
4991
|
+
editorExtensionCommandCache.set(editor, fallbackCommand);
|
|
4992
|
+
return fallbackCommand;
|
|
4993
|
+
}
|
|
4994
|
+
for (const candidate of getEditorWindowsCliCandidates({
|
|
4995
|
+
editor
|
|
4996
|
+
})){
|
|
4997
|
+
if (!await pathExists({
|
|
4998
|
+
path: candidate
|
|
4999
|
+
})) continue;
|
|
5000
|
+
const command = quoteShellCommand({
|
|
5001
|
+
command: candidate
|
|
5002
|
+
});
|
|
5003
|
+
editorExtensionCommandCache.set(editor, command);
|
|
5004
|
+
return command;
|
|
5005
|
+
}
|
|
5006
|
+
throw new Error(`${editor} 命令行工具不可用,请确认已安装并加入 PATH`);
|
|
4943
5007
|
}
|
|
4944
5008
|
async function getEditorExtensions({ source }) {
|
|
4945
5009
|
let data = [];
|
|
4946
5010
|
if ("Online" !== source) {
|
|
4947
|
-
const command = getEditorExtensionCommand({
|
|
5011
|
+
const command = await getEditorExtensionCommand({
|
|
4948
5012
|
editor: source
|
|
4949
5013
|
});
|
|
4950
5014
|
const output = await execAsync(`${command} --list-extensions`);
|
|
@@ -4971,7 +5035,7 @@ async function syncCursorExtToCode() {
|
|
|
4971
5035
|
const vscodeExts = await getEditorExtensions({
|
|
4972
5036
|
source: "Code"
|
|
4973
5037
|
});
|
|
4974
|
-
const codeCommand = getEditorExtensionCommand({
|
|
5038
|
+
const codeCommand = await getEditorExtensionCommand({
|
|
4975
5039
|
editor: "Code"
|
|
4976
5040
|
});
|
|
4977
5041
|
const installExts = cursorExts.difference(vscodeExts);
|
|
@@ -5097,7 +5161,7 @@ async function syncEditorFile({ type, source: { value: sourceValue }, target: {
|
|
|
5097
5161
|
consola.success(`${targetValue} 同步完成`);
|
|
5098
5162
|
}
|
|
5099
5163
|
async function syncEditorExtensions({ editor, sourceExtensions, targetExtensions }) {
|
|
5100
|
-
const command = getEditorExtensionCommand({
|
|
5164
|
+
const command = await getEditorExtensionCommand({
|
|
5101
5165
|
editor
|
|
5102
5166
|
});
|
|
5103
5167
|
const installExtensions = sourceExtensions.difference(targetExtensions);
|