zixulu 1.74.0 → 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 +37 -7
- package/dist/index.js.map +1 -1
- package/dist/src/utils/modifyJsonc.d.ts +2 -0
- package/dist/src/utils/syncEditorSetting.d.ts +2 -1
- package/dist/test.d.ts +1 -0
- package/package.json +2 -1
- package/src/utils/modifyJsonc.ts +15 -0
- package/src/utils/syncEditorSetting.ts +12 -10
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 ("
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
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]
|