zixulu 1.73.8 → 1.75.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.
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ import { Readable } from "stream";
24
24
  import { JSDOM } from "jsdom";
25
25
  import { exec } from "child_process";
26
26
  import md5 from "md5";
27
+ import { applyEdits, modify } from "jsonc-parser";
27
28
  async function addGitCommit(messageOrParams) {
28
29
  const { message, cwd } = "string" == typeof messageOrParams ? {
29
30
  message: messageOrParams
@@ -4355,6 +4356,21 @@ function hasCursor() {
4355
4356
  const path = join(userDir, "AppData/Roaming/Cursor");
4356
4357
  return existsSync(path);
4357
4358
  }
4359
+ function modifyJsonc(text, path, value, options) {
4360
+ options = {
4361
+ ...options
4362
+ };
4363
+ options.formattingOptions = {
4364
+ ...options.formattingOptions
4365
+ };
4366
+ options.formattingOptions.tabSize ??= 4;
4367
+ options.formattingOptions.insertSpaces ??= true;
4368
+ options.formattingOptions.insertFinalNewline ??= true;
4369
+ options.formattingOptions.keepLines ??= true;
4370
+ options.formattingOptions.eol ??= "\n";
4371
+ const edits = modify(text, path, value, options);
4372
+ return applyEdits(text, edits);
4373
+ }
4358
4374
  const syncEditorSetting_userDir = homedir();
4359
4375
  const fileSourceMap = {
4360
4376
  settings: {
@@ -4377,19 +4393,32 @@ async function getFile(source) {
4377
4393
  }
4378
4394
  return await readFile(source, "utf-8");
4379
4395
  }
4380
- async function syncEditorFile({ source: { type: sourceType, value: sourceValue }, target: { type: targetType, value: targetValue } }) {
4396
+ async function syncEditorFile({ type, source: { type: sourceType, value: sourceValue }, target: { type: targetType, value: targetValue } }) {
4381
4397
  const { dir, base } = parse(targetValue);
4382
4398
  await mkdir(dir, {
4383
4399
  recursive: true
4384
4400
  });
4385
4401
  const setting = await readZixuluSetting();
4386
4402
  let code = await getFile(sourceValue);
4387
- if ("Code" === targetType) code = code.replace(/\n^ *"extensions\.gallery\.serviceUrl":.+,?$/m, "");
4388
- if ("Antigravity" === targetType) code = code.replace(/\n^ *"extensions\.gallery\.serviceUrl":.+,?$/m, "").replace(/}[ \n]*$/, ` "antigravity.marketplaceExtensionGalleryServiceURL": "https://marketplace.visualstudio.com/_apis/public/gallery",
4389
- "antigravity.marketplaceGalleryItemURL": "https://marketplace.visualstudio.com/items",
4390
- "json.schemaDownload.enable": true,
4391
- }
4392
- `);
4403
+ if ("settings" === type) {
4404
+ code = modifyJsonc(code, [
4405
+ "extensions.gallery.serviceUrl"
4406
+ ], void 0);
4407
+ code = modifyJsonc(code, [
4408
+ "antigravity.marketplaceExtensionGalleryServiceURL"
4409
+ ], void 0);
4410
+ code = modifyJsonc(code, [
4411
+ "antigravity.marketplaceGalleryItemURL"
4412
+ ], void 0);
4413
+ if ("Antigravity" === targetType) {
4414
+ code = modifyJsonc(code, [
4415
+ "antigravity.marketplaceExtensionGalleryServiceURL"
4416
+ ], "https://marketplace.visualstudio.com/_apis/public/gallery");
4417
+ code = modifyJsonc(code, [
4418
+ "antigravity.marketplaceGalleryItemURL"
4419
+ ], "https://marketplace.visualstudio.com/items");
4420
+ }
4421
+ }
4393
4422
  if (existsSync(targetValue)) {
4394
4423
  const text = await readFile(targetValue, "utf-8");
4395
4424
  if (text === code) return void consola_0.success(`${targetValue} 已是最新`);
@@ -4474,6 +4503,7 @@ async function syncEditorSetting() {
4474
4503
  if (!setting.syncEditor.onlinePath) setting.syncEditor.targets = targets.filter((v)=>"Online" !== v);
4475
4504
  const onlinePath = setting.syncEditor.onlinePath;
4476
4505
  const configs = types.filter((item)=>"extensions" !== item).map((fileType)=>targets.map((target)=>({
4506
+ type: fileType,
4477
4507
  source: {
4478
4508
  type: source,
4479
4509
  value: fileSourceMap[fileType][source]
@@ -5028,6 +5058,41 @@ async function winget() {
5028
5058
  if (global.__ZIXULU_PROXY__) args.push("--proxy", "http://127.0.0.1:7890");
5029
5059
  spawnAsync("winget", args);
5030
5060
  }
5061
+ async function addOpenWith(path, { file, folder, background }) {
5062
+ if (!file && !folder && !background) throw new Error("至少选择一个");
5063
+ path = external_path_resolve(path);
5064
+ try {
5065
+ const status = await stat(path);
5066
+ if (!status.isFile()) throw new Error("路径不是文件");
5067
+ } catch (error) {}
5068
+ const { name } = parse(path);
5069
+ const escapedPath = path.replace(/[\\\/]/g, "\\\\");
5070
+ let reg = `\ufeffWindows Registry Editor Version 5.00
5071
+ `;
5072
+ if (file) reg += `
5073
+ [HKEY_CLASSES_ROOT\\*\\shell\\${name}]
5074
+ @="使用 ${name} 打开"
5075
+ "Icon"="\\"${escapedPath}\\""
5076
+
5077
+ [HKEY_CLASSES_ROOT\\*\\shell\\${name}\\command]
5078
+ @="\\"${escapedPath}\\" \\"%1\\""`;
5079
+ if (folder) reg += `
5080
+ [HKEY_CLASSES_ROOT\\Directory\\shell\\${name}]
5081
+ @="使用 ${name} 打开"
5082
+ "Icon"="\\"${escapedPath}\\""
5083
+
5084
+ [HKEY_CLASSES_ROOT\\Directory\\shell\\${name}\\command]
5085
+ @="\\"${escapedPath}\\" \\"%V\\""`;
5086
+ if (background) reg += `
5087
+ [HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\${name}]
5088
+ @="使用 ${name} 打开"
5089
+ "Icon"="\\"${escapedPath}\\""
5090
+
5091
+ [HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\${name}\\command]
5092
+ @="\\"${escapedPath}\\" \\"%V\\""
5093
+ `;
5094
+ await writeFile(`add_open_with_${name}.reg`, reg, "utf-16le");
5095
+ }
5031
5096
  const gdm_script = `// @ts-check
5032
5097
 
5033
5098
  import { spawnSync } from "child_process"
@@ -5129,6 +5194,18 @@ async function gdm() {
5129
5194
  await writeFile(".gdm/gdm.mjs", gdm_script);
5130
5195
  await verdaccio();
5131
5196
  }
5197
+ async function removeOpenWith(name, { file, folder, background }) {
5198
+ if (!file && !folder && !background) throw new Error("至少选择一个");
5199
+ let reg = `\ufeffWindows Registry Editor Version 5.00
5200
+ `;
5201
+ if (file) reg += `
5202
+ [-HKEY_CLASSES_ROOT\\*\\shell\\${name}]`;
5203
+ if (folder) reg += `
5204
+ [-HKEY_CLASSES_ROOT\\Directory\\shell\\${name}]`;
5205
+ if (background) reg += `
5206
+ [-HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\${name}]`;
5207
+ await writeFile(`remove_open_with_${name}.reg`, reg, "utf-16le");
5208
+ }
5132
5209
  setDefaultOptions({
5133
5210
  shell: true,
5134
5211
  stdio: "inherit"
@@ -5316,6 +5393,8 @@ program.command("replace-commit-message").alias("rcm").description("替换所有
5316
5393
  });
5317
5394
  });
5318
5395
  program.command("gdm").description("同步 geshu-docker-management").action(gdm);
5396
+ program.command("add-open-with").alias("aow").description("添加打开文件的脚本").argument("path", "程序路径").option("--no-file", "是否不添加文件关联").option("--no-folder", "是否不添加文件夹关联").option("--no-background", "是否不添加文件夹空白处关联").action(addOpenWith);
5397
+ program.command("remove-open-with").alias("row").description("删除打开文件的脚本").argument("name", "脚本名称").option("--no-file", "是否不删除文件关联").option("--no-folder", "是否不删除文件夹关联").option("--no-background", "是否不删除文件夹空白处关联").action(removeOpenWith);
5319
5398
  program.parse();
5320
5399
 
5321
5400
  //# sourceMappingURL=index.js.map