@tinyrack/devsync 1.1.0 → 1.2.2
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 +230 -62
- package/dist/cli/base-command.d.ts +14 -0
- package/dist/cli/base-command.d.ts.map +1 -0
- package/dist/cli/base-command.js +22 -0
- package/dist/cli/base-command.js.map +1 -0
- package/dist/cli/commands/dir.d.ts +8 -0
- package/dist/cli/commands/dir.d.ts.map +1 -0
- package/dist/cli/commands/dir.js +16 -0
- package/dist/cli/commands/dir.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +8 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +18 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/index.d.ts +23 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +23 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/init.d.ts +15 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +43 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/machine/list.d.ts +7 -0
- package/dist/cli/commands/machine/list.d.ts.map +1 -0
- package/dist/cli/commands/machine/list.js +12 -0
- package/dist/cli/commands/machine/list.js.map +1 -0
- package/dist/cli/commands/machine/use.d.ts +11 -0
- package/dist/cli/commands/machine/use.d.ts.map +1 -0
- package/dist/cli/commands/machine/use.js +28 -0
- package/dist/cli/commands/machine/use.js.map +1 -0
- package/dist/cli/commands/pull.d.ts +12 -0
- package/dist/cli/commands/pull.d.ts.map +1 -0
- package/dist/cli/commands/pull.js +34 -0
- package/dist/cli/commands/pull.js.map +1 -0
- package/dist/cli/commands/push.d.ts +12 -0
- package/dist/cli/commands/push.d.ts.map +1 -0
- package/dist/cli/commands/push.js +34 -0
- package/dist/cli/commands/push.js.map +1 -0
- package/dist/cli/commands/status.d.ts +11 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +27 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/track.d.ts +16 -0
- package/dist/cli/commands/track.d.ts.map +1 -0
- package/dist/cli/commands/track.js +82 -0
- package/dist/cli/commands/track.js.map +1 -0
- package/dist/cli/commands/untrack.d.ts +11 -0
- package/dist/cli/commands/untrack.d.ts.map +1 -0
- package/dist/cli/commands/untrack.js +28 -0
- package/dist/cli/commands/untrack.js.map +1 -0
- package/dist/config/global-config.d.ts +21 -0
- package/dist/config/global-config.d.ts.map +1 -0
- package/dist/config/global-config.js +106 -0
- package/dist/config/global-config.js.map +1 -0
- package/dist/config/sync.d.ts +96 -0
- package/dist/config/sync.d.ts.map +1 -0
- package/dist/config/sync.js +412 -0
- package/dist/config/sync.js.map +1 -0
- package/dist/config/xdg.d.ts +11 -0
- package/dist/config/xdg.d.ts.map +1 -0
- package/dist/config/xdg.js +79 -0
- package/dist/config/xdg.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/{src/index.ts → dist/index.js} +1 -1
- package/dist/index.js.map +1 -0
- package/dist/lib/file-mode.d.ts +3 -0
- package/dist/lib/file-mode.d.ts.map +1 -0
- package/dist/lib/file-mode.js +7 -0
- package/dist/lib/file-mode.js.map +1 -0
- package/dist/lib/output.d.ts +31 -0
- package/dist/lib/output.d.ts.map +1 -0
- package/dist/lib/output.js +198 -0
- package/dist/lib/output.js.map +1 -0
- package/dist/lib/path.d.ts +5 -0
- package/dist/lib/path.d.ts.map +1 -0
- package/dist/lib/path.js +25 -0
- package/dist/lib/path.js.map +1 -0
- package/dist/lib/string.d.ts +2 -0
- package/dist/lib/string.d.ts.map +1 -0
- package/dist/lib/string.js +4 -0
- package/dist/lib/string.js.map +1 -0
- package/dist/lib/validation.d.ts +3 -0
- package/dist/lib/validation.d.ts.map +1 -0
- package/dist/lib/validation.js +9 -0
- package/dist/lib/validation.js.map +1 -0
- package/dist/services/add.d.ts +20 -0
- package/dist/services/add.d.ts.map +1 -0
- package/dist/services/add.js +161 -0
- package/dist/services/add.js.map +1 -0
- package/dist/services/config-file.d.ts +30 -0
- package/dist/services/config-file.d.ts.map +1 -0
- package/dist/services/config-file.js +34 -0
- package/dist/services/config-file.js.map +1 -0
- package/dist/services/crypto.d.ts +9 -0
- package/dist/services/crypto.d.ts.map +1 -0
- package/dist/services/crypto.js +75 -0
- package/dist/services/crypto.js.map +1 -0
- package/dist/services/doctor.d.ts +16 -0
- package/dist/services/doctor.d.ts.map +1 -0
- package/dist/services/doctor.js +84 -0
- package/dist/services/doctor.js.map +1 -0
- package/dist/services/error.d.ts +14 -0
- package/dist/services/error.d.ts.map +1 -0
- package/dist/services/error.js +38 -0
- package/dist/services/error.js.map +1 -0
- package/dist/services/filesystem.d.ts +15 -0
- package/dist/services/filesystem.d.ts.map +1 -0
- package/dist/services/filesystem.js +113 -0
- package/dist/services/filesystem.js.map +1 -0
- package/dist/services/forget.d.ts +14 -0
- package/dist/services/forget.d.ts.map +1 -0
- package/dist/services/forget.js +124 -0
- package/dist/services/forget.js.map +1 -0
- package/dist/services/git.d.ts +10 -0
- package/dist/services/git.d.ts.map +1 -0
- package/dist/services/git.js +57 -0
- package/dist/services/git.js.map +1 -0
- package/dist/services/init.d.ts +19 -0
- package/dist/services/init.d.ts.map +1 -0
- package/dist/services/init.js +203 -0
- package/dist/services/init.js.map +1 -0
- package/dist/services/local-materialization.d.ts +28 -0
- package/dist/services/local-materialization.d.ts.map +1 -0
- package/dist/services/local-materialization.js +262 -0
- package/dist/services/local-materialization.js.map +1 -0
- package/dist/services/local-snapshot.d.ts +25 -0
- package/dist/services/local-snapshot.d.ts.map +1 -0
- package/dist/services/local-snapshot.js +93 -0
- package/dist/services/local-snapshot.js.map +1 -0
- package/dist/services/machine.d.ts +40 -0
- package/dist/services/machine.d.ts.map +1 -0
- package/dist/services/machine.js +113 -0
- package/dist/services/machine.js.map +1 -0
- package/dist/services/paths.d.ts +12 -0
- package/dist/services/paths.d.ts.map +1 -0
- package/dist/services/paths.js +71 -0
- package/dist/services/paths.js.map +1 -0
- package/dist/services/pull.d.ts +28 -0
- package/dist/services/pull.d.ts.map +1 -0
- package/dist/services/pull.js +67 -0
- package/dist/services/pull.js.map +1 -0
- package/dist/services/push.d.ts +35 -0
- package/dist/services/push.d.ts.map +1 -0
- package/dist/services/push.js +96 -0
- package/dist/services/push.js.map +1 -0
- package/dist/services/repo-artifacts.d.ts +52 -0
- package/dist/services/repo-artifacts.d.ts.map +1 -0
- package/dist/services/repo-artifacts.js +251 -0
- package/dist/services/repo-artifacts.js.map +1 -0
- package/dist/services/repo-snapshot.d.ts +6 -0
- package/dist/services/repo-snapshot.d.ts.map +1 -0
- package/dist/services/repo-snapshot.js +163 -0
- package/dist/services/repo-snapshot.js.map +1 -0
- package/dist/services/runtime.d.ts +40 -0
- package/dist/services/runtime.d.ts.map +1 -0
- package/dist/services/runtime.js +71 -0
- package/dist/services/runtime.js.map +1 -0
- package/dist/services/set.d.ts +38 -0
- package/dist/services/set.d.ts.map +1 -0
- package/dist/services/set.js +184 -0
- package/dist/services/set.js.map +1 -0
- package/dist/services/status.d.ts +30 -0
- package/dist/services/status.d.ts.map +1 -0
- package/dist/services/status.js +35 -0
- package/dist/services/status.js.map +1 -0
- package/package.json +15 -7
- package/src/cli/commands/add.ts +0 -40
- package/src/cli/commands/cd.ts +0 -80
- package/src/cli/commands/doctor.ts +0 -20
- package/src/cli/commands/forget.ts +0 -32
- package/src/cli/commands/index.ts +0 -23
- package/src/cli/commands/init.ts +0 -43
- package/src/cli/commands/list.ts +0 -17
- package/src/cli/commands/pull.ts +0 -31
- package/src/cli/commands/push.ts +0 -31
- package/src/cli/commands/set.ts +0 -47
- package/src/cli/commands/status.ts +0 -18
- package/src/cli/sync-output.test.ts +0 -173
- package/src/cli/sync-output.ts +0 -200
- package/src/config/sync.test.ts +0 -609
- package/src/config/sync.ts +0 -572
- package/src/config/xdg.ts +0 -138
- package/src/lib/string.test.ts +0 -13
- package/src/lib/string.ts +0 -3
- package/src/lib/validation.test.ts +0 -32
- package/src/lib/validation.ts +0 -11
- package/src/services/add.ts +0 -178
- package/src/services/config-file.test.ts +0 -161
- package/src/services/config-file.ts +0 -101
- package/src/services/crypto.test.ts +0 -132
- package/src/services/crypto.ts +0 -83
- package/src/services/doctor.ts +0 -142
- package/src/services/error.ts +0 -6
- package/src/services/filesystem.test.ts +0 -171
- package/src/services/filesystem.ts +0 -183
- package/src/services/forget.ts +0 -261
- package/src/services/git.test.ts +0 -83
- package/src/services/git.ts +0 -74
- package/src/services/init.test.ts +0 -109
- package/src/services/init.ts +0 -244
- package/src/services/list.ts +0 -63
- package/src/services/local-materialization.ts +0 -421
- package/src/services/local-snapshot.ts +0 -173
- package/src/services/paths.test.ts +0 -74
- package/src/services/paths.ts +0 -98
- package/src/services/pull.ts +0 -144
- package/src/services/push.ts +0 -168
- package/src/services/repo-artifacts.ts +0 -262
- package/src/services/repo-snapshot.ts +0 -197
- package/src/services/runtime.ts +0 -57
- package/src/services/set.ts +0 -383
- package/src/services/status.ts +0 -57
- package/src/services/sync.dry-run.test.ts +0 -179
- package/src/services/sync.runtime.test.ts +0 -756
- package/src/services/sync.service.test.ts +0 -1169
- package/src/test/helpers/sync-fixture.ts +0 -47
package/src/cli/commands/pull.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Command, Flags } from "@oclif/core";
|
|
2
|
-
|
|
3
|
-
import { formatSyncPullResult } from "#app/cli/sync-output.ts";
|
|
4
|
-
import { pullSync } from "#app/services/pull.ts";
|
|
5
|
-
import { createSyncContext } from "#app/services/runtime.ts";
|
|
6
|
-
|
|
7
|
-
export default class SyncPull extends Command {
|
|
8
|
-
public static override summary =
|
|
9
|
-
"Apply the git-backed sync repository to local config paths";
|
|
10
|
-
|
|
11
|
-
public static override flags = {
|
|
12
|
-
"dry-run": Flags.boolean({
|
|
13
|
-
default: false,
|
|
14
|
-
description: "Preview local config changes without writing files",
|
|
15
|
-
}),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
public override async run(): Promise<void> {
|
|
19
|
-
const { flags } = await this.parse(SyncPull);
|
|
20
|
-
const output = formatSyncPullResult(
|
|
21
|
-
await pullSync(
|
|
22
|
-
{
|
|
23
|
-
dryRun: flags["dry-run"],
|
|
24
|
-
},
|
|
25
|
-
createSyncContext(),
|
|
26
|
-
),
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
process.stdout.write(output);
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/cli/commands/push.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Command, Flags } from "@oclif/core";
|
|
2
|
-
|
|
3
|
-
import { formatSyncPushResult } from "#app/cli/sync-output.ts";
|
|
4
|
-
import { pushSync } from "#app/services/push.ts";
|
|
5
|
-
import { createSyncContext } from "#app/services/runtime.ts";
|
|
6
|
-
|
|
7
|
-
export default class SyncPush extends Command {
|
|
8
|
-
public static override summary =
|
|
9
|
-
"Mirror local config into the git-backed sync repository";
|
|
10
|
-
|
|
11
|
-
public static override flags = {
|
|
12
|
-
"dry-run": Flags.boolean({
|
|
13
|
-
default: false,
|
|
14
|
-
description: "Preview sync repository changes without writing files",
|
|
15
|
-
}),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
public override async run(): Promise<void> {
|
|
19
|
-
const { flags } = await this.parse(SyncPush);
|
|
20
|
-
const output = formatSyncPushResult(
|
|
21
|
-
await pushSync(
|
|
22
|
-
{
|
|
23
|
-
dryRun: flags["dry-run"],
|
|
24
|
-
},
|
|
25
|
-
createSyncContext(),
|
|
26
|
-
),
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
process.stdout.write(output);
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/cli/commands/set.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Args, Command, Flags } from "@oclif/core";
|
|
2
|
-
|
|
3
|
-
import { formatSyncSetResult } from "#app/cli/sync-output.ts";
|
|
4
|
-
import { createSyncContext } from "#app/services/runtime.ts";
|
|
5
|
-
import { setSyncTargetMode } from "#app/services/set.ts";
|
|
6
|
-
|
|
7
|
-
export default class SyncSet extends Command {
|
|
8
|
-
public static override summary =
|
|
9
|
-
"Set sync mode for a tracked directory root, child file, or child subtree";
|
|
10
|
-
|
|
11
|
-
public static override args = {
|
|
12
|
-
state: Args.string({
|
|
13
|
-
description: "Mode to apply: normal, secret, or ignore",
|
|
14
|
-
options: ["normal", "secret", "ignore"],
|
|
15
|
-
required: true,
|
|
16
|
-
}),
|
|
17
|
-
target: Args.string({
|
|
18
|
-
description:
|
|
19
|
-
"Tracked local path (including cwd-relative) or repository path inside a tracked directory",
|
|
20
|
-
required: true,
|
|
21
|
-
}),
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
public static override flags = {
|
|
25
|
-
recursive: Flags.boolean({
|
|
26
|
-
default: false,
|
|
27
|
-
description:
|
|
28
|
-
"Apply the mode to a directory subtree or update a tracked directory root default",
|
|
29
|
-
}),
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
public override async run(): Promise<void> {
|
|
33
|
-
const { args, flags } = await this.parse(SyncSet);
|
|
34
|
-
const output = formatSyncSetResult(
|
|
35
|
-
await setSyncTargetMode(
|
|
36
|
-
{
|
|
37
|
-
recursive: flags.recursive,
|
|
38
|
-
state: args.state as "ignore" | "normal" | "secret",
|
|
39
|
-
target: args.target,
|
|
40
|
-
},
|
|
41
|
-
createSyncContext(),
|
|
42
|
-
),
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
process.stdout.write(output);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Command } from "@oclif/core";
|
|
2
|
-
|
|
3
|
-
import { formatSyncStatusResult } from "#app/cli/sync-output.ts";
|
|
4
|
-
import { createSyncContext } from "#app/services/runtime.ts";
|
|
5
|
-
import { getSyncStatus } from "#app/services/status.ts";
|
|
6
|
-
|
|
7
|
-
export default class SyncStatus extends Command {
|
|
8
|
-
public static override summary =
|
|
9
|
-
"Show planned push and pull changes for the current sync config";
|
|
10
|
-
|
|
11
|
-
public override async run(): Promise<void> {
|
|
12
|
-
const output = formatSyncStatusResult(
|
|
13
|
-
await getSyncStatus(createSyncContext()),
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
process.stdout.write(output);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
formatSyncAddResult,
|
|
5
|
-
formatSyncDoctorResult,
|
|
6
|
-
formatSyncForgetResult,
|
|
7
|
-
formatSyncInitResult,
|
|
8
|
-
formatSyncListResult,
|
|
9
|
-
formatSyncPullResult,
|
|
10
|
-
formatSyncPushResult,
|
|
11
|
-
formatSyncSetResult,
|
|
12
|
-
formatSyncStatusResult,
|
|
13
|
-
} from "#app/cli/sync-output.ts";
|
|
14
|
-
|
|
15
|
-
describe("sync output formatting", () => {
|
|
16
|
-
it("formats init results for cloned repositories", () => {
|
|
17
|
-
expect(
|
|
18
|
-
formatSyncInitResult({
|
|
19
|
-
alreadyInitialized: false,
|
|
20
|
-
configPath: "/tmp/sync/config.json",
|
|
21
|
-
entryCount: 2,
|
|
22
|
-
generatedIdentity: true,
|
|
23
|
-
gitAction: "cloned",
|
|
24
|
-
gitSource: "/tmp/remote",
|
|
25
|
-
identityFile: "/tmp/xdg/devsync/age/keys.txt",
|
|
26
|
-
recipientCount: 3,
|
|
27
|
-
ruleCount: 4,
|
|
28
|
-
syncDirectory: "/tmp/sync",
|
|
29
|
-
}),
|
|
30
|
-
).toBe(
|
|
31
|
-
[
|
|
32
|
-
"Initialized sync directory.",
|
|
33
|
-
"Sync directory: /tmp/sync",
|
|
34
|
-
"Config file: /tmp/sync/config.json",
|
|
35
|
-
"Age identity file: /tmp/xdg/devsync/age/keys.txt",
|
|
36
|
-
"Git repository: cloned from /tmp/remote",
|
|
37
|
-
"Age bootstrap: generated a new local identity.",
|
|
38
|
-
"Summary: 3 recipients, 2 entries, 4 rules.",
|
|
39
|
-
"",
|
|
40
|
-
].join("\n"),
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("formats add, forget, and set results", () => {
|
|
45
|
-
expect(
|
|
46
|
-
formatSyncAddResult({
|
|
47
|
-
alreadyTracked: false,
|
|
48
|
-
configPath: "/tmp/sync/config.json",
|
|
49
|
-
kind: "file",
|
|
50
|
-
localPath: "/tmp/home/.zshrc",
|
|
51
|
-
mode: "secret",
|
|
52
|
-
repoPath: ".zshrc",
|
|
53
|
-
syncDirectory: "/tmp/sync",
|
|
54
|
-
}),
|
|
55
|
-
).toContain("Added sync target.\n");
|
|
56
|
-
expect(
|
|
57
|
-
formatSyncForgetResult({
|
|
58
|
-
configPath: "/tmp/sync/config.json",
|
|
59
|
-
localPath: "/tmp/home/.zshrc",
|
|
60
|
-
plainArtifactCount: 1,
|
|
61
|
-
repoPath: ".zshrc",
|
|
62
|
-
secretArtifactCount: 2,
|
|
63
|
-
syncDirectory: "/tmp/sync",
|
|
64
|
-
}),
|
|
65
|
-
).toContain("Removed repo artifacts: 1 plain, 2 secret.\n");
|
|
66
|
-
expect(
|
|
67
|
-
formatSyncSetResult({
|
|
68
|
-
action: "updated",
|
|
69
|
-
configPath: "/tmp/sync/config.json",
|
|
70
|
-
entryRepoPath: "bundle",
|
|
71
|
-
localPath: "/tmp/home/bundle/private.json",
|
|
72
|
-
mode: "ignore",
|
|
73
|
-
repoPath: "bundle/private.json",
|
|
74
|
-
scope: "exact",
|
|
75
|
-
syncDirectory: "/tmp/sync",
|
|
76
|
-
}),
|
|
77
|
-
).toContain("Scope: exact rule\nAction: updated\n");
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("formats push and pull dry-run summaries", () => {
|
|
81
|
-
expect(
|
|
82
|
-
formatSyncPushResult({
|
|
83
|
-
configPath: "/tmp/sync/config.json",
|
|
84
|
-
deletedArtifactCount: 4,
|
|
85
|
-
directoryCount: 1,
|
|
86
|
-
dryRun: true,
|
|
87
|
-
encryptedFileCount: 2,
|
|
88
|
-
plainFileCount: 3,
|
|
89
|
-
symlinkCount: 1,
|
|
90
|
-
syncDirectory: "/tmp/sync",
|
|
91
|
-
}),
|
|
92
|
-
).toContain("No filesystem changes were made.\n");
|
|
93
|
-
expect(
|
|
94
|
-
formatSyncPullResult({
|
|
95
|
-
configPath: "/tmp/sync/config.json",
|
|
96
|
-
decryptedFileCount: 2,
|
|
97
|
-
deletedLocalCount: 5,
|
|
98
|
-
directoryCount: 1,
|
|
99
|
-
dryRun: true,
|
|
100
|
-
plainFileCount: 3,
|
|
101
|
-
symlinkCount: 1,
|
|
102
|
-
syncDirectory: "/tmp/sync",
|
|
103
|
-
}),
|
|
104
|
-
).toContain(
|
|
105
|
-
"local paths would be removed.\nNo filesystem changes were made.\n",
|
|
106
|
-
);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("formats list, status, and doctor results", () => {
|
|
110
|
-
expect(
|
|
111
|
-
formatSyncListResult({
|
|
112
|
-
configPath: "/tmp/sync/config.json",
|
|
113
|
-
entries: [
|
|
114
|
-
{
|
|
115
|
-
kind: "directory",
|
|
116
|
-
localPath: "/tmp/home/.config/tool",
|
|
117
|
-
mode: "normal",
|
|
118
|
-
name: ".config/tool",
|
|
119
|
-
overrides: [{ mode: "secret", selector: "token.json" }],
|
|
120
|
-
repoPath: ".config/tool",
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
recipientCount: 1,
|
|
124
|
-
ruleCount: 1,
|
|
125
|
-
syncDirectory: "/tmp/sync",
|
|
126
|
-
}),
|
|
127
|
-
).toContain("override token.json: secret\n");
|
|
128
|
-
expect(
|
|
129
|
-
formatSyncStatusResult({
|
|
130
|
-
configPath: "/tmp/sync/config.json",
|
|
131
|
-
entryCount: 1,
|
|
132
|
-
pull: {
|
|
133
|
-
configPath: "/tmp/sync/config.json",
|
|
134
|
-
decryptedFileCount: 1,
|
|
135
|
-
deletedLocalCount: 2,
|
|
136
|
-
directoryCount: 1,
|
|
137
|
-
dryRun: true,
|
|
138
|
-
plainFileCount: 0,
|
|
139
|
-
preview: ["bundle", "bundle/token.txt"],
|
|
140
|
-
symlinkCount: 0,
|
|
141
|
-
syncDirectory: "/tmp/sync",
|
|
142
|
-
},
|
|
143
|
-
push: {
|
|
144
|
-
configPath: "/tmp/sync/config.json",
|
|
145
|
-
deletedArtifactCount: 1,
|
|
146
|
-
directoryCount: 1,
|
|
147
|
-
dryRun: true,
|
|
148
|
-
encryptedFileCount: 1,
|
|
149
|
-
plainFileCount: 0,
|
|
150
|
-
preview: ["bundle", "bundle/token.txt"],
|
|
151
|
-
symlinkCount: 0,
|
|
152
|
-
syncDirectory: "/tmp/sync",
|
|
153
|
-
},
|
|
154
|
-
recipientCount: 1,
|
|
155
|
-
ruleCount: 0,
|
|
156
|
-
syncDirectory: "/tmp/sync",
|
|
157
|
-
}),
|
|
158
|
-
).toContain("Push preview: bundle, bundle/token.txt\n");
|
|
159
|
-
expect(
|
|
160
|
-
formatSyncDoctorResult({
|
|
161
|
-
checks: [
|
|
162
|
-
{ detail: "ok", level: "ok", name: "git" },
|
|
163
|
-
{ detail: "warn", level: "warn", name: "entries" },
|
|
164
|
-
{ detail: "fail", level: "fail", name: "age" },
|
|
165
|
-
],
|
|
166
|
-
configPath: "/tmp/sync/config.json",
|
|
167
|
-
hasFailures: true,
|
|
168
|
-
hasWarnings: true,
|
|
169
|
-
syncDirectory: "/tmp/sync",
|
|
170
|
-
}),
|
|
171
|
-
).toContain("Summary: 1 ok, 1 warnings, 1 failures.\n");
|
|
172
|
-
});
|
|
173
|
-
});
|
package/src/cli/sync-output.ts
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { ensureTrailingNewline } from "#app/lib/string.ts";
|
|
2
|
-
import type { SyncAddResult } from "#app/services/add.ts";
|
|
3
|
-
import type { SyncDoctorResult } from "#app/services/doctor.ts";
|
|
4
|
-
import type { SyncForgetResult } from "#app/services/forget.ts";
|
|
5
|
-
import type { SyncInitResult } from "#app/services/init.ts";
|
|
6
|
-
import type { SyncListResult } from "#app/services/list.ts";
|
|
7
|
-
import type { SyncPullResult } from "#app/services/pull.ts";
|
|
8
|
-
import type { SyncPushResult } from "#app/services/push.ts";
|
|
9
|
-
import type { SyncSetResult } from "#app/services/set.ts";
|
|
10
|
-
import type { SyncStatusResult } from "#app/services/status.ts";
|
|
11
|
-
|
|
12
|
-
export const formatSyncInitResult = (result: SyncInitResult) => {
|
|
13
|
-
const lines = [
|
|
14
|
-
result.alreadyInitialized
|
|
15
|
-
? "Sync directory already initialized."
|
|
16
|
-
: "Initialized sync directory.",
|
|
17
|
-
`Sync directory: ${result.syncDirectory}`,
|
|
18
|
-
`Config file: ${result.configPath}`,
|
|
19
|
-
`Age identity file: ${result.identityFile}`,
|
|
20
|
-
(() => {
|
|
21
|
-
switch (result.gitAction) {
|
|
22
|
-
case "cloned":
|
|
23
|
-
return `Git repository: cloned from ${result.gitSource}`;
|
|
24
|
-
case "initialized":
|
|
25
|
-
return "Git repository: initialized new repository";
|
|
26
|
-
default:
|
|
27
|
-
return "Git repository: using existing repository";
|
|
28
|
-
}
|
|
29
|
-
})(),
|
|
30
|
-
...(result.generatedIdentity
|
|
31
|
-
? ["Age bootstrap: generated a new local identity."]
|
|
32
|
-
: []),
|
|
33
|
-
`Summary: ${result.recipientCount} recipients, ${result.entryCount} entries, ${result.ruleCount} rules.`,
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
return ensureTrailingNewline(lines.join("\n"));
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const formatSyncAddResult = (result: SyncAddResult) => {
|
|
40
|
-
const lines = [
|
|
41
|
-
result.alreadyTracked
|
|
42
|
-
? "Sync target already tracked."
|
|
43
|
-
: "Added sync target.",
|
|
44
|
-
`Sync directory: ${result.syncDirectory}`,
|
|
45
|
-
`Config file: ${result.configPath}`,
|
|
46
|
-
`Local path: ${result.localPath}`,
|
|
47
|
-
`Repository path: ${result.repoPath}`,
|
|
48
|
-
`Kind: ${result.kind}`,
|
|
49
|
-
`Mode: ${result.mode}`,
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
return ensureTrailingNewline(lines.join("\n"));
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const formatSyncForgetResult = (result: SyncForgetResult) => {
|
|
56
|
-
const lines = [
|
|
57
|
-
"Forgot sync target.",
|
|
58
|
-
`Sync directory: ${result.syncDirectory}`,
|
|
59
|
-
`Config file: ${result.configPath}`,
|
|
60
|
-
`Local path: ${result.localPath}`,
|
|
61
|
-
`Repository path: ${result.repoPath}`,
|
|
62
|
-
`Removed repo artifacts: ${result.plainArtifactCount} plain, ${result.secretArtifactCount} secret.`,
|
|
63
|
-
];
|
|
64
|
-
|
|
65
|
-
return ensureTrailingNewline(lines.join("\n"));
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const formatSetScope = (scope: SyncSetResult["scope"]) => {
|
|
69
|
-
switch (scope) {
|
|
70
|
-
case "default":
|
|
71
|
-
return "entry default";
|
|
72
|
-
case "subtree":
|
|
73
|
-
return "subtree rule";
|
|
74
|
-
default:
|
|
75
|
-
return "exact rule";
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export const formatSyncSetResult = (result: SyncSetResult) => {
|
|
80
|
-
const lines = [
|
|
81
|
-
result.action === "unchanged"
|
|
82
|
-
? "Sync mode unchanged."
|
|
83
|
-
: "Updated sync mode.",
|
|
84
|
-
`Sync directory: ${result.syncDirectory}`,
|
|
85
|
-
`Config file: ${result.configPath}`,
|
|
86
|
-
`Owning entry: ${result.entryRepoPath}`,
|
|
87
|
-
`Target repository path: ${result.repoPath}`,
|
|
88
|
-
`Mode: ${result.mode}`,
|
|
89
|
-
`Scope: ${formatSetScope(result.scope)}`,
|
|
90
|
-
`Action: ${result.action}`,
|
|
91
|
-
];
|
|
92
|
-
|
|
93
|
-
return ensureTrailingNewline(lines.join("\n"));
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export const formatSyncPushResult = (result: SyncPushResult) => {
|
|
97
|
-
const lines = result.dryRun
|
|
98
|
-
? [
|
|
99
|
-
"Dry run for sync push.",
|
|
100
|
-
`Sync directory: ${result.syncDirectory}`,
|
|
101
|
-
`Config file: ${result.configPath}`,
|
|
102
|
-
`Summary: ${result.plainFileCount} plain files, ${result.encryptedFileCount} encrypted files, ${result.symlinkCount} symlinks, ${result.directoryCount} directory roots, ${result.deletedArtifactCount} stale repository artifacts would be removed.`,
|
|
103
|
-
"No filesystem changes were made.",
|
|
104
|
-
]
|
|
105
|
-
: [
|
|
106
|
-
"Synchronized local config into the sync repository.",
|
|
107
|
-
`Sync directory: ${result.syncDirectory}`,
|
|
108
|
-
`Config file: ${result.configPath}`,
|
|
109
|
-
`Summary: ${result.plainFileCount} plain files, ${result.encryptedFileCount} encrypted files, ${result.symlinkCount} symlinks, ${result.directoryCount} directory roots, ${result.deletedArtifactCount} stale repository artifacts removed.`,
|
|
110
|
-
];
|
|
111
|
-
|
|
112
|
-
return ensureTrailingNewline(lines.join("\n"));
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export const formatSyncPullResult = (result: SyncPullResult) => {
|
|
116
|
-
const lines = result.dryRun
|
|
117
|
-
? [
|
|
118
|
-
"Dry run for sync pull.",
|
|
119
|
-
`Sync directory: ${result.syncDirectory}`,
|
|
120
|
-
`Config file: ${result.configPath}`,
|
|
121
|
-
`Summary: ${result.plainFileCount} plain files, ${result.decryptedFileCount} decrypted files, ${result.symlinkCount} symlinks, ${result.directoryCount} directory roots, ${result.deletedLocalCount} local paths would be removed.`,
|
|
122
|
-
"No filesystem changes were made.",
|
|
123
|
-
]
|
|
124
|
-
: [
|
|
125
|
-
"Applied sync repository to local config.",
|
|
126
|
-
`Sync directory: ${result.syncDirectory}`,
|
|
127
|
-
`Config file: ${result.configPath}`,
|
|
128
|
-
`Summary: ${result.plainFileCount} plain files, ${result.decryptedFileCount} decrypted files, ${result.symlinkCount} symlinks, ${result.directoryCount} directory roots, ${result.deletedLocalCount} local paths removed.`,
|
|
129
|
-
];
|
|
130
|
-
|
|
131
|
-
return ensureTrailingNewline(lines.join("\n"));
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
export const formatSyncListResult = (result: SyncListResult) => {
|
|
135
|
-
const lines = [
|
|
136
|
-
"Tracked sync configuration.",
|
|
137
|
-
`Sync directory: ${result.syncDirectory}`,
|
|
138
|
-
`Config file: ${result.configPath}`,
|
|
139
|
-
`Summary: ${result.recipientCount} recipients, ${result.entries.length} entries, ${result.ruleCount} rules.`,
|
|
140
|
-
...(result.entries.length === 0
|
|
141
|
-
? ["Entries: none"]
|
|
142
|
-
: result.entries.flatMap((entry) => {
|
|
143
|
-
return [
|
|
144
|
-
`- ${entry.repoPath} [${entry.kind}, ${entry.mode}] -> ${entry.localPath}`,
|
|
145
|
-
...(entry.overrides.length === 0
|
|
146
|
-
? []
|
|
147
|
-
: entry.overrides.map((override) => {
|
|
148
|
-
return ` override ${override.selector}: ${override.mode}`;
|
|
149
|
-
})),
|
|
150
|
-
];
|
|
151
|
-
})),
|
|
152
|
-
];
|
|
153
|
-
|
|
154
|
-
return ensureTrailingNewline(lines.join("\n"));
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export const formatSyncStatusResult = (result: SyncStatusResult) => {
|
|
158
|
-
const lines = [
|
|
159
|
-
"Sync status overview.",
|
|
160
|
-
`Sync directory: ${result.syncDirectory}`,
|
|
161
|
-
`Config file: ${result.configPath}`,
|
|
162
|
-
`Summary: ${result.recipientCount} recipients, ${result.entryCount} entries, ${result.ruleCount} rules.`,
|
|
163
|
-
`Push plan: ${result.push.plainFileCount} plain files, ${result.push.encryptedFileCount} encrypted files, ${result.push.symlinkCount} symlinks, ${result.push.directoryCount} directory roots, ${result.push.deletedArtifactCount} stale repository artifacts.`,
|
|
164
|
-
...(result.push.preview.length === 0
|
|
165
|
-
? ["Push preview: no tracked paths"]
|
|
166
|
-
: [`Push preview: ${result.push.preview.join(", ")}`]),
|
|
167
|
-
`Pull plan: ${result.pull.plainFileCount} plain files, ${result.pull.decryptedFileCount} decrypted files, ${result.pull.symlinkCount} symlinks, ${result.pull.directoryCount} directory roots, ${result.pull.deletedLocalCount} local paths.`,
|
|
168
|
-
...(result.pull.preview.length === 0
|
|
169
|
-
? ["Pull preview: no tracked paths"]
|
|
170
|
-
: [`Pull preview: ${result.pull.preview.join(", ")}`]),
|
|
171
|
-
];
|
|
172
|
-
|
|
173
|
-
return ensureTrailingNewline(lines.join("\n"));
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
export const formatSyncDoctorResult = (result: SyncDoctorResult) => {
|
|
177
|
-
const counts = result.checks.reduce(
|
|
178
|
-
(accumulator, check) => {
|
|
179
|
-
accumulator[check.level] += 1;
|
|
180
|
-
|
|
181
|
-
return accumulator;
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
fail: 0,
|
|
185
|
-
ok: 0,
|
|
186
|
-
warn: 0,
|
|
187
|
-
},
|
|
188
|
-
);
|
|
189
|
-
const lines = [
|
|
190
|
-
result.hasFailures ? "Sync doctor found issues." : "Sync doctor passed.",
|
|
191
|
-
`Sync directory: ${result.syncDirectory}`,
|
|
192
|
-
`Config file: ${result.configPath}`,
|
|
193
|
-
`Summary: ${counts.ok} ok, ${counts.warn} warnings, ${counts.fail} failures.`,
|
|
194
|
-
...result.checks.map((check) => {
|
|
195
|
-
return `[${check.level.toUpperCase()}] ${check.name}: ${check.detail}`;
|
|
196
|
-
}),
|
|
197
|
-
];
|
|
198
|
-
|
|
199
|
-
return ensureTrailingNewline(lines.join("\n"));
|
|
200
|
-
};
|