@poli-page/cli 0.11.0 → 0.12.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/README.md +91 -30
- package/dist/api-client.d.ts +42 -2
- package/dist/api-client.d.ts.map +1 -1
- package/dist/api-client.js +117 -4
- package/dist/api-client.js.map +1 -1
- package/dist/cloud-context.d.ts +1 -1
- package/dist/cloud-context.js +1 -1
- package/dist/commands/clone.d.ts +32 -0
- package/dist/commands/clone.d.ts.map +1 -0
- package/dist/commands/clone.js +266 -0
- package/dist/commands/clone.js.map +1 -0
- package/dist/commands/dev.d.ts +55 -3
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +307 -46
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +8 -8
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/link.d.ts +9 -0
- package/dist/commands/link.d.ts.map +1 -1
- package/dist/commands/link.js +25 -10
- package/dist/commands/link.js.map +1 -1
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +1 -7
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/publish.js +1 -1
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/sync.d.ts +52 -0
- package/dist/commands/sync.d.ts.map +1 -0
- package/dist/commands/sync.js +224 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/credentials.d.ts +6 -1
- package/dist/credentials.d.ts.map +1 -1
- package/dist/credentials.js +28 -10
- package/dist/credentials.js.map +1 -1
- package/dist/dev-page.d.ts.map +1 -1
- package/dist/dev-page.js +24 -0
- package/dist/dev-page.js.map +1 -1
- package/dist/draft-bases.d.ts +54 -0
- package/dist/draft-bases.d.ts.map +1 -0
- package/dist/draft-bases.js +253 -0
- package/dist/draft-bases.js.map +1 -0
- package/dist/draft-files.d.ts +96 -0
- package/dist/draft-files.d.ts.map +1 -0
- package/dist/draft-files.js +447 -0
- package/dist/draft-files.js.map +1 -0
- package/dist/exit-codes.d.ts +3 -1
- package/dist/exit-codes.d.ts.map +1 -1
- package/dist/exit-codes.js +3 -1
- package/dist/exit-codes.js.map +1 -1
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +6 -3
- package/dist/program.js.map +1 -1
- package/dist/project-files.d.ts +8 -1
- package/dist/project-files.d.ts.map +1 -1
- package/dist/project-files.js +22 -1
- package/dist/project-files.js.map +1 -1
- package/dist/project-sync.d.ts +88 -16
- package/dist/project-sync.d.ts.map +1 -1
- package/dist/project-sync.js +283 -46
- package/dist/project-sync.js.map +1 -1
- package/dist/slug.d.ts +8 -0
- package/dist/slug.d.ts.map +1 -0
- package/dist/slug.js +15 -0
- package/dist/slug.js.map +1 -0
- package/dist/sync-engine.d.ts +14 -9
- package/dist/sync-engine.d.ts.map +1 -1
- package/dist/sync-engine.js +26 -29
- package/dist/sync-engine.js.map +1 -1
- package/package.json +1 -1
- package/dist/commands/watch.d.ts +0 -29
- package/dist/commands/watch.d.ts.map +0 -1
- package/dist/commands/watch.js +0 -108
- package/dist/commands/watch.js.map +0 -1
package/dist/program.js
CHANGED
|
@@ -8,8 +8,9 @@ import { registerLinkCommands } from './commands/link.js';
|
|
|
8
8
|
import { registerPublishCommand } from './commands/publish.js';
|
|
9
9
|
import { registerEnvCommands } from './commands/env.js';
|
|
10
10
|
import { registerDocumentsCommands } from './commands/documents/index.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { registerDevCommand, registerRemovedWatchCommand } from './commands/dev.js';
|
|
12
|
+
import { registerCloneCommand } from './commands/clone.js';
|
|
13
|
+
import { registerSyncCommand } from './commands/sync.js';
|
|
13
14
|
import { readCredentials } from './credentials.js';
|
|
14
15
|
import { readManifest } from './manifest.js';
|
|
15
16
|
import { apiOrigin, DEFAULT_API_URL, setLoginApiUrl } from './api-origin.js';
|
|
@@ -61,11 +62,13 @@ export function createProgram() {
|
|
|
61
62
|
registerRenderCommand(program);
|
|
62
63
|
registerAuthCommands(program);
|
|
63
64
|
registerLinkCommands(program);
|
|
65
|
+
registerCloneCommand(program);
|
|
64
66
|
registerPublishCommand(program);
|
|
65
67
|
registerEnvCommands(program);
|
|
66
68
|
registerDocumentsCommands(program);
|
|
67
|
-
registerWatchCommand(program);
|
|
68
69
|
registerDevCommand(program);
|
|
70
|
+
registerRemovedWatchCommand(program);
|
|
71
|
+
registerSyncCommand(program);
|
|
69
72
|
return program;
|
|
70
73
|
}
|
|
71
74
|
/**
|
package/dist/program.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.js","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"program.js","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,E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.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ProjectFileEntry } from './api-client.js';
|
|
2
2
|
/**
|
|
3
|
-
* The project file set, shared by the draft sync (`poli
|
|
3
|
+
* The project file set, shared by the draft sync (`poli dev`)
|
|
4
4
|
* and `poli publish`. It mirrors the API's classifier: a path outside it is
|
|
5
5
|
* refused with `400 UNSUPPORTED_FILE_TYPE`, which fails the whole request, so
|
|
6
6
|
* the CLI leaves such files out instead of sending them.
|
|
@@ -19,6 +19,13 @@ export declare const IMAGE_EXTENSIONS: ReadonlySet<string>;
|
|
|
19
19
|
/** A file path inside `assets/images/` or `assets/icons/`, accepted or not. */
|
|
20
20
|
export declare function isImageFolderPath(path: string): boolean;
|
|
21
21
|
export declare function isAcceptedProjectPath(path: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* A path every OS can write as given: no leading `/`, no backslash, no `:`, no
|
|
24
|
+
* empty, `.` or `..` segment, no segment ending in `.` or a space (Windows
|
|
25
|
+
* drops those), no Windows device name (`con`, `nul`, `com1`...) before the
|
|
26
|
+
* first dot of a segment. Server-supplied paths must pass it before a write.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isPortableProjectPath(path: string): boolean;
|
|
22
29
|
/**
|
|
23
30
|
* Everything under `assets/` (images, icons, fonts) is binary and travels as
|
|
24
31
|
* base64; the rest of the accepted set is text and travels as utf8.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-files.d.ts","sourceRoot":"","sources":["../src/project-files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGxD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,QAAoC,CAAC;AAGlE,wFAAwF;AACxF,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAO/C,CAAC;AAOH,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOvD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAkB3D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAE9E;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAElF;AAED,mEAAmE;AACnE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,gBAAgB,EAAE,CAInF"}
|
|
1
|
+
{"version":3,"file":"project-files.d.ts","sourceRoot":"","sources":["../src/project-files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGxD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,QAAoC,CAAC;AAGlE,wFAAwF;AACxF,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAO/C,CAAC;AAOH,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOvD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAkB3D;AAKD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAU3D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAE9E;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAElF;AAED,mEAAmE;AACnE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,gBAAgB,EAAE,CAInF"}
|
package/dist/project-files.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MANIFEST_FILENAME } from './constants.js';
|
|
2
2
|
/**
|
|
3
|
-
* The project file set, shared by the draft sync (`poli
|
|
3
|
+
* The project file set, shared by the draft sync (`poli dev`)
|
|
4
4
|
* and `poli publish`. It mirrors the API's classifier: a path outside it is
|
|
5
5
|
* refused with `400 UNSUPPORTED_FILE_TYPE`, which fails the whole request, so
|
|
6
6
|
* the CLI leaves such files out instead of sending them.
|
|
@@ -56,6 +56,27 @@ export function isAcceptedProjectPath(path) {
|
|
|
56
56
|
}
|
|
57
57
|
return false;
|
|
58
58
|
}
|
|
59
|
+
// Names Windows reserves for devices, whatever the extension after them.
|
|
60
|
+
const RESERVED_NAME_RE = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;
|
|
61
|
+
/**
|
|
62
|
+
* A path every OS can write as given: no leading `/`, no backslash, no `:`, no
|
|
63
|
+
* empty, `.` or `..` segment, no segment ending in `.` or a space (Windows
|
|
64
|
+
* drops those), no Windows device name (`con`, `nul`, `com1`...) before the
|
|
65
|
+
* first dot of a segment. Server-supplied paths must pass it before a write.
|
|
66
|
+
*/
|
|
67
|
+
export function isPortableProjectPath(path) {
|
|
68
|
+
if (path === '' || path.startsWith('/') || path.includes('\\') || path.includes(':')) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return path.split('/').every((segment) => {
|
|
72
|
+
if (segment === '' || segment === '.' || segment === '..')
|
|
73
|
+
return false;
|
|
74
|
+
if (segment.endsWith('.') || segment.endsWith(' '))
|
|
75
|
+
return false;
|
|
76
|
+
const dot = segment.indexOf('.');
|
|
77
|
+
return !RESERVED_NAME_RE.test(dot === -1 ? segment : segment.slice(0, dot));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
59
80
|
/**
|
|
60
81
|
* Everything under `assets/` (images, icons, fonts) is binary and travels as
|
|
61
82
|
* base64; the rest of the accepted set is text and travels as utf8.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{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U,oBAAoB,CAAC,KAA0B;IAC9D,OAAO,CAAC,GAAG,KAAK,CAAC;SACf,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAChD,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;AAC/D,CAAC"}
|
package/dist/project-sync.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { DraftConflictError, type ApiClient } from './api-client.js';
|
|
2
2
|
import type { CloudContext } from './cloud-context.js';
|
|
3
|
+
import { type Conflict } from './draft-files.js';
|
|
3
4
|
export declare const IGNORED_DIRECTORY_NAMES: Set<string>;
|
|
4
5
|
/**
|
|
5
6
|
* `true` when a segment of `relPath` names a directory the sync never
|
|
@@ -44,8 +45,19 @@ export declare function listProjectFiles(cwd: string): Promise<ProjectFileStat[]
|
|
|
44
45
|
* assets, utf-8 verbatim for everything else.
|
|
45
46
|
*/
|
|
46
47
|
export declare function readAllProjectFiles(cwd: string): Promise<Map<string, string>>;
|
|
48
|
+
/** Local project files the sync may send, with their byte hashes. */
|
|
49
|
+
export interface SyncableFiles {
|
|
50
|
+
/** Content as `readAllProjectFiles` encodes it. */
|
|
51
|
+
contents: Map<string, string>;
|
|
52
|
+
/** SHA-256 of each file's bytes. */
|
|
53
|
+
hashes: Map<string, string>;
|
|
54
|
+
/** Files of the set no OS-portable draft path can hold: never sent, never deleted. */
|
|
55
|
+
nonPortable: string[];
|
|
56
|
+
}
|
|
57
|
+
/** `readAllProjectFiles` split into what the sync may send and what it leaves alone. */
|
|
58
|
+
export declare function readSyncableFiles(cwd: string): Promise<SyncableFiles>;
|
|
47
59
|
export interface ProjectSyncOutcome {
|
|
48
|
-
/** `false` when
|
|
60
|
+
/** `false` when no local file changed since the stored bases. */
|
|
49
61
|
changed: boolean;
|
|
50
62
|
syncedAt?: string;
|
|
51
63
|
/** Project-relative POSIX paths touched by this sync (added + modified + deleted). */
|
|
@@ -56,28 +68,88 @@ export interface ProjectSyncerOptions {
|
|
|
56
68
|
client: ApiClient;
|
|
57
69
|
ctx: CloudContext;
|
|
58
70
|
signal?: AbortSignal;
|
|
71
|
+
/**
|
|
72
|
+
* Network failures one sync request may meet before the sync gives up
|
|
73
|
+
* (`syncWithRetry`'s `maxNetworkAttempts`). Absent: it retries until it
|
|
74
|
+
* gets through or `signal` aborts.
|
|
75
|
+
*/
|
|
76
|
+
maxNetworkAttempts?: number;
|
|
77
|
+
/** Where the base store lives (`~/.polipage`); tests point it elsewhere. */
|
|
78
|
+
homeDir?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Called once per file and syncer for a local file whose path no other OS
|
|
81
|
+
* could write: it is neither sent nor deleted. Defaults to a warning.
|
|
82
|
+
*/
|
|
83
|
+
onNonPortable?: (path: string) => void;
|
|
84
|
+
/**
|
|
85
|
+
* Called once per template and syncer whose html file was deleted here
|
|
86
|
+
* while its mock is still on disk: the deletion waits for the mock (the
|
|
87
|
+
* draft deletes both together). Defaults to a warning.
|
|
88
|
+
*/
|
|
89
|
+
onHeldBack?: (path: string, mock: string) => void;
|
|
59
90
|
}
|
|
60
91
|
/**
|
|
61
|
-
*
|
|
62
|
-
* `poli dev`.
|
|
92
|
+
* Local ⇄ cloud-draft synchroniser of `poli dev` (with or without the preview).
|
|
63
93
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
94
|
+
* Every file it sends carries a base from the store (`draft-bases.ts`): the
|
|
95
|
+
* server hash it last agreed on, or `null` for a file the draft must not
|
|
96
|
+
* have. The API refuses the whole sync (`409 DRAFT_CONFLICT`) when one base
|
|
97
|
+
* is stale, so another person's change in the draft is never overwritten.
|
|
98
|
+
* A folder with no bases is reconciled with the draft first; nothing is
|
|
99
|
+
* ever sent without them.
|
|
67
100
|
*/
|
|
68
101
|
export interface ProjectSyncer {
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Start-up: reconcile when the folder has no bases, then one sync of the
|
|
104
|
+
* files changed since the stored local hashes. Same contract as `sync()`.
|
|
105
|
+
*/
|
|
106
|
+
start(): Promise<ProjectSyncOutcome>;
|
|
107
|
+
/**
|
|
108
|
+
* Send the files changed since the stored local hashes, except the
|
|
109
|
+
* paths of unresolved conflicts, then store the answer's hashes. A
|
|
110
|
+
* refused sync writes nothing: its conflicts become pending (stored,
|
|
111
|
+
* paused) and a `SyncConflictError` is thrown. While the folder has
|
|
112
|
+
* pending conflicts, from this process or an earlier one, every sync
|
|
113
|
+
* sends the other files and then throws `SyncConflictError` listing them,
|
|
114
|
+
* with what it sent in `outcome`.
|
|
115
|
+
*/
|
|
74
116
|
sync(): Promise<ProjectSyncOutcome>;
|
|
117
|
+
/** Paths of the pending conflicts as of the last sync, sorted: left out until resolved. */
|
|
118
|
+
paused(): string[];
|
|
75
119
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* the local files rather than whatever the draft happened to hold.
|
|
120
|
+
* Puts paths back into the sync once `resolveConflicts` has resolved
|
|
121
|
+
* them; a path still pending in the store is paused again by the next sync.
|
|
79
122
|
*/
|
|
80
|
-
|
|
123
|
+
resume(paths: string[]): void;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* A sync that still has unresolved conflicts. Thrown in two cases, so none
|
|
127
|
+
* goes unreported:
|
|
128
|
+
*
|
|
129
|
+
* - the API refused the sync for conflicts it had not reported before:
|
|
130
|
+
* nothing was sent (`outcome.changed` is `false`), and the conflicts are
|
|
131
|
+
* now pending and paused, so the next sync sends every other change;
|
|
132
|
+
* - the folder already had pending conflicts: their paths were left out
|
|
133
|
+
* and every other change was sent (`outcome`).
|
|
134
|
+
*/
|
|
135
|
+
export declare class SyncConflictError extends DraftConflictError {
|
|
136
|
+
readonly outcome: ProjectSyncOutcome;
|
|
137
|
+
/** With `localSha256` (and `reconciled`), which the API's list does not carry. */
|
|
138
|
+
readonly conflicts: Conflict[];
|
|
139
|
+
constructor(conflicts: Conflict[], outcome: ProjectSyncOutcome);
|
|
81
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Conflicts nobody can answer here (no terminal): the paths, and the
|
|
143
|
+
* `poli sync` commands that settle them either way, with `--` before the
|
|
144
|
+
* paths so none is ever read as a flag. Exit code 7.
|
|
145
|
+
*/
|
|
146
|
+
export declare class UnresolvedConflictsError extends DraftConflictError {
|
|
147
|
+
constructor(conflicts: Conflict[]);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* A conflict on a file the draft has and this folder does not: keeping
|
|
151
|
+
* "mine" deletes it from the draft.
|
|
152
|
+
*/
|
|
153
|
+
export declare function isNotHere(conflict: Conflict): boolean;
|
|
82
154
|
export declare function createProjectSyncer(options: ProjectSyncerOptions): ProjectSyncer;
|
|
83
155
|
//# sourceMappingURL=project-sync.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-sync.d.ts","sourceRoot":"","sources":["../src/project-sync.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"project-sync.d.ts","sourceRoot":"","sources":["../src/project-sync.ts"],"names":[],"mappings":"AAGA,OAAO,EAEN,kBAAkB,EAClB,KAAK,SAAS,EAEd,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAUvD,OAAO,EAAmC,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAalF,eAAO,MAAM,uBAAuB,aAA+D,CAAC;AAEpG;;;;;GAKG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ises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { ApiError, DraftConflictError, } from './api-client.js';
|
|
4
5
|
import { MANIFEST_FILENAME } from './constants.js';
|
|
6
|
+
import { forgetBases, readBases, readPending, updateBases, } from './draft-bases.js';
|
|
7
|
+
import { reconcileDraft, settleConflicts } from './draft-files.js';
|
|
5
8
|
import { UsageError } from './exit-codes.js';
|
|
6
9
|
import { oneLine } from './output.js';
|
|
7
|
-
import { IMAGE_EXTENSIONS, isAcceptedProjectPath, isImageFolderPath, projectFileEncoding,
|
|
8
|
-
import {
|
|
10
|
+
import { IMAGE_EXTENSIONS, isAcceptedProjectPath, isImageFolderPath, isPortableProjectPath, projectFileEncoding, toProjectFileEntry, } from './project-files.js';
|
|
11
|
+
import { hashContent, syncWithRetry } from './sync-engine.js';
|
|
9
12
|
export const IGNORED_DIRECTORY_NAMES = new Set(['node_modules', '.git', 'output', 'dist', '.poli']);
|
|
10
13
|
/**
|
|
11
14
|
* `true` when a segment of `relPath` names a directory the sync never
|
|
@@ -36,9 +39,8 @@ export function shouldIgnoreProjectPath(relPath) {
|
|
|
36
39
|
return isJunkProjectPath(normalized) || !isAcceptedProjectPath(normalized);
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
39
|
-
* Absolute paths already named by `warnNotAnImage`: `poli
|
|
40
|
-
*
|
|
41
|
-
* each one once.
|
|
42
|
+
* Absolute paths already named by `warnNotAnImage`: `poli dev` lists the
|
|
43
|
+
* project on every sync, and the user needs to read each one once.
|
|
42
44
|
*/
|
|
43
45
|
const namedNotImages = new Set();
|
|
44
46
|
/**
|
|
@@ -190,60 +192,295 @@ export async function readAllProjectFiles(cwd) {
|
|
|
190
192
|
}
|
|
191
193
|
return out;
|
|
192
194
|
}
|
|
195
|
+
/** `readAllProjectFiles` split into what the sync may send and what it leaves alone. */
|
|
196
|
+
export async function readSyncableFiles(cwd) {
|
|
197
|
+
const contents = new Map();
|
|
198
|
+
const hashes = new Map();
|
|
199
|
+
const nonPortable = [];
|
|
200
|
+
for (const [path, content] of await readAllProjectFiles(cwd)) {
|
|
201
|
+
if (!isPortableProjectPath(path)) {
|
|
202
|
+
nonPortable.push(path);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
contents.set(path, content);
|
|
206
|
+
hashes.set(path, hashContent(toProjectFileEntry(path, content)));
|
|
207
|
+
}
|
|
208
|
+
return { contents, hashes, nonPortable };
|
|
209
|
+
}
|
|
210
|
+
/** Conflicts settled silently in a row before the sync gives up on retrying. */
|
|
211
|
+
const MAX_SETTLE_ROUNDS = 3;
|
|
212
|
+
/**
|
|
213
|
+
* A sync that still has unresolved conflicts. Thrown in two cases, so none
|
|
214
|
+
* goes unreported:
|
|
215
|
+
*
|
|
216
|
+
* - the API refused the sync for conflicts it had not reported before:
|
|
217
|
+
* nothing was sent (`outcome.changed` is `false`), and the conflicts are
|
|
218
|
+
* now pending and paused, so the next sync sends every other change;
|
|
219
|
+
* - the folder already had pending conflicts: their paths were left out
|
|
220
|
+
* and every other change was sent (`outcome`).
|
|
221
|
+
*/
|
|
222
|
+
export class SyncConflictError extends DraftConflictError {
|
|
223
|
+
outcome;
|
|
224
|
+
/** With `localSha256` (and `reconciled`), which the API's list does not carry. */
|
|
225
|
+
conflicts;
|
|
226
|
+
constructor(conflicts, outcome) {
|
|
227
|
+
super(`${conflicts.length} file(s) changed in the cloud draft since the last sync.`, undefined, { error: 'DRAFT_CONFLICT', conflicts });
|
|
228
|
+
this.outcome = outcome;
|
|
229
|
+
this.conflicts = conflicts;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/** `path` as one shell word: quoted when the shell would split or expand it. */
|
|
233
|
+
function shellWord(path) {
|
|
234
|
+
return /^[\w./@+-]+$/.test(path) ? path : `'${path.replace(/'/g, `'\\''`)}'`;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Conflicts nobody can answer here (no terminal): the paths, and the
|
|
238
|
+
* `poli sync` commands that settle them either way, with `--` before the
|
|
239
|
+
* paths so none is ever read as a flag. Exit code 7.
|
|
240
|
+
*/
|
|
241
|
+
export class UnresolvedConflictsError extends DraftConflictError {
|
|
242
|
+
constructor(conflicts) {
|
|
243
|
+
// Server-supplied paths: one line each, no control character.
|
|
244
|
+
const paths = conflicts.map((c) => oneLine(c.path));
|
|
245
|
+
const words = paths.map(shellWord).join(' ');
|
|
246
|
+
// A reconciliation cannot tell which side changed a file.
|
|
247
|
+
const header = conflicts.some((c) => c.reconciled)
|
|
248
|
+
? `${paths.length} file(s) differ from the cloud draft:`
|
|
249
|
+
: `${paths.length} file(s) changed both here and in the cloud draft since the last sync:`;
|
|
250
|
+
super([
|
|
251
|
+
header,
|
|
252
|
+
...conflicts.map((c, i) => isNotHere(c)
|
|
253
|
+
? ` ${paths[i]} (not in this folder: keep-mine deletes it from the draft)`
|
|
254
|
+
: ` ${paths[i]}`),
|
|
255
|
+
'Keep your version:',
|
|
256
|
+
` poli sync --keep-mine -- ${words}`,
|
|
257
|
+
"Or take the cloud's:",
|
|
258
|
+
` poli sync --take-theirs -- ${words}`,
|
|
259
|
+
].join('\n'), undefined, { error: 'DRAFT_CONFLICT', conflicts });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function byPath(a, b) {
|
|
263
|
+
return a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* A conflict on a file the draft has and this folder does not: keeping
|
|
267
|
+
* "mine" deletes it from the draft.
|
|
268
|
+
*/
|
|
269
|
+
export function isNotHere(conflict) {
|
|
270
|
+
return conflict.localSha256 === null && conflict.remoteSha256 !== null;
|
|
271
|
+
}
|
|
272
|
+
/** Pending conflicts as reported, each with the local file's hash now (`null`: not here). */
|
|
273
|
+
function asConflicts(pending, local) {
|
|
274
|
+
return pending
|
|
275
|
+
.map(({ path, remoteSha256, reconciled }) => ({
|
|
276
|
+
path,
|
|
277
|
+
remoteSha256,
|
|
278
|
+
localSha256: local.hashes.get(path) ?? null,
|
|
279
|
+
...(reconciled ? { reconciled } : {}),
|
|
280
|
+
}))
|
|
281
|
+
.sort(byPath);
|
|
282
|
+
}
|
|
283
|
+
/** `templates/{slug}/{slug}.html`: the API deletes `{slug}.json` with it. */
|
|
284
|
+
const TEMPLATE_HTML_RE = /^templates\/([^/]+)\/([^/]+)\.html$/;
|
|
285
|
+
function mockOfTemplate(path) {
|
|
286
|
+
const match = TEMPLATE_HTML_RE.exec(path);
|
|
287
|
+
return match && match[1] === match[2] ? `templates/${match[1]}/${match[1]}.json` : null;
|
|
288
|
+
}
|
|
193
289
|
export function createProjectSyncer(options) {
|
|
194
|
-
|
|
195
|
-
|
|
290
|
+
const { cwd, client, ctx, homeDir } = options;
|
|
291
|
+
let pausedPaths = new Set();
|
|
292
|
+
const namedNonPortable = new Set();
|
|
293
|
+
const namedHeldBack = new Set();
|
|
294
|
+
const onHeldBack = options.onHeldBack ??
|
|
295
|
+
((path, mock) => console.warn(`⚠ ${oneLine(path)} stays in the draft while ${oneLine(mock)} exists; ` +
|
|
296
|
+
'delete both to remove the template.'));
|
|
297
|
+
const onNonPortable = options.onNonPortable ??
|
|
298
|
+
((path) => console.warn(`⚠ ${oneLine(path)} has a name some systems cannot hold; it is left out of the sync. ` +
|
|
299
|
+
'Rename it to sync it.'));
|
|
300
|
+
/**
|
|
301
|
+
* The stored bases and pending conflicts; a folder with none is
|
|
302
|
+
* reconciled first. Pending paths are paused.
|
|
303
|
+
*/
|
|
304
|
+
async function loadBases() {
|
|
305
|
+
let bases = await readBases(cwd, ctx.projectId, homeDir);
|
|
306
|
+
if (!bases) {
|
|
307
|
+
await reconcileDraft(ctx, cwd, client, homeDir);
|
|
308
|
+
bases = await readBases(cwd, ctx.projectId, homeDir);
|
|
309
|
+
// `reconcileDraft` has just written them: gone means another process
|
|
310
|
+
// forgot them meanwhile. Never send without bases.
|
|
311
|
+
if (!bases)
|
|
312
|
+
throw new Error('The draft bases of this folder could not be recorded.');
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
await refreshPending();
|
|
316
|
+
}
|
|
317
|
+
const pending = (await readPending(cwd, ctx.projectId, homeDir)) ?? [];
|
|
318
|
+
pausedPaths = new Set(pending.map((p) => p.path));
|
|
319
|
+
return { bases, pending };
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* A pending path is never sent, so no 409 tells how it stands now: list
|
|
323
|
+
* the draft (once, only when there are pending conflicts), settle the
|
|
324
|
+
* ones that no longer are (same bytes, same manifest, gone on both
|
|
325
|
+
* sides), and store the draft's current hash for the others, so the
|
|
326
|
+
* conflict reported is the one a resolution will meet.
|
|
327
|
+
*/
|
|
328
|
+
async function refreshPending() {
|
|
329
|
+
const stored = (await readPending(cwd, ctx.projectId, homeDir)) ?? [];
|
|
330
|
+
if (stored.length === 0)
|
|
331
|
+
return;
|
|
332
|
+
const listing = await client.listDraftFiles(ctx.session, ctx.orgId, ctx.projectId);
|
|
333
|
+
const remote = new Map(listing.map((f) => [f.path, f.sha256]));
|
|
334
|
+
const current = stored.map((p) => ({ ...p, remoteSha256: remote.get(p.path) ?? null }));
|
|
335
|
+
const local = await readSyncableFiles(cwd);
|
|
336
|
+
const left = new Set((await settleConflicts(ctx, cwd, client, current, local, homeDir)).map((c) => c.path));
|
|
337
|
+
const moved = current.filter((p, i) => left.has(p.path) && p.remoteSha256 !== stored[i].remoteSha256);
|
|
338
|
+
if (moved.length > 0) {
|
|
339
|
+
await updateBases(cwd, ctx.projectId, { addPending: moved }, homeDir);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/** One request: what changed since `bases`, minus paused paths. */
|
|
343
|
+
async function syncOnce(bases, local) {
|
|
344
|
+
const body = { added: [], modified: [], deleted: [] };
|
|
345
|
+
const sentHashes = new Map();
|
|
346
|
+
for (const [path, hash] of local.hashes) {
|
|
347
|
+
if (pausedPaths.has(path))
|
|
348
|
+
continue;
|
|
349
|
+
const base = bases[path];
|
|
350
|
+
if (base && base.local === hash)
|
|
351
|
+
continue;
|
|
352
|
+
const entry = {
|
|
353
|
+
...toProjectFileEntry(path, local.contents.get(path)),
|
|
354
|
+
baseSha256: base ? base.server : null,
|
|
355
|
+
};
|
|
356
|
+
(base ? body.modified : body.added).push(entry);
|
|
357
|
+
sentHashes.set(path, hash);
|
|
358
|
+
}
|
|
359
|
+
const nonPortable = new Set(local.nonPortable);
|
|
360
|
+
const deletions = new Map();
|
|
361
|
+
for (const path of Object.keys(bases)) {
|
|
362
|
+
if (local.hashes.has(path) || nonPortable.has(path) || pausedPaths.has(path))
|
|
363
|
+
continue;
|
|
364
|
+
deletions.set(path, bases[path].server);
|
|
365
|
+
}
|
|
366
|
+
// Deleting a template deletes its mock in the draft too, so the pair
|
|
367
|
+
// goes together: the mock with its own base (a mock someone else
|
|
368
|
+
// changed is a conflict, not a silent loss), or `null` when this
|
|
369
|
+
// folder never had one (a no-op on a draft without it). The
|
|
370
|
+
// template's deletion waits while its mock is still on disk (deleting
|
|
371
|
+
// it would drop the mock from the draft, only for the next sync to
|
|
372
|
+
// upload it again) or paused.
|
|
373
|
+
for (const path of [...deletions.keys()]) {
|
|
374
|
+
const mock = mockOfTemplate(path);
|
|
375
|
+
if (!mock || deletions.has(mock))
|
|
376
|
+
continue;
|
|
377
|
+
if (local.hashes.has(mock) || nonPortable.has(mock)) {
|
|
378
|
+
deletions.delete(path);
|
|
379
|
+
if (!namedHeldBack.has(path)) {
|
|
380
|
+
namedHeldBack.add(path);
|
|
381
|
+
onHeldBack(path, mock);
|
|
382
|
+
}
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if (pausedPaths.has(mock)) {
|
|
386
|
+
// Reported as a conflict already.
|
|
387
|
+
deletions.delete(path);
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
deletions.set(mock, null);
|
|
391
|
+
}
|
|
392
|
+
body.deleted = [...deletions]
|
|
393
|
+
.map(([path, baseSha256]) => ({ path, baseSha256 }))
|
|
394
|
+
.sort(byPath);
|
|
395
|
+
body.added.sort(byPath);
|
|
396
|
+
body.modified.sort(byPath);
|
|
397
|
+
if (body.added.length === 0 && body.modified.length === 0 && body.deleted.length === 0) {
|
|
398
|
+
return { changed: false, changedPaths: [] };
|
|
399
|
+
}
|
|
196
400
|
const result = await syncWithRetry({
|
|
197
|
-
syncFn: () =>
|
|
401
|
+
syncFn: () => client.patchFiles(ctx.session, ctx.orgId, ctx.projectId, body),
|
|
198
402
|
signal: options.signal,
|
|
403
|
+
maxNetworkAttempts: options.maxNetworkAttempts,
|
|
199
404
|
});
|
|
200
|
-
|
|
405
|
+
const deleted = body.deleted.map((d) => (typeof d === 'string' ? d : d.path));
|
|
406
|
+
const answered = new Map(result.files.map((f) => [f.path, f.sha256]));
|
|
407
|
+
if ([...sentHashes.keys()].some((path) => !answered.has(path))) {
|
|
408
|
+
// An API from before the bases answers no hashes: guessing them
|
|
409
|
+
// would turn a later change of someone else into an overwrite.
|
|
410
|
+
// Without bases, the next sync reconciles.
|
|
411
|
+
await forgetBases(cwd, ctx.projectId, homeDir);
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
const set = {};
|
|
415
|
+
for (const [path, hash] of sentHashes) {
|
|
416
|
+
set[path] = { server: answered.get(path), local: hash };
|
|
417
|
+
}
|
|
418
|
+
await updateBases(cwd, ctx.projectId, { set, remove: deleted }, homeDir);
|
|
419
|
+
}
|
|
201
420
|
return {
|
|
202
421
|
changed: true,
|
|
203
422
|
syncedAt: result.syncedAt,
|
|
204
|
-
changedPaths: [
|
|
205
|
-
...body.added.map((e) => e.path),
|
|
206
|
-
...body.modified.map((e) => e.path),
|
|
207
|
-
...body.deleted,
|
|
208
|
-
],
|
|
423
|
+
changedPaths: [...sentHashes.keys(), ...deleted],
|
|
209
424
|
};
|
|
210
425
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
426
|
+
async function sync() {
|
|
427
|
+
let { bases, pending } = await loadBases();
|
|
428
|
+
for (let round = 1;; round++) {
|
|
429
|
+
const local = await readSyncableFiles(cwd);
|
|
430
|
+
for (const path of local.nonPortable) {
|
|
431
|
+
if (namedNonPortable.has(path))
|
|
432
|
+
continue;
|
|
433
|
+
namedNonPortable.add(path);
|
|
434
|
+
onNonPortable(path);
|
|
220
435
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
async sync() {
|
|
225
|
-
const newFiles = await readAllProjectFiles(options.cwd);
|
|
226
|
-
const delta = computeDelta(hashes, newFiles);
|
|
227
|
-
if (delta.added.length === 0 &&
|
|
228
|
-
delta.modified.length === 0 &&
|
|
229
|
-
delta.deleted.length === 0) {
|
|
230
|
-
hashes = delta.newHashes;
|
|
231
|
-
return { changed: false, changedPaths: [] };
|
|
436
|
+
let outcome;
|
|
437
|
+
try {
|
|
438
|
+
outcome = await syncOnce(bases, local);
|
|
232
439
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
440
|
+
catch (err) {
|
|
441
|
+
if (!(err instanceof DraftConflictError))
|
|
442
|
+
throw err;
|
|
443
|
+
const left = await settleConflicts(ctx, cwd, client, err.conflicts, local, homeDir);
|
|
444
|
+
if (left.length > 0) {
|
|
445
|
+
const added = left.map(({ path, remoteSha256 }) => ({
|
|
446
|
+
path,
|
|
447
|
+
remoteSha256,
|
|
448
|
+
localSha256: local.hashes.get(path) ?? null,
|
|
449
|
+
}));
|
|
450
|
+
await updateBases(cwd, ctx.projectId, { addPending: added }, homeDir);
|
|
451
|
+
for (const { path } of left)
|
|
452
|
+
pausedPaths.add(path);
|
|
453
|
+
const reported = new Map([...asConflicts(pending, local), ...added].map((c) => [c.path, c]));
|
|
454
|
+
throw new SyncConflictError([...reported.values()].sort(byPath), {
|
|
455
|
+
changed: false,
|
|
456
|
+
changedPaths: [],
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
if (round === MAX_SETTLE_ROUNDS) {
|
|
460
|
+
// Each conflict settled (the draft held this folder's own
|
|
461
|
+
// bytes), yet the draft kept moving: not a conflict to ask about.
|
|
462
|
+
throw new ApiError('DRAFT_BUSY', 409, 'The cloud draft kept changing during the sync. Try again.');
|
|
463
|
+
}
|
|
464
|
+
// Each conflict was this folder's own change already in the
|
|
465
|
+
// draft (a sync whose answer was lost): send the rest now.
|
|
466
|
+
({ bases, pending } = await loadBases());
|
|
467
|
+
continue;
|
|
240
468
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
hashes = newHashes;
|
|
244
|
-
return { changed: false, changedPaths: [] };
|
|
469
|
+
if (pending.length > 0) {
|
|
470
|
+
throw new SyncConflictError(asConflicts(pending, local), outcome);
|
|
245
471
|
}
|
|
246
|
-
return
|
|
472
|
+
return outcome;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return {
|
|
476
|
+
start: sync,
|
|
477
|
+
sync,
|
|
478
|
+
paused() {
|
|
479
|
+
return [...pausedPaths].sort();
|
|
480
|
+
},
|
|
481
|
+
resume(paths) {
|
|
482
|
+
for (const path of paths)
|
|
483
|
+
pausedPaths.delete(path);
|
|
247
484
|
},
|
|
248
485
|
};
|
|
249
486
|
}
|