@iwonz/ywtc 0.0.0 → 2.0.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/.env.example +4 -0
- package/CHANGELOG.md +39 -0
- package/LICENSE +21 -0
- package/README.md +258 -1
- package/dist/adapters/confluence.d.ts +46 -0
- package/dist/adapters/confluence.js +187 -0
- package/dist/adapters/confluence.js.map +1 -0
- package/dist/adapters/factory.d.ts +3 -0
- package/dist/adapters/factory.js +11 -0
- package/dist/adapters/factory.js.map +1 -0
- package/dist/adapters/yandex.d.ts +45 -0
- package/dist/adapters/yandex.js +233 -0
- package/dist/adapters/yandex.js.map +1 -0
- package/dist/cli-arguments.d.ts +41 -0
- package/dist/cli-arguments.js +149 -0
- package/dist/cli-arguments.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +180 -0
- package/dist/cli.js.map +1 -0
- package/dist/clients/confluence-cloud.d.ts +45 -0
- package/dist/clients/confluence-cloud.js +261 -0
- package/dist/clients/confluence-cloud.js.map +1 -0
- package/dist/clients/confluence-factory.d.ts +3 -0
- package/dist/clients/confluence-factory.js +8 -0
- package/dist/clients/confluence-factory.js.map +1 -0
- package/dist/clients/confluence.d.ts +42 -0
- package/dist/clients/confluence.js +286 -0
- package/dist/clients/confluence.js.map +1 -0
- package/dist/clients/yandex-wiki.d.ts +35 -0
- package/dist/clients/yandex-wiki.js +255 -0
- package/dist/clients/yandex-wiki.js.map +1 -0
- package/dist/config.d.ts +52 -0
- package/dist/config.js +177 -0
- package/dist/config.js.map +1 -0
- package/dist/content-model.d.ts +12 -0
- package/dist/content-model.js +416 -0
- package/dist/content-model.js.map +1 -0
- package/dist/conversion.d.ts +43 -0
- package/dist/conversion.js +450 -0
- package/dist/conversion.js.map +1 -0
- package/dist/doctor.d.ts +24 -0
- package/dist/doctor.js +45 -0
- package/dist/doctor.js.map +1 -0
- package/dist/domain.d.ts +202 -0
- package/dist/domain.js +18 -0
- package/dist/domain.js.map +1 -0
- package/dist/filesystem-export.d.ts +53 -0
- package/dist/filesystem-export.js +243 -0
- package/dist/filesystem-export.js.map +1 -0
- package/dist/graph.d.ts +13 -0
- package/dist/graph.js +121 -0
- package/dist/graph.js.map +1 -0
- package/dist/http.d.ts +26 -0
- package/dist/http.js +100 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/input.d.ts +4 -0
- package/dist/input.js +56 -0
- package/dist/input.js.map +1 -0
- package/dist/locators.d.ts +24 -0
- package/dist/locators.js +84 -0
- package/dist/locators.js.map +1 -0
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +28 -0
- package/dist/logger.js.map +1 -0
- package/dist/migrator.d.ts +53 -0
- package/dist/migrator.js +669 -0
- package/dist/migrator.js.map +1 -0
- package/dist/rate-limiter.d.ts +12 -0
- package/dist/rate-limiter.js +31 -0
- package/dist/rate-limiter.js.map +1 -0
- package/dist/report.d.ts +101 -0
- package/dist/report.js +106 -0
- package/dist/report.js.map +1 -0
- package/dist/state.d.ts +119 -0
- package/dist/state.js +201 -0
- package/dist/state.js.map +1 -0
- package/dist/types.d.ts +197 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/updater.d.ts +24 -0
- package/dist/updater.js +92 -0
- package/dist/updater.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +8 -0
- package/dist/version.js.map +1 -0
- package/dist/workspace.d.ts +29 -0
- package/dist/workspace.js +157 -0
- package/dist/workspace.js.map +1 -0
- package/docs/assets/readme-header.png +0 -0
- package/package.json +108 -3
- package/ywtc.config.example.yaml +52 -0
package/dist/domain.d.ts
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import type { ConnectionProfile } from './config.js';
|
|
2
|
+
export type ProviderKind = 'yandex-wiki' | 'confluence';
|
|
3
|
+
export type TransferScope = 'page' | 'subtree' | 'linked';
|
|
4
|
+
export type ExportFormat = 'markdown' | 'html';
|
|
5
|
+
export type RawContentFormat = 'yfm' | 'confluence-storage';
|
|
6
|
+
export interface PageReference {
|
|
7
|
+
raw: string;
|
|
8
|
+
href?: string;
|
|
9
|
+
pageTitle?: string;
|
|
10
|
+
anchor?: string;
|
|
11
|
+
kind: 'page' | 'attachment' | 'anchor' | 'external' | 'unsupported';
|
|
12
|
+
}
|
|
13
|
+
export interface SourcePage {
|
|
14
|
+
provider: ProviderKind;
|
|
15
|
+
profile: string;
|
|
16
|
+
id: string;
|
|
17
|
+
canonicalId: string;
|
|
18
|
+
title: string;
|
|
19
|
+
locator: string;
|
|
20
|
+
url: string;
|
|
21
|
+
parentId?: string;
|
|
22
|
+
space?: string;
|
|
23
|
+
rawContent: string;
|
|
24
|
+
rawFormat: RawContentFormat;
|
|
25
|
+
modifiedAt?: string;
|
|
26
|
+
version?: string;
|
|
27
|
+
references: PageReference[];
|
|
28
|
+
}
|
|
29
|
+
export interface SourceResource {
|
|
30
|
+
provider: ProviderKind;
|
|
31
|
+
id: string;
|
|
32
|
+
pageId: string;
|
|
33
|
+
name: string;
|
|
34
|
+
size?: number;
|
|
35
|
+
mimeType?: string;
|
|
36
|
+
downloadUrl?: string;
|
|
37
|
+
kind: 'attachment' | 'image' | 'grid';
|
|
38
|
+
metadata?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
export interface DestinationContainer {
|
|
41
|
+
provider: ProviderKind;
|
|
42
|
+
profile: string;
|
|
43
|
+
id: string;
|
|
44
|
+
canonicalId: string;
|
|
45
|
+
title: string;
|
|
46
|
+
url: string;
|
|
47
|
+
space?: string;
|
|
48
|
+
locator?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface DestinationPage {
|
|
51
|
+
provider: ProviderKind;
|
|
52
|
+
profile: string;
|
|
53
|
+
id: string;
|
|
54
|
+
canonicalId: string;
|
|
55
|
+
title: string;
|
|
56
|
+
url: string;
|
|
57
|
+
locator?: string;
|
|
58
|
+
space?: string;
|
|
59
|
+
version?: string;
|
|
60
|
+
fingerprint?: string;
|
|
61
|
+
contentLength?: number;
|
|
62
|
+
}
|
|
63
|
+
export interface UploadedResource {
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
url?: string;
|
|
67
|
+
size?: number;
|
|
68
|
+
fingerprint?: string;
|
|
69
|
+
}
|
|
70
|
+
export interface AdapterCapabilities {
|
|
71
|
+
readPages: boolean;
|
|
72
|
+
readHierarchy: boolean;
|
|
73
|
+
readResources: boolean;
|
|
74
|
+
writePages: boolean;
|
|
75
|
+
writeResources: boolean;
|
|
76
|
+
verifyWrites: boolean;
|
|
77
|
+
}
|
|
78
|
+
export interface SourceAdapter {
|
|
79
|
+
readonly profile: ConnectionProfile;
|
|
80
|
+
readonly kind: ProviderKind;
|
|
81
|
+
readonly capabilities: AdapterCapabilities;
|
|
82
|
+
preflight(): Promise<{
|
|
83
|
+
product: string;
|
|
84
|
+
version?: string;
|
|
85
|
+
warnings: string[];
|
|
86
|
+
}>;
|
|
87
|
+
resolvePage(locator: string): Promise<SourcePage>;
|
|
88
|
+
getPage(id: string): Promise<SourcePage>;
|
|
89
|
+
getDescendants(page: SourcePage): Promise<SourcePage[]>;
|
|
90
|
+
resolveReference(from: SourcePage, reference: PageReference): Promise<SourcePage | undefined>;
|
|
91
|
+
listResources(page: SourcePage): Promise<SourceResource[]>;
|
|
92
|
+
downloadResource(resource: SourceResource, destination: string): Promise<{
|
|
93
|
+
path: string;
|
|
94
|
+
size: number;
|
|
95
|
+
sha256: string;
|
|
96
|
+
mimeType?: string;
|
|
97
|
+
}>;
|
|
98
|
+
}
|
|
99
|
+
export interface DestinationAdapter {
|
|
100
|
+
readonly profile: ConnectionProfile;
|
|
101
|
+
readonly kind: ProviderKind;
|
|
102
|
+
readonly capabilities: AdapterCapabilities;
|
|
103
|
+
preflight(): Promise<{
|
|
104
|
+
product: string;
|
|
105
|
+
version?: string;
|
|
106
|
+
warnings: string[];
|
|
107
|
+
}>;
|
|
108
|
+
resolveContainer(locator: string): Promise<DestinationContainer>;
|
|
109
|
+
findChild(container: DestinationContainer | DestinationPage, title: string): Promise<DestinationPage | undefined>;
|
|
110
|
+
createPage(input: {
|
|
111
|
+
container: DestinationContainer | DestinationPage;
|
|
112
|
+
title: string;
|
|
113
|
+
body: string;
|
|
114
|
+
}): Promise<DestinationPage>;
|
|
115
|
+
updatePage(input: {
|
|
116
|
+
page: DestinationPage;
|
|
117
|
+
title: string;
|
|
118
|
+
body: string;
|
|
119
|
+
expectedFingerprint?: string;
|
|
120
|
+
}): Promise<DestinationPage>;
|
|
121
|
+
uploadResource(input: {
|
|
122
|
+
page: DestinationPage;
|
|
123
|
+
name: string;
|
|
124
|
+
filePath: string;
|
|
125
|
+
size?: number;
|
|
126
|
+
mimeType?: string;
|
|
127
|
+
existingId?: string;
|
|
128
|
+
}): Promise<UploadedResource>;
|
|
129
|
+
listUploadedResources(page: DestinationPage): Promise<UploadedResource[]>;
|
|
130
|
+
verifyPage(page: DestinationPage): Promise<DestinationPage>;
|
|
131
|
+
renderPageReference(page: DestinationPage, label: string, anchor?: string): string;
|
|
132
|
+
renderResourceReference(resource: UploadedResource, label: string, image: boolean): string;
|
|
133
|
+
}
|
|
134
|
+
export type GraphEdgeStatus = 'resolved' | 'external' | 'inaccessible' | 'broken' | 'cycle' | 'unsupported';
|
|
135
|
+
export interface PageGraphEdge {
|
|
136
|
+
from: string;
|
|
137
|
+
raw: string;
|
|
138
|
+
to?: string;
|
|
139
|
+
status: GraphEdgeStatus;
|
|
140
|
+
message?: string;
|
|
141
|
+
}
|
|
142
|
+
export interface DiscoveredPage extends SourcePage {
|
|
143
|
+
depth: number;
|
|
144
|
+
projectedParentId?: string;
|
|
145
|
+
}
|
|
146
|
+
export interface PageGraph {
|
|
147
|
+
rootId: string;
|
|
148
|
+
pages: DiscoveredPage[];
|
|
149
|
+
edges: PageGraphEdge[];
|
|
150
|
+
warnings: string[];
|
|
151
|
+
}
|
|
152
|
+
export interface NormalizedReference {
|
|
153
|
+
token: string;
|
|
154
|
+
kind: PageReference['kind'];
|
|
155
|
+
raw: string;
|
|
156
|
+
href?: string;
|
|
157
|
+
pageId?: string;
|
|
158
|
+
resourceName?: string;
|
|
159
|
+
label: string;
|
|
160
|
+
anchor?: string;
|
|
161
|
+
}
|
|
162
|
+
export interface NormalizedNode {
|
|
163
|
+
type: 'document' | 'html' | 'page-reference' | 'resource-reference' | 'vendor-extension' | 'fallback';
|
|
164
|
+
value?: string;
|
|
165
|
+
children?: NormalizedNode[];
|
|
166
|
+
reference?: NormalizedReference;
|
|
167
|
+
vendor?: ProviderKind;
|
|
168
|
+
}
|
|
169
|
+
export interface NormalizedDocument {
|
|
170
|
+
root: NormalizedNode;
|
|
171
|
+
raw: string;
|
|
172
|
+
rawFormat: RawContentFormat;
|
|
173
|
+
references: NormalizedReference[];
|
|
174
|
+
warnings: string[];
|
|
175
|
+
degraded: boolean;
|
|
176
|
+
metrics: {
|
|
177
|
+
links: number;
|
|
178
|
+
images: number;
|
|
179
|
+
tables: number;
|
|
180
|
+
codeBlocks: number;
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
export interface RenderContext {
|
|
184
|
+
pages: Map<string, DestinationPage | {
|
|
185
|
+
path: string;
|
|
186
|
+
title: string;
|
|
187
|
+
}>;
|
|
188
|
+
resources: Map<string, UploadedResource | {
|
|
189
|
+
path: string;
|
|
190
|
+
name: string;
|
|
191
|
+
}>;
|
|
192
|
+
sourcePages: Map<string, SourcePage>;
|
|
193
|
+
currentPageId: string;
|
|
194
|
+
currentPath?: string;
|
|
195
|
+
}
|
|
196
|
+
export interface RenderedDocument {
|
|
197
|
+
body: string;
|
|
198
|
+
warnings: string[];
|
|
199
|
+
degraded: boolean;
|
|
200
|
+
representedReferences: number;
|
|
201
|
+
}
|
|
202
|
+
export declare function assertTransferCapabilities(source: SourceAdapter, destination: DestinationAdapter | undefined, scope: TransferScope): void;
|
package/dist/domain.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function assertTransferCapabilities(source, destination, scope) {
|
|
2
|
+
const missing = [];
|
|
3
|
+
if (!source.capabilities.readPages)
|
|
4
|
+
missing.push(`${source.profile.name}: read pages`);
|
|
5
|
+
if (scope !== 'page' && !source.capabilities.readHierarchy)
|
|
6
|
+
missing.push(`${source.profile.name}: read hierarchy`);
|
|
7
|
+
if (!source.capabilities.readResources)
|
|
8
|
+
missing.push(`${source.profile.name}: read resources`);
|
|
9
|
+
if (destination && !destination.capabilities.writePages)
|
|
10
|
+
missing.push(`${destination.profile.name}: write pages`);
|
|
11
|
+
if (destination && !destination.capabilities.writeResources)
|
|
12
|
+
missing.push(`${destination.profile.name}: write resources`);
|
|
13
|
+
if (destination && !destination.capabilities.verifyWrites)
|
|
14
|
+
missing.push(`${destination.profile.name}: verify writes`);
|
|
15
|
+
if (missing.length > 0)
|
|
16
|
+
throw new Error(`Selected direction lacks required capabilities: ${missing.join(', ')}.`);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=domain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain.js","sourceRoot":"","sources":["../src/domain.ts"],"names":[],"mappings":"AAiMA,MAAM,UAAU,0BAA0B,CACxC,MAAqB,EACrB,WAA2C,EAC3C,KAAoB;IAEpB,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS;QAAE,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,cAAc,CAAC,CAAC;IACvF,IAAI,KAAK,KAAK,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,aAAa;QAAE,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,kBAAkB,CAAC,CAAC;IACnH,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,aAAa;QAAE,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,kBAAkB,CAAC,CAAC;IAC/F,IAAI,WAAW,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU;QAAE,OAAO,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,eAAe,CAAC,CAAC;IAClH,IAAI,WAAW,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,cAAc;QAAE,OAAO,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,mBAAmB,CAAC,CAAC;IAC1H,IAAI,WAAW,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,YAAY;QAAE,OAAO,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,iBAAiB,CAAC,CAAC;IACtH,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpH,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { normalizePageContent } from './content-model.js';
|
|
2
|
+
import type { ExportFormat, PageGraph, SourceAdapter, SourcePage, SourceResource } from './domain.js';
|
|
3
|
+
export interface ExportManifestPage {
|
|
4
|
+
sourceCanonicalId: string;
|
|
5
|
+
sourceUrl: string;
|
|
6
|
+
title: string;
|
|
7
|
+
path: string;
|
|
8
|
+
parentId?: string;
|
|
9
|
+
resources: Array<{
|
|
10
|
+
name: string;
|
|
11
|
+
path: string;
|
|
12
|
+
size?: number;
|
|
13
|
+
sha256?: string;
|
|
14
|
+
}>;
|
|
15
|
+
degraded: boolean;
|
|
16
|
+
warnings: string[];
|
|
17
|
+
}
|
|
18
|
+
export interface ExportManifest {
|
|
19
|
+
schemaVersion: 2;
|
|
20
|
+
tool: 'ywtc';
|
|
21
|
+
identity: string;
|
|
22
|
+
format: ExportFormat;
|
|
23
|
+
generatedAt: string;
|
|
24
|
+
rootId: string;
|
|
25
|
+
pages: ExportManifestPage[];
|
|
26
|
+
}
|
|
27
|
+
export interface FilesystemExportResult {
|
|
28
|
+
directory: string;
|
|
29
|
+
archive?: string;
|
|
30
|
+
backup?: string;
|
|
31
|
+
manifest: ExportManifest;
|
|
32
|
+
warnings: string[];
|
|
33
|
+
errors: string[];
|
|
34
|
+
}
|
|
35
|
+
export declare class FilesystemExporter {
|
|
36
|
+
private readonly source;
|
|
37
|
+
private readonly concurrency;
|
|
38
|
+
constructor(source: SourceAdapter, concurrency: number);
|
|
39
|
+
export(input: {
|
|
40
|
+
graph: PageGraph;
|
|
41
|
+
directory: string;
|
|
42
|
+
format: ExportFormat;
|
|
43
|
+
identity: string;
|
|
44
|
+
archive: boolean;
|
|
45
|
+
dryRun: boolean;
|
|
46
|
+
cacheDirectory: string;
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
onItem?: (message: string) => void;
|
|
49
|
+
resourcesByPage?: Map<string, SourceResource[]>;
|
|
50
|
+
loadPage?: (page: SourcePage) => Promise<SourcePage>;
|
|
51
|
+
loadDocument?: (page: SourcePage) => Promise<ReturnType<typeof normalizePageContent>>;
|
|
52
|
+
}): Promise<FilesystemExportResult>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { createWriteStream } from 'node:fs';
|
|
3
|
+
import { access, mkdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { pipeline } from 'node:stream/promises';
|
|
6
|
+
import { ZipArchive } from '@archiver/archiver';
|
|
7
|
+
import PQueue from 'p-queue';
|
|
8
|
+
import { appendGridSnapshots, normalizePageContent, renderMarkdown, renderStaticHtml } from './content-model.js';
|
|
9
|
+
import { safeFilename } from './input.js';
|
|
10
|
+
function stableSegment(page) {
|
|
11
|
+
const title = page.title.normalize('NFKD').toLocaleLowerCase()
|
|
12
|
+
.replace(/[^\p{L}\p{N}]+/gu, '-')
|
|
13
|
+
.replace(/^-+|-+$/g, '')
|
|
14
|
+
.slice(0, 64) || 'page';
|
|
15
|
+
const suffix = createHash('sha256').update(page.canonicalId).digest('hex').slice(0, 8);
|
|
16
|
+
return `${title}-${suffix}`;
|
|
17
|
+
}
|
|
18
|
+
function pagePath(page, format, rootId) {
|
|
19
|
+
if (page.canonicalId === rootId)
|
|
20
|
+
return format === 'html' ? 'index.html' : 'index.md';
|
|
21
|
+
return format === 'html' ? `pages/${stableSegment(page)}/index.html` : `pages/${stableSegment(page)}.md`;
|
|
22
|
+
}
|
|
23
|
+
function htmlPage(title, navigation, body, cssPath) {
|
|
24
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${title.replaceAll('&', '&').replaceAll('<', '<')}</title><link rel="stylesheet" href="${cssPath}"></head><body><aside class="nav"><a class="brand" href="${cssPath.replace(/assets\/site\.css$/, 'index.html')}">ywtc export</a>${navigation}</aside><main><h1>${title.replaceAll('&', '&').replaceAll('<', '<')}</h1>${body}</main></body></html>`;
|
|
25
|
+
}
|
|
26
|
+
const SITE_CSS = `:root{font:16px/1.55 system-ui,sans-serif;color:#172033;background:#f4f6fa}*{box-sizing:border-box}body{margin:0;display:grid;grid-template-columns:minmax(220px,300px) 1fr;min-height:100vh}.nav{padding:24px;background:#111827;color:#dbe4f3;overflow:auto}.nav a{color:#dbe4f3;text-decoration:none}.nav a[aria-current=page]{color:#fff;font-weight:700}.nav ul{list-style:none;padding-left:16px}.brand{display:block;font-weight:700;margin-bottom:20px}main{max-width:1100px;width:100%;padding:40px;margin:0 auto;background:#fff}img{max-width:100%;height:auto}table{border-collapse:collapse;width:100%}th,td{border:1px solid #ccd5e2;padding:8px;text-align:left}pre{overflow:auto;background:#111827;color:#f8fafc;padding:16px;border-radius:8px}aside[class^=ywtc-]{border-left:4px solid #526dcf;background:#f2f5ff;padding:12px;margin:16px 0}.ywtc-fallback{border-color:#d59b24}@media(max-width:760px){body{display:block}.nav{position:relative}main{padding:22px}}`;
|
|
27
|
+
function relativeHref(from, to) {
|
|
28
|
+
const base = path.posix.dirname(from);
|
|
29
|
+
const result = path.posix.relative(base, to);
|
|
30
|
+
return result || path.posix.basename(to);
|
|
31
|
+
}
|
|
32
|
+
async function exists(filename) {
|
|
33
|
+
try {
|
|
34
|
+
await access(filename);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function managedManifest(directory, identity) {
|
|
42
|
+
try {
|
|
43
|
+
const parsed = JSON.parse(await readFile(path.join(directory, '.ywtc-export.json'), 'utf8'));
|
|
44
|
+
return parsed.schemaVersion === 2 && parsed.tool === 'ywtc' && parsed.identity === identity;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function timestamp() {
|
|
51
|
+
return new Date().toISOString().replace(/[:.]/g, '-');
|
|
52
|
+
}
|
|
53
|
+
async function createArchive(directory) {
|
|
54
|
+
const destination = `${directory}-${timestamp()}-${randomUUID().slice(0, 8)}.zip`;
|
|
55
|
+
const archive = new ZipArchive({ zlib: { level: 9 } });
|
|
56
|
+
archive.directory(directory, path.basename(directory));
|
|
57
|
+
const output = createWriteStream(destination, { flags: 'wx', mode: 0o600 });
|
|
58
|
+
const piping = pipeline(archive, output);
|
|
59
|
+
await archive.finalize();
|
|
60
|
+
await piping;
|
|
61
|
+
return destination;
|
|
62
|
+
}
|
|
63
|
+
async function verifyGeneratedTree(directory, manifest) {
|
|
64
|
+
const expected = [
|
|
65
|
+
'.ywtc-export.json',
|
|
66
|
+
...(manifest.format === 'html' ? ['assets/site.css'] : []),
|
|
67
|
+
...manifest.pages.flatMap((page) => [page.path, ...page.resources.map((resource) => resource.path)]),
|
|
68
|
+
];
|
|
69
|
+
await Promise.all(expected.map((relative) => access(path.join(directory, relative))));
|
|
70
|
+
for (const page of manifest.pages) {
|
|
71
|
+
const filename = path.join(directory, page.path);
|
|
72
|
+
const content = await readFile(filename, 'utf8');
|
|
73
|
+
const references = manifest.format === 'html'
|
|
74
|
+
? [...content.matchAll(/(?:href|src)=["']([^"']+)["']/g)].map((match) => match[1])
|
|
75
|
+
: [...content.matchAll(/!?\[[^\]]*\]\(([^)\s]+)(?:\s+["'][^"']*["'])?\)/g)].map((match) => match[1]);
|
|
76
|
+
for (const reference of references) {
|
|
77
|
+
if (/^(?:https?:|mailto:|tel:|data:|#)/i.test(reference))
|
|
78
|
+
continue;
|
|
79
|
+
const clean = decodeURIComponent(reference.split(/[?#]/, 1)[0] ?? '');
|
|
80
|
+
if (!clean)
|
|
81
|
+
continue;
|
|
82
|
+
const target = path.resolve(path.dirname(filename), clean);
|
|
83
|
+
const relative = path.relative(directory, target);
|
|
84
|
+
if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
85
|
+
throw new Error(`Generated reference escapes the export directory: ${page.path} → ${reference}`);
|
|
86
|
+
}
|
|
87
|
+
await access(target);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export class FilesystemExporter {
|
|
92
|
+
source;
|
|
93
|
+
concurrency;
|
|
94
|
+
constructor(source, concurrency) {
|
|
95
|
+
this.source = source;
|
|
96
|
+
this.concurrency = concurrency;
|
|
97
|
+
}
|
|
98
|
+
async export(input) {
|
|
99
|
+
const warnings = [...input.graph.warnings];
|
|
100
|
+
const errors = [];
|
|
101
|
+
const pagePaths = new Map(input.graph.pages.map((page) => [page.canonicalId, pagePath(page, input.format, input.graph.rootId)]));
|
|
102
|
+
const manifest = {
|
|
103
|
+
schemaVersion: 2,
|
|
104
|
+
tool: 'ywtc',
|
|
105
|
+
identity: input.identity,
|
|
106
|
+
format: input.format,
|
|
107
|
+
generatedAt: new Date().toISOString(),
|
|
108
|
+
rootId: input.graph.rootId,
|
|
109
|
+
pages: [],
|
|
110
|
+
};
|
|
111
|
+
if (input.dryRun) {
|
|
112
|
+
manifest.pages = input.graph.pages.map((page) => ({
|
|
113
|
+
sourceCanonicalId: page.canonicalId,
|
|
114
|
+
sourceUrl: page.url,
|
|
115
|
+
title: page.title,
|
|
116
|
+
path: pagePaths.get(page.canonicalId),
|
|
117
|
+
...(page.projectedParentId ? { parentId: page.projectedParentId } : {}),
|
|
118
|
+
resources: [],
|
|
119
|
+
degraded: false,
|
|
120
|
+
warnings: [],
|
|
121
|
+
}));
|
|
122
|
+
return { directory: input.directory, manifest, warnings, errors };
|
|
123
|
+
}
|
|
124
|
+
const parent = path.dirname(input.directory);
|
|
125
|
+
const staging = path.join(parent, `.${path.basename(input.directory)}.ywtc-staging-${randomUUID().slice(0, 8)}`);
|
|
126
|
+
await mkdir(parent, { recursive: true, mode: 0o700 });
|
|
127
|
+
await mkdir(staging, { recursive: false, mode: 0o700 });
|
|
128
|
+
let backup;
|
|
129
|
+
try {
|
|
130
|
+
const sourcePages = new Map(input.graph.pages.map((page) => [page.canonicalId, page]));
|
|
131
|
+
const queue = new PQueue({ concurrency: this.concurrency });
|
|
132
|
+
const resourceMapByPage = new Map();
|
|
133
|
+
const resourcesByPage = new Map();
|
|
134
|
+
await Promise.all(input.graph.pages.map((page) => queue.add(async () => {
|
|
135
|
+
if (input.signal?.aborted)
|
|
136
|
+
throw input.signal.reason ?? new Error('Export cancelled');
|
|
137
|
+
const resources = input.resourcesByPage?.get(page.canonicalId) ?? await this.source.listResources(page);
|
|
138
|
+
resourcesByPage.set(page.canonicalId, resources);
|
|
139
|
+
const pageResources = new Map();
|
|
140
|
+
const manifestResources = [];
|
|
141
|
+
for (const resource of resources.filter((item) => item.kind !== 'grid')) {
|
|
142
|
+
const name = safeFilename(resource.name);
|
|
143
|
+
const relative = `attachments/${stableSegment(page)}/${name}`;
|
|
144
|
+
const destination = path.join(staging, relative);
|
|
145
|
+
await mkdir(path.dirname(destination), { recursive: true });
|
|
146
|
+
const downloaded = await this.source.downloadResource(resource, destination);
|
|
147
|
+
pageResources.set(name.toLocaleLowerCase(), { path: relative, name });
|
|
148
|
+
manifestResources.push({ name, path: relative, size: downloaded.size, sha256: downloaded.sha256 });
|
|
149
|
+
input.onItem?.(`attachment ${name}`);
|
|
150
|
+
}
|
|
151
|
+
resourceMapByPage.set(page.canonicalId, pageResources);
|
|
152
|
+
manifest.pages.push({
|
|
153
|
+
sourceCanonicalId: page.canonicalId,
|
|
154
|
+
sourceUrl: page.url,
|
|
155
|
+
title: page.title,
|
|
156
|
+
path: pagePaths.get(page.canonicalId),
|
|
157
|
+
...(page.projectedParentId ? { parentId: page.projectedParentId } : {}),
|
|
158
|
+
resources: manifestResources,
|
|
159
|
+
degraded: false,
|
|
160
|
+
warnings: [],
|
|
161
|
+
});
|
|
162
|
+
})));
|
|
163
|
+
const children = new Map();
|
|
164
|
+
for (const page of input.graph.pages) {
|
|
165
|
+
const parentId = page.projectedParentId ?? '__root__';
|
|
166
|
+
const siblings = children.get(parentId) ?? [];
|
|
167
|
+
siblings.push(page);
|
|
168
|
+
children.set(parentId, siblings);
|
|
169
|
+
}
|
|
170
|
+
const navigationFor = (currentPath) => {
|
|
171
|
+
const renderItems = (parentId) => `<ul>${(children.get(parentId) ?? []).map((page) => {
|
|
172
|
+
const pageFile = pagePaths.get(page.canonicalId);
|
|
173
|
+
const active = pageFile === currentPath ? ' aria-current="page"' : '';
|
|
174
|
+
const title = page.title.replaceAll('&', '&').replaceAll('<', '<');
|
|
175
|
+
return `<li><a${active} href="${relativeHref(currentPath, pageFile)}">${title}</a>${renderItems(page.canonicalId)}</li>`;
|
|
176
|
+
}).join('')}</ul>`;
|
|
177
|
+
return renderItems('__root__');
|
|
178
|
+
};
|
|
179
|
+
for (const page of input.graph.pages) {
|
|
180
|
+
const fullPage = input.loadPage ? await input.loadPage(page) : page;
|
|
181
|
+
const relative = pagePaths.get(page.canonicalId);
|
|
182
|
+
const resources = resourcesByPage.get(page.canonicalId) ?? [];
|
|
183
|
+
const document = input.loadDocument
|
|
184
|
+
? await input.loadDocument(page)
|
|
185
|
+
: appendGridSnapshots(normalizePageContent(fullPage), resources);
|
|
186
|
+
const pages = new Map([...pagePaths].map(([id, file]) => [id, { path: file, title: sourcePages.get(id)?.title ?? id }]));
|
|
187
|
+
const context = {
|
|
188
|
+
pages,
|
|
189
|
+
resources: resourceMapByPage.get(page.canonicalId) ?? new Map(),
|
|
190
|
+
sourcePages,
|
|
191
|
+
currentPageId: page.canonicalId,
|
|
192
|
+
currentPath: relative,
|
|
193
|
+
};
|
|
194
|
+
const rendered = input.format === 'html' ? await renderStaticHtml(document, context) : await renderMarkdown(document, context);
|
|
195
|
+
const output = input.format === 'html'
|
|
196
|
+
? htmlPage(page.title, navigationFor(relative), rendered.body, relativeHref(relative, 'assets/site.css'))
|
|
197
|
+
: `# ${page.title}\n\n${rendered.body}`;
|
|
198
|
+
await mkdir(path.dirname(path.join(staging, relative)), { recursive: true });
|
|
199
|
+
await writeFile(path.join(staging, relative), output, { mode: 0o600 });
|
|
200
|
+
const manifestPage = manifest.pages.find((item) => item.sourceCanonicalId === page.canonicalId);
|
|
201
|
+
manifestPage.degraded = rendered.degraded;
|
|
202
|
+
manifestPage.warnings.push(...rendered.warnings);
|
|
203
|
+
warnings.push(...rendered.warnings.map((warning) => `${page.title}: ${warning}`));
|
|
204
|
+
if (rendered.degraded) {
|
|
205
|
+
const snapshot = `_source/${stableSegment(page)}.${page.rawFormat === 'yfm' ? 'yfm' : 'storage.xml'}`;
|
|
206
|
+
await mkdir(path.dirname(path.join(staging, snapshot)), { recursive: true });
|
|
207
|
+
await writeFile(path.join(staging, snapshot), fullPage.rawContent, { mode: 0o600 });
|
|
208
|
+
}
|
|
209
|
+
input.onItem?.(`page ${page.title}`);
|
|
210
|
+
}
|
|
211
|
+
manifest.pages.sort((left, right) => left.path.localeCompare(right.path));
|
|
212
|
+
if (input.format === 'html') {
|
|
213
|
+
await mkdir(path.join(staging, 'assets'), { recursive: true });
|
|
214
|
+
await writeFile(path.join(staging, 'assets/site.css'), SITE_CSS, { mode: 0o600 });
|
|
215
|
+
}
|
|
216
|
+
await writeFile(path.join(staging, '.ywtc-export.json'), `${JSON.stringify(manifest, null, 2)}\n`, { mode: 0o600 });
|
|
217
|
+
await verifyGeneratedTree(staging, manifest);
|
|
218
|
+
if (await exists(input.directory)) {
|
|
219
|
+
const selected = await stat(input.directory);
|
|
220
|
+
if (!selected.isDirectory() || !(await managedManifest(input.directory, input.identity))) {
|
|
221
|
+
throw new Error(`Refusing to replace unmanaged destination "${input.directory}". Choose an empty path or a directory with a matching .ywtc-export.json.`);
|
|
222
|
+
}
|
|
223
|
+
backup = `${input.directory}.backup-${timestamp()}`;
|
|
224
|
+
await rename(input.directory, backup);
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
await rename(staging, input.directory);
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
if (backup && !(await exists(input.directory)))
|
|
231
|
+
await rename(backup, input.directory);
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
234
|
+
const archive = input.archive ? await createArchive(input.directory) : undefined;
|
|
235
|
+
return { directory: input.directory, ...(archive ? { archive } : {}), ...(backup ? { backup } : {}), manifest, warnings, errors };
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
await rm(staging, { recursive: true, force: true });
|
|
239
|
+
throw error;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=filesystem-export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filesystem-export.js","sourceRoot":"","sources":["../src/filesystem-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,UAAU,EAAC,MAAM,aAAa,CAAC;AACnD,OAAO,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,IA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E,MAAM,EAAC,CAAC;QAC9H,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,EAAE,CAAC,OAAO,EAAE,EAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC,CAAC;YAClD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
package/dist/graph.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PageGraph, SourceAdapter, SourcePage, TransferScope } from './domain.js';
|
|
2
|
+
export interface DiscoveryProgress {
|
|
3
|
+
pages: number;
|
|
4
|
+
edges: number;
|
|
5
|
+
active?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function discoverPageGraph(input: {
|
|
8
|
+
adapter: SourceAdapter;
|
|
9
|
+
root: SourcePage;
|
|
10
|
+
scope: TransferScope;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
onProgress?: (progress: DiscoveryProgress) => void;
|
|
13
|
+
}): Promise<PageGraph>;
|