@lumy-pack/syncpoint 0.0.11 → 0.0.12
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/cli.mjs +57 -25
- package/dist/index.cjs +44 -15
- package/dist/index.mjs +44 -15
- package/dist/version.d.ts +1 -1
- package/package.json +3 -1
package/dist/cli.mjs
CHANGED
|
@@ -148,6 +148,7 @@ var ProgressBar = ({
|
|
|
148
148
|
// src/core/backup.ts
|
|
149
149
|
import { readdir } from "fs/promises";
|
|
150
150
|
import { basename, join as join5 } from "path";
|
|
151
|
+
import { filter } from "@winglet/common-utils";
|
|
151
152
|
import fg from "fast-glob";
|
|
152
153
|
|
|
153
154
|
// src/constants.ts
|
|
@@ -451,6 +452,10 @@ function isValidPattern(pattern) {
|
|
|
451
452
|
// src/core/metadata.ts
|
|
452
453
|
import { createHash } from "crypto";
|
|
453
454
|
import { lstat, readFile, readlink } from "fs/promises";
|
|
455
|
+
import { isString } from "@winglet/common-utils";
|
|
456
|
+
|
|
457
|
+
// src/schemas/metadata.schema.ts
|
|
458
|
+
import { map } from "@winglet/common-utils";
|
|
454
459
|
|
|
455
460
|
// assets/schemas/metadata.schema.json
|
|
456
461
|
var metadata_schema_default = {
|
|
@@ -595,14 +600,15 @@ var validate2 = ajv.compile(metadata_schema_default);
|
|
|
595
600
|
function validateMetadata(data) {
|
|
596
601
|
const valid = validate2(data);
|
|
597
602
|
if (valid) return { valid: true };
|
|
598
|
-
const errors = validate2.errors
|
|
603
|
+
const errors = validate2.errors ? map(
|
|
604
|
+
validate2.errors,
|
|
599
605
|
(e) => `${e.instancePath || "/"} ${e.message ?? "unknown error"}`
|
|
600
|
-
);
|
|
606
|
+
) : void 0;
|
|
601
607
|
return { valid: false, errors };
|
|
602
608
|
}
|
|
603
609
|
|
|
604
610
|
// src/version.ts
|
|
605
|
-
var VERSION = "0.0.
|
|
611
|
+
var VERSION = "0.0.12";
|
|
606
612
|
|
|
607
613
|
// src/core/metadata.ts
|
|
608
614
|
var METADATA_VERSION = "1.0.0";
|
|
@@ -626,7 +632,7 @@ function createMetadata(files, config) {
|
|
|
626
632
|
};
|
|
627
633
|
}
|
|
628
634
|
function parseMetadata(data) {
|
|
629
|
-
const str =
|
|
635
|
+
const str = isString(data) ? data : data.toString("utf-8");
|
|
630
636
|
const parsed = JSON.parse(str);
|
|
631
637
|
const result = validateMetadata(parsed);
|
|
632
638
|
if (!result.valid) {
|
|
@@ -780,7 +786,8 @@ async function scanTargets(config) {
|
|
|
780
786
|
"**/Library/**",
|
|
781
787
|
"**/.cache/**",
|
|
782
788
|
"**/node_modules/**",
|
|
783
|
-
...
|
|
789
|
+
...filter(
|
|
790
|
+
config.backup.exclude,
|
|
784
791
|
(p) => detectPatternType(p) === "glob"
|
|
785
792
|
)
|
|
786
793
|
]
|
|
@@ -951,8 +958,12 @@ async function createBackup(config, options = {}) {
|
|
|
951
958
|
// src/core/config.ts
|
|
952
959
|
import { readFile as readFile3, writeFile as writeFile2 } from "fs/promises";
|
|
953
960
|
import { join as join7 } from "path";
|
|
961
|
+
import { isArray, map as map3 } from "@winglet/common-utils";
|
|
954
962
|
import YAML from "yaml";
|
|
955
963
|
|
|
964
|
+
// src/schemas/config.schema.ts
|
|
965
|
+
import { map as map2 } from "@winglet/common-utils";
|
|
966
|
+
|
|
956
967
|
// assets/schemas/config.schema.json
|
|
957
968
|
var config_schema_default = {
|
|
958
969
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
@@ -1022,9 +1033,10 @@ var validate3 = ajv.compile(config_schema_default);
|
|
|
1022
1033
|
function validateConfig(data) {
|
|
1023
1034
|
const valid = validate3(data);
|
|
1024
1035
|
if (valid) return { valid: true };
|
|
1025
|
-
const errors = validate3.errors
|
|
1036
|
+
const errors = validate3.errors ? map2(
|
|
1037
|
+
validate3.errors,
|
|
1026
1038
|
(e) => `${e.instancePath || "/"} ${e.message ?? "unknown error"}`
|
|
1027
|
-
);
|
|
1039
|
+
) : void 0;
|
|
1028
1040
|
return { valid: false, errors };
|
|
1029
1041
|
}
|
|
1030
1042
|
|
|
@@ -1032,7 +1044,7 @@ function validateConfig(data) {
|
|
|
1032
1044
|
init_assets();
|
|
1033
1045
|
function stripDangerousKeys(obj) {
|
|
1034
1046
|
if (obj === null || typeof obj !== "object") return obj;
|
|
1035
|
-
if (
|
|
1047
|
+
if (isArray(obj)) return map3(obj, stripDangerousKeys);
|
|
1036
1048
|
const cleaned = {};
|
|
1037
1049
|
for (const [key, value] of Object.entries(obj)) {
|
|
1038
1050
|
if (["__proto__", "constructor", "prototype"].includes(key)) continue;
|
|
@@ -1574,6 +1586,9 @@ import Spinner from "ink-spinner";
|
|
|
1574
1586
|
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
1575
1587
|
init_wizard_template();
|
|
1576
1588
|
|
|
1589
|
+
// src/schemas/template.schema.ts
|
|
1590
|
+
import { map as map4 } from "@winglet/common-utils";
|
|
1591
|
+
|
|
1577
1592
|
// assets/schemas/template.schema.json
|
|
1578
1593
|
var template_schema_default = {
|
|
1579
1594
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
@@ -1642,9 +1657,10 @@ var validate4 = ajv.compile(template_schema_default);
|
|
|
1642
1657
|
function validateTemplate(data) {
|
|
1643
1658
|
const valid = validate4(data);
|
|
1644
1659
|
if (valid) return { valid: true };
|
|
1645
|
-
const errors = validate4.errors
|
|
1660
|
+
const errors = validate4.errors ? map4(
|
|
1661
|
+
validate4.errors,
|
|
1646
1662
|
(e) => `${e.instancePath || "/"} ${e.message ?? "unknown error"}`
|
|
1647
|
-
);
|
|
1663
|
+
) : void 0;
|
|
1648
1664
|
return { valid: false, errors };
|
|
1649
1665
|
}
|
|
1650
1666
|
|
|
@@ -1754,11 +1770,12 @@ Start by asking the user about their backup priorities for the home directory st
|
|
|
1754
1770
|
}
|
|
1755
1771
|
|
|
1756
1772
|
// src/utils/error-formatter.ts
|
|
1773
|
+
import { map as map5 } from "@winglet/common-utils";
|
|
1757
1774
|
function formatValidationErrors(errors) {
|
|
1758
1775
|
if (errors.length === 0) {
|
|
1759
1776
|
return "No validation errors.";
|
|
1760
1777
|
}
|
|
1761
|
-
const formattedErrors = errors
|
|
1778
|
+
const formattedErrors = map5(errors, (error, index) => {
|
|
1762
1779
|
return `${index + 1}. ${error}`;
|
|
1763
1780
|
});
|
|
1764
1781
|
return `Validation failed with ${errors.length} error(s):
|
|
@@ -2665,6 +2682,7 @@ var Table = ({
|
|
|
2665
2682
|
import { exec } from "child_process";
|
|
2666
2683
|
import { readFile as readFile4, readdir as readdir2 } from "fs/promises";
|
|
2667
2684
|
import { join as join11 } from "path";
|
|
2685
|
+
import { filter as filter2, isTruthy } from "@winglet/common-utils";
|
|
2668
2686
|
import YAML3 from "yaml";
|
|
2669
2687
|
var REMOTE_SCRIPT_PATTERNS = [
|
|
2670
2688
|
/curl\s.*\|\s*(ba)?sh/,
|
|
@@ -2773,7 +2791,7 @@ async function executeStep(step) {
|
|
|
2773
2791
|
}
|
|
2774
2792
|
try {
|
|
2775
2793
|
const { stdout, stderr } = await execAsync(step.command);
|
|
2776
|
-
const output = [stdout, stderr]
|
|
2794
|
+
const output = filter2([stdout, stderr], isTruthy).join("\n").trim();
|
|
2777
2795
|
return {
|
|
2778
2796
|
name: step.name,
|
|
2779
2797
|
status: "success",
|
|
@@ -2784,7 +2802,7 @@ async function executeStep(step) {
|
|
|
2784
2802
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
2785
2803
|
const stdout = err?.stdout ?? "";
|
|
2786
2804
|
const stderr = err?.stderr ?? "";
|
|
2787
|
-
const errorOutput = [stdout, stderr, error.message]
|
|
2805
|
+
const errorOutput = filter2([stdout, stderr, error.message], isTruthy).join("\n").trim();
|
|
2788
2806
|
return {
|
|
2789
2807
|
name: step.name,
|
|
2790
2808
|
status: "failed",
|
|
@@ -2824,6 +2842,7 @@ async function* runProvision(templatePath, options = {}) {
|
|
|
2824
2842
|
// src/core/restore.ts
|
|
2825
2843
|
import { copyFile, lstat as lstat4, readdir as readdir3, stat as stat3 } from "fs/promises";
|
|
2826
2844
|
import { dirname as dirname2, join as join12 } from "path";
|
|
2845
|
+
import { forEach } from "@winglet/common-utils";
|
|
2827
2846
|
async function getBackupList(config) {
|
|
2828
2847
|
const backupDir = config?.backup.destination ? resolveTargetPath(config.backup.destination) : getSubDir(BACKUPS_DIR);
|
|
2829
2848
|
const exists = await fileExists(backupDir);
|
|
@@ -2928,15 +2947,26 @@ async function restoreBackup(archivePath, options = {}) {
|
|
|
2928
2947
|
const plan = await getRestorePlan(archivePath);
|
|
2929
2948
|
const restoredFiles = [];
|
|
2930
2949
|
const skippedFiles = [];
|
|
2931
|
-
const overwritePaths =
|
|
2950
|
+
const overwritePaths = [];
|
|
2951
|
+
forEach(plan.actions, (a) => {
|
|
2952
|
+
if (a.action === "overwrite") overwritePaths.push(a.path);
|
|
2953
|
+
});
|
|
2932
2954
|
let safetyBackupPath;
|
|
2933
2955
|
if (overwritePaths.length > 0 && !options.dryRun) {
|
|
2934
2956
|
safetyBackupPath = await createSafetyBackup(overwritePaths);
|
|
2935
2957
|
}
|
|
2936
2958
|
if (options.dryRun) {
|
|
2959
|
+
const restoredFiles2 = [];
|
|
2960
|
+
forEach(plan.actions, (a) => {
|
|
2961
|
+
if (a.action !== "skip") restoredFiles2.push(a.path);
|
|
2962
|
+
});
|
|
2963
|
+
const skippedFiles2 = [];
|
|
2964
|
+
forEach(plan.actions, (a) => {
|
|
2965
|
+
if (a.action === "skip") skippedFiles2.push(a.path);
|
|
2966
|
+
});
|
|
2937
2967
|
return {
|
|
2938
|
-
restoredFiles:
|
|
2939
|
-
skippedFiles:
|
|
2968
|
+
restoredFiles: restoredFiles2,
|
|
2969
|
+
skippedFiles: skippedFiles2,
|
|
2940
2970
|
safetyBackupPath
|
|
2941
2971
|
};
|
|
2942
2972
|
}
|
|
@@ -3443,6 +3473,7 @@ import { useEffect as useEffect6, useState as useState7 } from "react";
|
|
|
3443
3473
|
|
|
3444
3474
|
// src/core/migrate.ts
|
|
3445
3475
|
import { copyFile as copyFile2, readFile as readFile5, writeFile as writeFile4 } from "fs/promises";
|
|
3476
|
+
import { filter as filter3, map as map6 } from "@winglet/common-utils";
|
|
3446
3477
|
import YAML4 from "yaml";
|
|
3447
3478
|
init_assets();
|
|
3448
3479
|
function extractSchemaPaths(schema, prefix = []) {
|
|
@@ -3492,22 +3523,23 @@ function diffConfigFields(userData) {
|
|
|
3492
3523
|
const templateData = YAML4.parse(readAsset("config.default.yml"));
|
|
3493
3524
|
const templatePaths = extractDataPaths(templateData);
|
|
3494
3525
|
const userPaths = extractDataPaths(userData);
|
|
3495
|
-
const schemaKeys = new Set(schemaPaths
|
|
3496
|
-
const userKeys = new Set(userPaths
|
|
3526
|
+
const schemaKeys = new Set(map6(schemaPaths, pathKey));
|
|
3527
|
+
const userKeys = new Set(map6(userPaths, pathKey));
|
|
3497
3528
|
const isEditorDirective = (p) => p.length === 1 && p[0] === "yaml-language-server";
|
|
3498
3529
|
return {
|
|
3499
3530
|
// Fields present in template with defaults AND valid in schema, but missing from user
|
|
3500
|
-
added: templatePaths
|
|
3531
|
+
added: filter3(templatePaths, (p) => {
|
|
3501
3532
|
if (isEditorDirective(p)) return false;
|
|
3502
3533
|
const key = pathKey(p);
|
|
3503
3534
|
return schemaKeys.has(key) && !userKeys.has(key);
|
|
3504
3535
|
}),
|
|
3505
3536
|
// Fields in user but not in schema (truly deprecated)
|
|
3506
|
-
removed:
|
|
3537
|
+
removed: filter3(
|
|
3538
|
+
userPaths,
|
|
3507
3539
|
(p) => !isEditorDirective(p) && !schemaKeys.has(pathKey(p))
|
|
3508
3540
|
),
|
|
3509
3541
|
// Fields in user AND in schema (preserve user values)
|
|
3510
|
-
existing: userPaths
|
|
3542
|
+
existing: filter3(userPaths, (p) => schemaKeys.has(pathKey(p)))
|
|
3511
3543
|
};
|
|
3512
3544
|
}
|
|
3513
3545
|
function buildMigratedDocument(templateText, userData, diff) {
|
|
@@ -3554,15 +3586,15 @@ Run "syncpoint init" first.`
|
|
|
3554
3586
|
return {
|
|
3555
3587
|
added: [],
|
|
3556
3588
|
deprecated: [],
|
|
3557
|
-
preserved: diff.existing
|
|
3589
|
+
preserved: map6(diff.existing, pathKey),
|
|
3558
3590
|
backupPath: "",
|
|
3559
3591
|
migrated: false
|
|
3560
3592
|
};
|
|
3561
3593
|
}
|
|
3562
3594
|
const result = {
|
|
3563
|
-
added: diff.added
|
|
3564
|
-
deprecated: diff.removed
|
|
3565
|
-
preserved: diff.existing
|
|
3595
|
+
added: map6(diff.added, pathKey),
|
|
3596
|
+
deprecated: map6(diff.removed, pathKey),
|
|
3597
|
+
preserved: map6(diff.existing, pathKey),
|
|
3566
3598
|
backupPath: "",
|
|
3567
3599
|
migrated: false
|
|
3568
3600
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -51,6 +51,7 @@ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
|
51
51
|
// src/core/config.ts
|
|
52
52
|
var import_promises2 = require("fs/promises");
|
|
53
53
|
var import_node_path4 = require("path");
|
|
54
|
+
var import_common_utils2 = require("@winglet/common-utils");
|
|
54
55
|
var import_yaml = __toESM(require("yaml"), 1);
|
|
55
56
|
|
|
56
57
|
// src/constants.ts
|
|
@@ -126,6 +127,9 @@ function getSubDir(sub) {
|
|
|
126
127
|
return (0, import_node_path2.join)(getAppDir(), sub);
|
|
127
128
|
}
|
|
128
129
|
|
|
130
|
+
// src/schemas/config.schema.ts
|
|
131
|
+
var import_common_utils = require("@winglet/common-utils");
|
|
132
|
+
|
|
129
133
|
// assets/schemas/config.schema.json
|
|
130
134
|
var config_schema_default = {
|
|
131
135
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
@@ -299,9 +303,10 @@ var validate2 = ajv.compile(config_schema_default);
|
|
|
299
303
|
function validateConfig(data) {
|
|
300
304
|
const valid = validate2(data);
|
|
301
305
|
if (valid) return { valid: true };
|
|
302
|
-
const errors = validate2.errors
|
|
306
|
+
const errors = validate2.errors ? (0, import_common_utils.map)(
|
|
307
|
+
validate2.errors,
|
|
303
308
|
(e) => `${e.instancePath || "/"} ${e.message ?? "unknown error"}`
|
|
304
|
-
);
|
|
309
|
+
) : void 0;
|
|
305
310
|
return { valid: false, errors };
|
|
306
311
|
}
|
|
307
312
|
|
|
@@ -327,7 +332,7 @@ function readAsset(filename) {
|
|
|
327
332
|
// src/core/config.ts
|
|
328
333
|
function stripDangerousKeys(obj) {
|
|
329
334
|
if (obj === null || typeof obj !== "object") return obj;
|
|
330
|
-
if (
|
|
335
|
+
if ((0, import_common_utils2.isArray)(obj)) return (0, import_common_utils2.map)(obj, stripDangerousKeys);
|
|
331
336
|
const cleaned = {};
|
|
332
337
|
for (const [key, value] of Object.entries(obj)) {
|
|
333
338
|
if (["__proto__", "constructor", "prototype"].includes(key)) continue;
|
|
@@ -401,6 +406,7 @@ async function initDefaultConfig() {
|
|
|
401
406
|
// src/core/backup.ts
|
|
402
407
|
var import_promises6 = require("fs/promises");
|
|
403
408
|
var import_node_path7 = require("path");
|
|
409
|
+
var import_common_utils5 = require("@winglet/common-utils");
|
|
404
410
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
405
411
|
|
|
406
412
|
// src/utils/system.ts
|
|
@@ -510,6 +516,10 @@ var logger = {
|
|
|
510
516
|
// src/core/metadata.ts
|
|
511
517
|
var import_node_crypto = require("crypto");
|
|
512
518
|
var import_promises4 = require("fs/promises");
|
|
519
|
+
var import_common_utils4 = require("@winglet/common-utils");
|
|
520
|
+
|
|
521
|
+
// src/schemas/metadata.schema.ts
|
|
522
|
+
var import_common_utils3 = require("@winglet/common-utils");
|
|
513
523
|
|
|
514
524
|
// assets/schemas/metadata.schema.json
|
|
515
525
|
var metadata_schema_default = {
|
|
@@ -639,14 +649,15 @@ var validate3 = ajv.compile(metadata_schema_default);
|
|
|
639
649
|
function validateMetadata(data) {
|
|
640
650
|
const valid = validate3(data);
|
|
641
651
|
if (valid) return { valid: true };
|
|
642
|
-
const errors = validate3.errors
|
|
652
|
+
const errors = validate3.errors ? (0, import_common_utils3.map)(
|
|
653
|
+
validate3.errors,
|
|
643
654
|
(e) => `${e.instancePath || "/"} ${e.message ?? "unknown error"}`
|
|
644
|
-
);
|
|
655
|
+
) : void 0;
|
|
645
656
|
return { valid: false, errors };
|
|
646
657
|
}
|
|
647
658
|
|
|
648
659
|
// src/version.ts
|
|
649
|
-
var VERSION = "0.0.
|
|
660
|
+
var VERSION = "0.0.12";
|
|
650
661
|
|
|
651
662
|
// src/core/metadata.ts
|
|
652
663
|
var METADATA_VERSION = "1.0.0";
|
|
@@ -670,7 +681,7 @@ function createMetadata(files, config) {
|
|
|
670
681
|
};
|
|
671
682
|
}
|
|
672
683
|
function parseMetadata(data) {
|
|
673
|
-
const str =
|
|
684
|
+
const str = (0, import_common_utils4.isString)(data) ? data : data.toString("utf-8");
|
|
674
685
|
const parsed = JSON.parse(str);
|
|
675
686
|
const result = validateMetadata(parsed);
|
|
676
687
|
if (!result.valid) {
|
|
@@ -824,7 +835,8 @@ async function scanTargets(config) {
|
|
|
824
835
|
"**/Library/**",
|
|
825
836
|
"**/.cache/**",
|
|
826
837
|
"**/node_modules/**",
|
|
827
|
-
...
|
|
838
|
+
...(0, import_common_utils5.filter)(
|
|
839
|
+
config.backup.exclude,
|
|
828
840
|
(p) => detectPatternType(p) === "glob"
|
|
829
841
|
)
|
|
830
842
|
]
|
|
@@ -995,6 +1007,7 @@ async function createBackup(config, options = {}) {
|
|
|
995
1007
|
// src/core/restore.ts
|
|
996
1008
|
var import_promises7 = require("fs/promises");
|
|
997
1009
|
var import_node_path8 = require("path");
|
|
1010
|
+
var import_common_utils6 = require("@winglet/common-utils");
|
|
998
1011
|
async function getBackupList(config) {
|
|
999
1012
|
const backupDir = config?.backup.destination ? resolveTargetPath(config.backup.destination) : getSubDir(BACKUPS_DIR);
|
|
1000
1013
|
const exists = await fileExists(backupDir);
|
|
@@ -1099,15 +1112,26 @@ async function restoreBackup(archivePath, options = {}) {
|
|
|
1099
1112
|
const plan = await getRestorePlan(archivePath);
|
|
1100
1113
|
const restoredFiles = [];
|
|
1101
1114
|
const skippedFiles = [];
|
|
1102
|
-
const overwritePaths =
|
|
1115
|
+
const overwritePaths = [];
|
|
1116
|
+
(0, import_common_utils6.forEach)(plan.actions, (a) => {
|
|
1117
|
+
if (a.action === "overwrite") overwritePaths.push(a.path);
|
|
1118
|
+
});
|
|
1103
1119
|
let safetyBackupPath;
|
|
1104
1120
|
if (overwritePaths.length > 0 && !options.dryRun) {
|
|
1105
1121
|
safetyBackupPath = await createSafetyBackup(overwritePaths);
|
|
1106
1122
|
}
|
|
1107
1123
|
if (options.dryRun) {
|
|
1124
|
+
const restoredFiles2 = [];
|
|
1125
|
+
(0, import_common_utils6.forEach)(plan.actions, (a) => {
|
|
1126
|
+
if (a.action !== "skip") restoredFiles2.push(a.path);
|
|
1127
|
+
});
|
|
1128
|
+
const skippedFiles2 = [];
|
|
1129
|
+
(0, import_common_utils6.forEach)(plan.actions, (a) => {
|
|
1130
|
+
if (a.action === "skip") skippedFiles2.push(a.path);
|
|
1131
|
+
});
|
|
1108
1132
|
return {
|
|
1109
|
-
restoredFiles:
|
|
1110
|
-
skippedFiles:
|
|
1133
|
+
restoredFiles: restoredFiles2,
|
|
1134
|
+
skippedFiles: skippedFiles2,
|
|
1111
1135
|
safetyBackupPath
|
|
1112
1136
|
};
|
|
1113
1137
|
}
|
|
@@ -1154,8 +1178,12 @@ async function restoreBackup(archivePath, options = {}) {
|
|
|
1154
1178
|
var import_node_child_process = require("child_process");
|
|
1155
1179
|
var import_promises8 = require("fs/promises");
|
|
1156
1180
|
var import_node_path9 = require("path");
|
|
1181
|
+
var import_common_utils8 = require("@winglet/common-utils");
|
|
1157
1182
|
var import_yaml2 = __toESM(require("yaml"), 1);
|
|
1158
1183
|
|
|
1184
|
+
// src/schemas/template.schema.ts
|
|
1185
|
+
var import_common_utils7 = require("@winglet/common-utils");
|
|
1186
|
+
|
|
1159
1187
|
// assets/schemas/template.schema.json
|
|
1160
1188
|
var template_schema_default = {
|
|
1161
1189
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
@@ -1224,9 +1252,10 @@ var validate4 = ajv.compile(template_schema_default);
|
|
|
1224
1252
|
function validateTemplate(data) {
|
|
1225
1253
|
const valid = validate4(data);
|
|
1226
1254
|
if (valid) return { valid: true };
|
|
1227
|
-
const errors = validate4.errors
|
|
1255
|
+
const errors = validate4.errors ? (0, import_common_utils7.map)(
|
|
1256
|
+
validate4.errors,
|
|
1228
1257
|
(e) => `${e.instancePath || "/"} ${e.message ?? "unknown error"}`
|
|
1229
|
-
);
|
|
1258
|
+
) : void 0;
|
|
1230
1259
|
return { valid: false, errors };
|
|
1231
1260
|
}
|
|
1232
1261
|
|
|
@@ -1338,7 +1367,7 @@ async function executeStep(step) {
|
|
|
1338
1367
|
}
|
|
1339
1368
|
try {
|
|
1340
1369
|
const { stdout, stderr } = await execAsync(step.command);
|
|
1341
|
-
const output = [stdout, stderr].
|
|
1370
|
+
const output = (0, import_common_utils8.filter)([stdout, stderr], import_common_utils8.isTruthy).join("\n").trim();
|
|
1342
1371
|
return {
|
|
1343
1372
|
name: step.name,
|
|
1344
1373
|
status: "success",
|
|
@@ -1349,7 +1378,7 @@ async function executeStep(step) {
|
|
|
1349
1378
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
1350
1379
|
const stdout = err?.stdout ?? "";
|
|
1351
1380
|
const stderr = err?.stderr ?? "";
|
|
1352
|
-
const errorOutput = [stdout, stderr, error.message].
|
|
1381
|
+
const errorOutput = (0, import_common_utils8.filter)([stdout, stderr, error.message], import_common_utils8.isTruthy).join("\n").trim();
|
|
1353
1382
|
return {
|
|
1354
1383
|
name: step.name,
|
|
1355
1384
|
status: "failed",
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/core/config.ts
|
|
2
2
|
import { readFile, writeFile } from "fs/promises";
|
|
3
3
|
import { join as join4 } from "path";
|
|
4
|
+
import { isArray, map as map2 } from "@winglet/common-utils";
|
|
4
5
|
import YAML from "yaml";
|
|
5
6
|
|
|
6
7
|
// src/constants.ts
|
|
@@ -76,6 +77,9 @@ function getSubDir(sub) {
|
|
|
76
77
|
return join2(getAppDir(), sub);
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
// src/schemas/config.schema.ts
|
|
81
|
+
import { map } from "@winglet/common-utils";
|
|
82
|
+
|
|
79
83
|
// assets/schemas/config.schema.json
|
|
80
84
|
var config_schema_default = {
|
|
81
85
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
@@ -249,9 +253,10 @@ var validate2 = ajv.compile(config_schema_default);
|
|
|
249
253
|
function validateConfig(data) {
|
|
250
254
|
const valid = validate2(data);
|
|
251
255
|
if (valid) return { valid: true };
|
|
252
|
-
const errors = validate2.errors
|
|
256
|
+
const errors = validate2.errors ? map(
|
|
257
|
+
validate2.errors,
|
|
253
258
|
(e) => `${e.instancePath || "/"} ${e.message ?? "unknown error"}`
|
|
254
|
-
);
|
|
259
|
+
) : void 0;
|
|
255
260
|
return { valid: false, errors };
|
|
256
261
|
}
|
|
257
262
|
|
|
@@ -277,7 +282,7 @@ function readAsset(filename) {
|
|
|
277
282
|
// src/core/config.ts
|
|
278
283
|
function stripDangerousKeys(obj) {
|
|
279
284
|
if (obj === null || typeof obj !== "object") return obj;
|
|
280
|
-
if (
|
|
285
|
+
if (isArray(obj)) return map2(obj, stripDangerousKeys);
|
|
281
286
|
const cleaned = {};
|
|
282
287
|
for (const [key, value] of Object.entries(obj)) {
|
|
283
288
|
if (["__proto__", "constructor", "prototype"].includes(key)) continue;
|
|
@@ -351,6 +356,7 @@ async function initDefaultConfig() {
|
|
|
351
356
|
// src/core/backup.ts
|
|
352
357
|
import { readdir } from "fs/promises";
|
|
353
358
|
import { basename, join as join7 } from "path";
|
|
359
|
+
import { filter } from "@winglet/common-utils";
|
|
354
360
|
import fg from "fast-glob";
|
|
355
361
|
|
|
356
362
|
// src/utils/system.ts
|
|
@@ -460,6 +466,10 @@ var logger = {
|
|
|
460
466
|
// src/core/metadata.ts
|
|
461
467
|
import { createHash } from "crypto";
|
|
462
468
|
import { lstat, readFile as readFile2, readlink } from "fs/promises";
|
|
469
|
+
import { isString } from "@winglet/common-utils";
|
|
470
|
+
|
|
471
|
+
// src/schemas/metadata.schema.ts
|
|
472
|
+
import { map as map3 } from "@winglet/common-utils";
|
|
463
473
|
|
|
464
474
|
// assets/schemas/metadata.schema.json
|
|
465
475
|
var metadata_schema_default = {
|
|
@@ -589,14 +599,15 @@ var validate3 = ajv.compile(metadata_schema_default);
|
|
|
589
599
|
function validateMetadata(data) {
|
|
590
600
|
const valid = validate3(data);
|
|
591
601
|
if (valid) return { valid: true };
|
|
592
|
-
const errors = validate3.errors
|
|
602
|
+
const errors = validate3.errors ? map3(
|
|
603
|
+
validate3.errors,
|
|
593
604
|
(e) => `${e.instancePath || "/"} ${e.message ?? "unknown error"}`
|
|
594
|
-
);
|
|
605
|
+
) : void 0;
|
|
595
606
|
return { valid: false, errors };
|
|
596
607
|
}
|
|
597
608
|
|
|
598
609
|
// src/version.ts
|
|
599
|
-
var VERSION = "0.0.
|
|
610
|
+
var VERSION = "0.0.12";
|
|
600
611
|
|
|
601
612
|
// src/core/metadata.ts
|
|
602
613
|
var METADATA_VERSION = "1.0.0";
|
|
@@ -620,7 +631,7 @@ function createMetadata(files, config) {
|
|
|
620
631
|
};
|
|
621
632
|
}
|
|
622
633
|
function parseMetadata(data) {
|
|
623
|
-
const str =
|
|
634
|
+
const str = isString(data) ? data : data.toString("utf-8");
|
|
624
635
|
const parsed = JSON.parse(str);
|
|
625
636
|
const result = validateMetadata(parsed);
|
|
626
637
|
if (!result.valid) {
|
|
@@ -774,7 +785,8 @@ async function scanTargets(config) {
|
|
|
774
785
|
"**/Library/**",
|
|
775
786
|
"**/.cache/**",
|
|
776
787
|
"**/node_modules/**",
|
|
777
|
-
...
|
|
788
|
+
...filter(
|
|
789
|
+
config.backup.exclude,
|
|
778
790
|
(p) => detectPatternType(p) === "glob"
|
|
779
791
|
)
|
|
780
792
|
]
|
|
@@ -945,6 +957,7 @@ async function createBackup(config, options = {}) {
|
|
|
945
957
|
// src/core/restore.ts
|
|
946
958
|
import { copyFile, lstat as lstat2, readdir as readdir2, stat as stat2 } from "fs/promises";
|
|
947
959
|
import { dirname as dirname2, join as join8 } from "path";
|
|
960
|
+
import { forEach } from "@winglet/common-utils";
|
|
948
961
|
async function getBackupList(config) {
|
|
949
962
|
const backupDir = config?.backup.destination ? resolveTargetPath(config.backup.destination) : getSubDir(BACKUPS_DIR);
|
|
950
963
|
const exists = await fileExists(backupDir);
|
|
@@ -1049,15 +1062,26 @@ async function restoreBackup(archivePath, options = {}) {
|
|
|
1049
1062
|
const plan = await getRestorePlan(archivePath);
|
|
1050
1063
|
const restoredFiles = [];
|
|
1051
1064
|
const skippedFiles = [];
|
|
1052
|
-
const overwritePaths =
|
|
1065
|
+
const overwritePaths = [];
|
|
1066
|
+
forEach(plan.actions, (a) => {
|
|
1067
|
+
if (a.action === "overwrite") overwritePaths.push(a.path);
|
|
1068
|
+
});
|
|
1053
1069
|
let safetyBackupPath;
|
|
1054
1070
|
if (overwritePaths.length > 0 && !options.dryRun) {
|
|
1055
1071
|
safetyBackupPath = await createSafetyBackup(overwritePaths);
|
|
1056
1072
|
}
|
|
1057
1073
|
if (options.dryRun) {
|
|
1074
|
+
const restoredFiles2 = [];
|
|
1075
|
+
forEach(plan.actions, (a) => {
|
|
1076
|
+
if (a.action !== "skip") restoredFiles2.push(a.path);
|
|
1077
|
+
});
|
|
1078
|
+
const skippedFiles2 = [];
|
|
1079
|
+
forEach(plan.actions, (a) => {
|
|
1080
|
+
if (a.action === "skip") skippedFiles2.push(a.path);
|
|
1081
|
+
});
|
|
1058
1082
|
return {
|
|
1059
|
-
restoredFiles:
|
|
1060
|
-
skippedFiles:
|
|
1083
|
+
restoredFiles: restoredFiles2,
|
|
1084
|
+
skippedFiles: skippedFiles2,
|
|
1061
1085
|
safetyBackupPath
|
|
1062
1086
|
};
|
|
1063
1087
|
}
|
|
@@ -1104,8 +1128,12 @@ async function restoreBackup(archivePath, options = {}) {
|
|
|
1104
1128
|
import { exec } from "child_process";
|
|
1105
1129
|
import { readFile as readFile4, readdir as readdir3 } from "fs/promises";
|
|
1106
1130
|
import { join as join9 } from "path";
|
|
1131
|
+
import { filter as filter2, isTruthy } from "@winglet/common-utils";
|
|
1107
1132
|
import YAML2 from "yaml";
|
|
1108
1133
|
|
|
1134
|
+
// src/schemas/template.schema.ts
|
|
1135
|
+
import { map as map4 } from "@winglet/common-utils";
|
|
1136
|
+
|
|
1109
1137
|
// assets/schemas/template.schema.json
|
|
1110
1138
|
var template_schema_default = {
|
|
1111
1139
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
@@ -1174,9 +1202,10 @@ var validate4 = ajv.compile(template_schema_default);
|
|
|
1174
1202
|
function validateTemplate(data) {
|
|
1175
1203
|
const valid = validate4(data);
|
|
1176
1204
|
if (valid) return { valid: true };
|
|
1177
|
-
const errors = validate4.errors
|
|
1205
|
+
const errors = validate4.errors ? map4(
|
|
1206
|
+
validate4.errors,
|
|
1178
1207
|
(e) => `${e.instancePath || "/"} ${e.message ?? "unknown error"}`
|
|
1179
|
-
);
|
|
1208
|
+
) : void 0;
|
|
1180
1209
|
return { valid: false, errors };
|
|
1181
1210
|
}
|
|
1182
1211
|
|
|
@@ -1288,7 +1317,7 @@ async function executeStep(step) {
|
|
|
1288
1317
|
}
|
|
1289
1318
|
try {
|
|
1290
1319
|
const { stdout, stderr } = await execAsync(step.command);
|
|
1291
|
-
const output = [stdout, stderr]
|
|
1320
|
+
const output = filter2([stdout, stderr], isTruthy).join("\n").trim();
|
|
1292
1321
|
return {
|
|
1293
1322
|
name: step.name,
|
|
1294
1323
|
status: "success",
|
|
@@ -1299,7 +1328,7 @@ async function executeStep(step) {
|
|
|
1299
1328
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
1300
1329
|
const stdout = err?.stdout ?? "";
|
|
1301
1330
|
const stderr = err?.stderr ?? "";
|
|
1302
|
-
const errorOutput = [stdout, stderr, error.message]
|
|
1331
|
+
const errorOutput = filter2([stdout, stderr, error.message], isTruthy).join("\n").trim();
|
|
1303
1332
|
return {
|
|
1304
1333
|
name: step.name,
|
|
1305
1334
|
status: "failed",
|
package/dist/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumy-pack/syncpoint",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "CLI tool for project synchronization and scaffolding",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -56,6 +56,8 @@
|
|
|
56
56
|
"version:patch": "yarn version patch"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
+
"@winglet/common-utils": "^0.11.2",
|
|
60
|
+
"@winglet/react-utils": "^0.11.2",
|
|
59
61
|
"ajv": "^8.0.0",
|
|
60
62
|
"ajv-formats": "^3.0.0",
|
|
61
63
|
"commander": "^12.1.0",
|