@foliwake/cli 0.0.0-stage → 0.7.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/CHANGELOG.md +56 -0
- package/LICENSE +202 -0
- package/README.md +654 -2
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +9 -0
- package/dist/command-words.d.ts +13 -0
- package/dist/command-words.js +53 -0
- package/dist/commands/account/keys/create.d.ts +12 -0
- package/dist/commands/account/keys/create.js +36 -0
- package/dist/commands/account/keys/list.d.ts +9 -0
- package/dist/commands/account/keys/list.js +23 -0
- package/dist/commands/account/keys/revoke.d.ts +12 -0
- package/dist/commands/account/keys/revoke.js +15 -0
- package/dist/commands/branch/bootstrap.d.ts +11 -0
- package/dist/commands/branch/bootstrap.js +23 -0
- package/dist/commands/branch/delete.d.ts +17 -0
- package/dist/commands/branch/delete.js +38 -0
- package/dist/commands/branch/history.d.ts +14 -0
- package/dist/commands/branch/history.js +24 -0
- package/dist/commands/branch/list.d.ts +11 -0
- package/dist/commands/branch/list.js +15 -0
- package/dist/commands/branch/update.d.ts +19 -0
- package/dist/commands/branch/update.js +49 -0
- package/dist/commands/code/deploy.d.ts +15 -0
- package/dist/commands/code/deploy.js +78 -0
- package/dist/commands/code/prepare.d.ts +13 -0
- package/dist/commands/code/prepare.js +54 -0
- package/dist/commands/code/release.d.ts +19 -0
- package/dist/commands/code/release.js +51 -0
- package/dist/commands/code/rollback.d.ts +17 -0
- package/dist/commands/code/rollback.js +38 -0
- package/dist/commands/connect.d.ts +19 -0
- package/dist/commands/connect.js +100 -0
- package/dist/commands/create.d.ts +32 -0
- package/dist/commands/create.js +171 -0
- package/dist/commands/credential/list.d.ts +10 -0
- package/dist/commands/credential/list.js +21 -0
- package/dist/commands/credential/rm.d.ts +12 -0
- package/dist/commands/credential/rm.js +18 -0
- package/dist/commands/credential/set.d.ts +15 -0
- package/dist/commands/credential/set.js +58 -0
- package/dist/commands/dev.d.ts +30 -0
- package/dist/commands/dev.js +144 -0
- package/dist/commands/login.d.ts +20 -0
- package/dist/commands/login.js +94 -0
- package/dist/commands/logout.d.ts +14 -0
- package/dist/commands/logout.js +61 -0
- package/dist/commands/migration/commit.d.ts +13 -0
- package/dist/commands/migration/commit.js +42 -0
- package/dist/commands/migration/prepare.d.ts +18 -0
- package/dist/commands/migration/prepare.js +53 -0
- package/dist/commands/operation/cancel.d.ts +14 -0
- package/dist/commands/operation/cancel.js +21 -0
- package/dist/commands/operation/get.d.ts +14 -0
- package/dist/commands/operation/get.js +26 -0
- package/dist/commands/operation/list.d.ts +12 -0
- package/dist/commands/operation/list.js +25 -0
- package/dist/commands/operation/recover.d.ts +20 -0
- package/dist/commands/operation/recover.js +61 -0
- package/dist/commands/page/changes.d.ts +13 -0
- package/dist/commands/page/changes.js +26 -0
- package/dist/commands/page/check.d.ts +12 -0
- package/dist/commands/page/check.js +25 -0
- package/dist/commands/page/replace.d.ts +13 -0
- package/dist/commands/page/replace.js +59 -0
- package/dist/commands/page/unpreview.d.ts +17 -0
- package/dist/commands/page/unpreview.js +54 -0
- package/dist/commands/page/unpublish.d.ts +18 -0
- package/dist/commands/page/unpublish.js +36 -0
- package/dist/commands/project/preview.d.ts +8 -0
- package/dist/commands/project/preview.js +20 -0
- package/dist/commands/project/publish.d.ts +16 -0
- package/dist/commands/project/publish.js +40 -0
- package/dist/commands/project/unpublish.d.ts +16 -0
- package/dist/commands/project/unpublish.js +33 -0
- package/dist/commands/release/rollback.d.ts +17 -0
- package/dist/commands/release/rollback.js +38 -0
- package/dist/commands/servers/index.d.ts +20 -0
- package/dist/commands/servers/index.js +36 -0
- package/dist/commands/servers/use.d.ts +11 -0
- package/dist/commands/servers/use.js +30 -0
- package/dist/commands/site/adopt.d.ts +11 -0
- package/dist/commands/site/adopt.js +21 -0
- package/dist/commands/site/create.d.ts +18 -0
- package/dist/commands/site/create.js +61 -0
- package/dist/commands/site/edit.d.ts +11 -0
- package/dist/commands/site/edit.js +56 -0
- package/dist/commands/site/history.d.ts +11 -0
- package/dist/commands/site/history.js +25 -0
- package/dist/commands/site/link.d.ts +15 -0
- package/dist/commands/site/link.js +35 -0
- package/dist/commands/site/list.d.ts +9 -0
- package/dist/commands/site/list.js +29 -0
- package/dist/commands/site/reset-storage.d.ts +15 -0
- package/dist/commands/site/reset-storage.js +61 -0
- package/dist/commands/site/set.d.ts +16 -0
- package/dist/commands/site/set.js +45 -0
- package/dist/commands/site/show.d.ts +10 -0
- package/dist/commands/site/show.js +19 -0
- package/dist/commands/site/status.d.ts +11 -0
- package/dist/commands/site/status.js +15 -0
- package/dist/commands/site/unlink.d.ts +11 -0
- package/dist/commands/site/unlink.js +28 -0
- package/dist/commands/source/add.d.ts +32 -0
- package/dist/commands/source/add.js +103 -0
- package/dist/commands/source/adopt-pages.d.ts +14 -0
- package/dist/commands/source/adopt-pages.js +30 -0
- package/dist/commands/source/check.d.ts +17 -0
- package/dist/commands/source/check.js +52 -0
- package/dist/commands/source/list.d.ts +11 -0
- package/dist/commands/source/list.js +15 -0
- package/dist/commands/source/mappings/check.d.ts +13 -0
- package/dist/commands/source/mappings/check.js +69 -0
- package/dist/commands/source/pending.d.ts +12 -0
- package/dist/commands/source/pending.js +25 -0
- package/dist/commands/source/plugins.d.ts +6 -0
- package/dist/commands/source/plugins.js +17 -0
- package/dist/commands/source/sync.d.ts +16 -0
- package/dist/commands/source/sync.js +58 -0
- package/dist/commands/whoami.d.ts +6 -0
- package/dist/commands/whoami.js +22 -0
- package/dist/connect-prompts.d.ts +16 -0
- package/dist/connect-prompts.js +24 -0
- package/dist/connect.d.ts +133 -0
- package/dist/connect.js +416 -0
- package/dist/core-command.d.ts +99 -0
- package/dist/core-command.js +332 -0
- package/dist/core-types.d.ts +21 -0
- package/dist/core-types.js +1 -0
- package/dist/create-connect.d.ts +26 -0
- package/dist/create-connect.js +93 -0
- package/dist/dev/code-watcher.d.ts +66 -0
- package/dist/dev/code-watcher.js +254 -0
- package/dist/dev/dev-checks.d.ts +14 -0
- package/dist/dev/dev-checks.js +138 -0
- package/dist/dev/dev-reload.d.ts +51 -0
- package/dist/dev/dev-reload.js +345 -0
- package/dist/dev/flags.d.ts +19 -0
- package/dist/dev/flags.js +54 -0
- package/dist/dev/html.d.ts +30 -0
- package/dist/dev/html.js +106 -0
- package/dist/dev/kit-files.d.ts +7 -0
- package/dist/dev/kit-files.js +33 -0
- package/dist/dev/local-code.d.ts +22 -0
- package/dist/dev/local-code.js +101 -0
- package/dist/dev/remote-config.d.ts +57 -0
- package/dist/dev/remote-config.js +100 -0
- package/dist/dev/remote-dev.d.ts +41 -0
- package/dist/dev/remote-dev.js +527 -0
- package/dist/dev/remote-fetch.d.ts +5 -0
- package/dist/dev/remote-fetch.js +36 -0
- package/dist/dev/remote-html.d.ts +10 -0
- package/dist/dev/remote-html.js +60 -0
- package/dist/dev/remote-page.d.ts +34 -0
- package/dist/dev/remote-page.js +183 -0
- package/dist/dev/remote-routes.d.ts +63 -0
- package/dist/dev/remote-routes.js +114 -0
- package/dist/dev/signal-stop.d.ts +17 -0
- package/dist/dev/signal-stop.js +46 -0
- package/dist/dev/start.d.ts +18 -0
- package/dist/dev/start.js +80 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -0
- package/dist/lib/diagnostics.d.ts +15 -0
- package/dist/lib/diagnostics.js +12 -0
- package/dist/lib/front-matter.d.ts +6 -0
- package/dist/lib/front-matter.js +59 -0
- package/dist/lib/operation-result.d.ts +3 -0
- package/dist/lib/operation-result.js +16 -0
- package/dist/lib/problem-groups.d.ts +27 -0
- package/dist/lib/problem-groups.js +49 -0
- package/dist/lib/problems.d.ts +50 -0
- package/dist/lib/problems.js +94 -0
- package/dist/lib/prompts.d.ts +38 -0
- package/dist/lib/prompts.js +77 -0
- package/dist/lib/result-types.d.ts +198 -0
- package/dist/lib/result-types.js +3 -0
- package/dist/lib/rules.d.ts +15 -0
- package/dist/lib/rules.js +26 -0
- package/dist/lib/summaries.d.ts +19 -0
- package/dist/lib/summaries.js +22 -0
- package/dist/lib/sync-problems.d.ts +21 -0
- package/dist/lib/sync-problems.js +19 -0
- package/dist/local-runtime.d.ts +78 -0
- package/dist/local-runtime.js +11 -0
- package/dist/local-target.d.ts +6 -0
- package/dist/local-target.js +23 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +40 -0
- package/dist/project-preview.d.ts +35 -0
- package/dist/project-preview.js +156 -0
- package/dist/project-publish.d.ts +28 -0
- package/dist/project-publish.js +173 -0
- package/dist/remote/connection.d.ts +8 -0
- package/dist/remote/connection.js +19 -0
- package/dist/remote/core-failure.d.ts +8 -0
- package/dist/remote/core-failure.js +15 -0
- package/dist/remote/credentials.d.ts +15 -0
- package/dist/remote/credentials.js +112 -0
- package/dist/remote/device-login.d.ts +33 -0
- package/dist/remote/device-login.js +161 -0
- package/dist/remote/remote-caller.d.ts +14 -0
- package/dist/remote/remote-caller.js +52 -0
- package/dist/remote/rpc-wire.d.ts +18 -0
- package/dist/remote/rpc-wire.js +57 -0
- package/dist/remote/servers.d.ts +80 -0
- package/dist/remote/servers.js +162 -0
- package/dist/remote/session.d.ts +53 -0
- package/dist/remote/session.js +132 -0
- package/dist/remote/sign-in-here.d.ts +5 -0
- package/dist/remote/sign-in-here.js +33 -0
- package/dist/remote/sign-in.d.ts +25 -0
- package/dist/remote/sign-in.js +55 -0
- package/dist/remote/wait-slices.d.ts +16 -0
- package/dist/remote/wait-slices.js +21 -0
- package/dist/render/add.d.ts +3 -0
- package/dist/render/add.js +9 -0
- package/dist/render/branch-write.d.ts +9 -0
- package/dist/render/branch-write.js +28 -0
- package/dist/render/branches.d.ts +5 -0
- package/dist/render/branches.js +28 -0
- package/dist/render/credentials.d.ts +5 -0
- package/dist/render/credentials.js +39 -0
- package/dist/render/operation-result.d.ts +16 -0
- package/dist/render/operation-result.js +65 -0
- package/dist/render/operation.d.ts +7 -0
- package/dist/render/operation.js +15 -0
- package/dist/render/page-changes.d.ts +3 -0
- package/dist/render/page-changes.js +36 -0
- package/dist/render/pending.d.ts +3 -0
- package/dist/render/pending.js +46 -0
- package/dist/render/plugin-list.d.ts +3 -0
- package/dist/render/plugin-list.js +30 -0
- package/dist/render/probe.d.ts +3 -0
- package/dist/render/probe.js +61 -0
- package/dist/render/problems.d.ts +35 -0
- package/dist/render/problems.js +64 -0
- package/dist/render/recovery.d.ts +2 -0
- package/dist/render/recovery.js +36 -0
- package/dist/render/reset-storage.d.ts +4 -0
- package/dist/render/reset-storage.js +70 -0
- package/dist/render/site-status.d.ts +2 -0
- package/dist/render/site-status.js +81 -0
- package/dist/render/source-list.d.ts +2 -0
- package/dist/render/source-list.js +37 -0
- package/dist/render/sync.d.ts +5 -0
- package/dist/render/sync.js +66 -0
- package/dist/settings.d.ts +10 -0
- package/dist/settings.js +45 -0
- package/dist/site-entry-edit.d.ts +5 -0
- package/dist/site-entry-edit.js +44 -0
- package/dist/source-entry.d.ts +32 -0
- package/dist/source-entry.js +89 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.js +10 -0
- package/package.json +112 -3
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Diagnostic } from '@foliwake/site-check/formats/diagnostics';
|
|
2
|
+
import type { DevProblem } from './dev-reload.js';
|
|
3
|
+
/** The content kept from a remote page. */
|
|
4
|
+
export interface RemotePage {
|
|
5
|
+
lang: string | null;
|
|
6
|
+
htmlContract: string | null;
|
|
7
|
+
title: string;
|
|
8
|
+
description: string | null;
|
|
9
|
+
/** The children of <main>, serialized. */
|
|
10
|
+
body: string;
|
|
11
|
+
/** data-component values used in <main>, in document order, without duplicates. */
|
|
12
|
+
components: string[];
|
|
13
|
+
}
|
|
14
|
+
/** Extracts the content of a deployed page; null when the document has no <main>. */
|
|
15
|
+
export declare function extractRemotePage(html: string): RemotePage | null;
|
|
16
|
+
/** Visible text of an HTML document (for the remote's own error pages). */
|
|
17
|
+
export declare function remoteText(html: string): string;
|
|
18
|
+
/** The local descriptor as far as it can be read: htmlContract and component names. */
|
|
19
|
+
export interface LocalDescriptor {
|
|
20
|
+
htmlContract: unknown;
|
|
21
|
+
components: Record<string, unknown> | null;
|
|
22
|
+
}
|
|
23
|
+
export declare function readLocalDescriptor(cwd: string): Promise<LocalDescriptor | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Whether the local frontend can render a remote page: the remote contract
|
|
26
|
+
* equals the engine's and the local descriptor's, every component the page
|
|
27
|
+
* uses is declared locally, and the descriptor (assets present) is valid.
|
|
28
|
+
*/
|
|
29
|
+
export declare function compatibilityProblems({ page, descriptor, descriptorDiagnostics, engineContract, }: {
|
|
30
|
+
page: RemotePage;
|
|
31
|
+
descriptor: LocalDescriptor | null;
|
|
32
|
+
descriptorDiagnostics: readonly Diagnostic[];
|
|
33
|
+
engineContract?: number;
|
|
34
|
+
}): DevProblem[];
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// `foliwake dev --remote`: the content kept from a deployed page (parse5; only the children of <main>,
|
|
2
|
+
// <title>, <meta name="description">, <html lang> and <html data-html-contract>), and whether the local
|
|
3
|
+
// frontend can render it.
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { parse, serialize } from 'parse5';
|
|
7
|
+
import { HTML_CONTRACT } from '@foliwake/site-check/formats/constants';
|
|
8
|
+
import { DESCRIPTOR_PATH } from '@foliwake/site-check/formats/descriptor';
|
|
9
|
+
import { toProblem } from './dev-checks.js';
|
|
10
|
+
function isElement(node) {
|
|
11
|
+
return 'tagName' in node;
|
|
12
|
+
}
|
|
13
|
+
function attr(element, name) {
|
|
14
|
+
return element.attrs.find((a) => a.name === name)?.value ?? null;
|
|
15
|
+
}
|
|
16
|
+
function children(node) {
|
|
17
|
+
const own = 'childNodes' in node ? node.childNodes : [];
|
|
18
|
+
// <template> content is a separate fragment.
|
|
19
|
+
return isElement(node) && node.tagName === 'template' && 'content' in node
|
|
20
|
+
? [...own, ...node.content.childNodes]
|
|
21
|
+
: own;
|
|
22
|
+
}
|
|
23
|
+
function find(node, predicate) {
|
|
24
|
+
for (const child of children(node)) {
|
|
25
|
+
if (isElement(child) && predicate(child))
|
|
26
|
+
return child;
|
|
27
|
+
const found = find(child, predicate);
|
|
28
|
+
if (found)
|
|
29
|
+
return found;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function walk(node, visit) {
|
|
34
|
+
for (const child of children(node)) {
|
|
35
|
+
if (isElement(child))
|
|
36
|
+
visit(child);
|
|
37
|
+
walk(child, visit);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function textOf(node) {
|
|
41
|
+
if (node.nodeName === '#text')
|
|
42
|
+
return node.value;
|
|
43
|
+
return children(node).map(textOf).join('');
|
|
44
|
+
}
|
|
45
|
+
/** Extracts the content of a deployed page; null when the document has no <main>. */
|
|
46
|
+
export function extractRemotePage(html) {
|
|
47
|
+
const document = parse(html);
|
|
48
|
+
const root = document.childNodes.find((n) => isElement(n) && n.tagName === 'html');
|
|
49
|
+
if (!root)
|
|
50
|
+
return null;
|
|
51
|
+
const head = root.childNodes.find((n) => isElement(n) && n.tagName === 'head');
|
|
52
|
+
const body = root.childNodes.find((n) => isElement(n) && n.tagName === 'body');
|
|
53
|
+
const main = body ? find(body, (e) => e.tagName === 'main') : null;
|
|
54
|
+
if (!main)
|
|
55
|
+
return null;
|
|
56
|
+
const title = head ? find(head, (e) => e.tagName === 'title') : null;
|
|
57
|
+
const meta = head
|
|
58
|
+
? find(head, (e) => e.tagName === 'meta' && (attr(e, 'name') ?? '').toLowerCase() === 'description')
|
|
59
|
+
: null;
|
|
60
|
+
const components = [];
|
|
61
|
+
walk(main, (element) => {
|
|
62
|
+
const name = attr(element, 'data-component')?.trim();
|
|
63
|
+
if (name && !components.includes(name))
|
|
64
|
+
components.push(name);
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
lang: attr(root, 'lang'),
|
|
68
|
+
htmlContract: attr(root, 'data-html-contract'),
|
|
69
|
+
title: title ? textOf(title).trim() : '',
|
|
70
|
+
description: meta ? attr(meta, 'content') : null,
|
|
71
|
+
body: serialize(main),
|
|
72
|
+
components,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** Visible text of an HTML document (for the remote's own error pages). */
|
|
76
|
+
export function remoteText(html) {
|
|
77
|
+
const document = parse(html);
|
|
78
|
+
const root = document.childNodes.find((n) => isElement(n) && n.tagName === 'html');
|
|
79
|
+
const body = root?.childNodes.find((n) => isElement(n) && n.tagName === 'body');
|
|
80
|
+
const parts = [];
|
|
81
|
+
const collect = (node) => {
|
|
82
|
+
for (const child of children(node)) {
|
|
83
|
+
if (isElement(child) && (child.tagName === 'script' || child.tagName === 'style'))
|
|
84
|
+
continue;
|
|
85
|
+
if (child.nodeName === '#text')
|
|
86
|
+
parts.push(child.value);
|
|
87
|
+
else
|
|
88
|
+
collect(child);
|
|
89
|
+
if (isElement(child) && /^(p|h[1-6]|li|div|pre|br|tr)$/.test(child.tagName))
|
|
90
|
+
parts.push('\n');
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
if (body)
|
|
94
|
+
collect(body);
|
|
95
|
+
return parts
|
|
96
|
+
.join('')
|
|
97
|
+
.replace(/[ \t]+/g, ' ')
|
|
98
|
+
.replace(/\n\s*\n+/g, '\n')
|
|
99
|
+
.trim()
|
|
100
|
+
.slice(0, 4000);
|
|
101
|
+
}
|
|
102
|
+
export async function readLocalDescriptor(cwd) {
|
|
103
|
+
try {
|
|
104
|
+
const parsed = JSON.parse(await readFile(path.join(cwd, DESCRIPTOR_PATH), 'utf8'));
|
|
105
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
106
|
+
return null;
|
|
107
|
+
const record = parsed;
|
|
108
|
+
const components = record.components !== null && typeof record.components === 'object' && !Array.isArray(record.components)
|
|
109
|
+
? record.components
|
|
110
|
+
: null;
|
|
111
|
+
return { htmlContract: record.htmlContract, components };
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Whether the local frontend can render a remote page: the remote contract
|
|
119
|
+
* equals the engine's and the local descriptor's, every component the page
|
|
120
|
+
* uses is declared locally, and the descriptor (assets present) is valid.
|
|
121
|
+
*/
|
|
122
|
+
export function compatibilityProblems({ page, descriptor, descriptorDiagnostics, engineContract = HTML_CONTRACT, }) {
|
|
123
|
+
const problems = [];
|
|
124
|
+
const remote = page.htmlContract;
|
|
125
|
+
if (remote === null) {
|
|
126
|
+
problems.push({
|
|
127
|
+
file: '(remote page)',
|
|
128
|
+
line: null,
|
|
129
|
+
column: null,
|
|
130
|
+
code: 'REMOTE_CONTRACT_MISSING',
|
|
131
|
+
message: 'The remote page has no <html data-html-contract>; it does not look like a Foliwake page.',
|
|
132
|
+
fix: 'Check the configured URL: it must be the Foliwake origin (preview or live).',
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
if (remote !== String(engineContract)) {
|
|
137
|
+
problems.push({
|
|
138
|
+
file: '(remote page)',
|
|
139
|
+
line: null,
|
|
140
|
+
column: null,
|
|
141
|
+
code: 'REMOTE_CONTRACT_MISMATCH',
|
|
142
|
+
message: `The remote page uses HTML contract ${remote}, this CLI's frontend checks use contract ` +
|
|
143
|
+
`${engineContract}.`,
|
|
144
|
+
fix: `Use a @foliwake/cli version with HTML contract ${remote}, or develop against a site published with ` +
|
|
145
|
+
`contract ${engineContract}.`,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (descriptor && String(descriptor.htmlContract) !== remote) {
|
|
149
|
+
problems.push({
|
|
150
|
+
file: DESCRIPTOR_PATH,
|
|
151
|
+
line: null,
|
|
152
|
+
column: null,
|
|
153
|
+
code: 'REMOTE_CONTRACT_MISMATCH',
|
|
154
|
+
message: `${DESCRIPTOR_PATH} has htmlContract ${JSON.stringify(descriptor.htmlContract)}, the remote page ` +
|
|
155
|
+
`uses ${remote}.`,
|
|
156
|
+
fix: `Develop this frontend against a site with contract ${JSON.stringify(descriptor.htmlContract)}, or ` +
|
|
157
|
+
`update the components to contract ${remote}.`,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const declared = descriptor?.components ?? null;
|
|
162
|
+
const undeclared = declared ? page.components.filter((name) => !Object.hasOwn(declared, name)) : [];
|
|
163
|
+
for (const name of undeclared) {
|
|
164
|
+
problems.push({
|
|
165
|
+
file: DESCRIPTOR_PATH,
|
|
166
|
+
line: null,
|
|
167
|
+
column: null,
|
|
168
|
+
code: 'CODE_COMPONENT_NOT_DECLARED',
|
|
169
|
+
message: `The remote page uses component "${name}", but ${DESCRIPTOR_PATH} does not declare it; it is not ` +
|
|
170
|
+
`enhanced here.`,
|
|
171
|
+
fix: `Add "${name}": {"css": …, "js": …} with its files under components/${name}/, or develop against ` +
|
|
172
|
+
`content without it.`,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
// Descriptor errors that affect this page: an unreadable descriptor and missing assets of used components.
|
|
176
|
+
for (const d of descriptorDiagnostics) {
|
|
177
|
+
if (d.severity !== 'error')
|
|
178
|
+
continue;
|
|
179
|
+
if (d.component === null || page.components.includes(d.component))
|
|
180
|
+
problems.push(toProblem(d));
|
|
181
|
+
}
|
|
182
|
+
return problems;
|
|
183
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** The author block catalog of a preview origin; `dev --remote` answers it with a stub. */
|
|
2
|
+
export declare const BLOCK_CATALOG_PATH = "/_foliwake/blocks";
|
|
3
|
+
/** Content-addressed media of the deployed origin: the only /media paths fetched. */
|
|
4
|
+
export declare const REMOTE_MEDIA_PATTERN: RegExp;
|
|
5
|
+
/** Browser cache of proxied media: short, private, not immutable. */
|
|
6
|
+
export declare const REMOTE_MEDIA_CACHE = "private, max-age=300";
|
|
7
|
+
export declare const DEFAULT_REMOTE_TIMEOUT_MS = 15000;
|
|
8
|
+
export declare const DEPLOYED_CODE_TEXT: string;
|
|
9
|
+
/** What one request path is served from. */
|
|
10
|
+
export type RemoteRoute = {
|
|
11
|
+
kind: 'code';
|
|
12
|
+
prefix: string;
|
|
13
|
+
rest: string[];
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'media';
|
|
16
|
+
path: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'deployed-code';
|
|
19
|
+
} | {
|
|
20
|
+
kind: 'dev';
|
|
21
|
+
path: string;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'page';
|
|
24
|
+
path: string;
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'not-found';
|
|
27
|
+
};
|
|
28
|
+
/** Classifies a raw request path (without the query). Unsafe paths are `not-found` and never reach the remote site. */
|
|
29
|
+
export declare function classifyRemoteRoute(rawPath: string): RemoteRoute;
|
|
30
|
+
/** The remote URL of a page or media path: always on `origin`, or null. */
|
|
31
|
+
export declare function remoteUrl(origin: string, rawPath: string, query: string): URL | null;
|
|
32
|
+
export type LocalRequestCheck = {
|
|
33
|
+
ok: true;
|
|
34
|
+
} | {
|
|
35
|
+
ok: false;
|
|
36
|
+
status: 403 | 421;
|
|
37
|
+
message: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The browser request may reach this listener only from itself: Host must be a
|
|
41
|
+
* loopback name with the listening port (DNS rebinding), and an Origin header,
|
|
42
|
+
* when present, must be this listener's own origin.
|
|
43
|
+
*/
|
|
44
|
+
export declare function checkLocalRequest(headers: {
|
|
45
|
+
host?: string | undefined;
|
|
46
|
+
origin?: string | undefined;
|
|
47
|
+
}, port: number): LocalRequestCheck;
|
|
48
|
+
/**
|
|
49
|
+
* The complete set of headers sent to the remote site: fixed values, a
|
|
50
|
+
* validated Accept-Language and the configured Authorization. Nothing else
|
|
51
|
+
* from the browser request is forwarded (no cookies, no browser credentials).
|
|
52
|
+
*/
|
|
53
|
+
export declare function remoteRequestHeaders({ kind, acceptLanguage, authorization, }: {
|
|
54
|
+
kind: 'page' | 'media';
|
|
55
|
+
acceptLanguage?: string | string[] | undefined;
|
|
56
|
+
authorization: string | null;
|
|
57
|
+
}): Record<string, string>;
|
|
58
|
+
/**
|
|
59
|
+
* The only remote response headers passed to the browser: the release IDs of
|
|
60
|
+
* the deployed site (validated). Set-Cookie, WWW-Authenticate, caching,
|
|
61
|
+
* hop-by-hop and every other header are dropped.
|
|
62
|
+
*/
|
|
63
|
+
export declare function pickRemoteHeaders(headers: Headers): Record<string, string>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// `foliwake dev --remote`: what a request path is served from, the remote URL it maps to, which browser
|
|
2
|
+
// requests reach the listener at all, and the fixed request and response headers towards the remote site.
|
|
3
|
+
// Pure helpers; the server is remote-dev.ts.
|
|
4
|
+
import { isLoopbackHost } from '../settings.js';
|
|
5
|
+
import { CODE_PREFIXES, decodeSegments, isKitFile } from './local-code.js';
|
|
6
|
+
/** The author block catalog of a preview origin; `dev --remote` answers it with a stub. */
|
|
7
|
+
export const BLOCK_CATALOG_PATH = '/_foliwake/blocks';
|
|
8
|
+
const MISDIRECTED_TEXT = 'This listener answers only loopback host names (127.0.0.1, localhost, *.localhost).\n';
|
|
9
|
+
/** Content-addressed media of the deployed origin: the only /media paths fetched. */
|
|
10
|
+
export const REMOTE_MEDIA_PATTERN = /^\/media\/[0-9a-f]{64}\.(?:jpg|jpeg|png|gif|webp|avif)$/;
|
|
11
|
+
/** Browser cache of proxied media: short, private, not immutable. */
|
|
12
|
+
export const REMOTE_MEDIA_CACHE = 'private, max-age=300';
|
|
13
|
+
const MAX_PATH_LENGTH = 2048;
|
|
14
|
+
const MAX_QUERY_LENGTH = 2048;
|
|
15
|
+
export const DEFAULT_REMOTE_TIMEOUT_MS = 15000;
|
|
16
|
+
const RELEASE_HEADER_VALUE = /^[a-z]{2}_[0-9a-f]{8,64}$/;
|
|
17
|
+
export const DEPLOYED_CODE_TEXT = 'Deployed code is never loaded in local development: foliwake dev --remote serves components/, scripts/ and ' +
|
|
18
|
+
'styles/ from this checkout.\n';
|
|
19
|
+
/** Classifies a raw request path (without the query). Unsafe paths are `not-found` and never reach the remote site. */
|
|
20
|
+
export function classifyRemoteRoute(rawPath) {
|
|
21
|
+
if (!rawPath.startsWith('/') || rawPath.length > MAX_PATH_LENGTH)
|
|
22
|
+
return { kind: 'not-found' };
|
|
23
|
+
let segments;
|
|
24
|
+
try {
|
|
25
|
+
segments = decodeSegments(rawPath);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return { kind: 'not-found' };
|
|
29
|
+
}
|
|
30
|
+
const [first, ...rest] = segments;
|
|
31
|
+
if (CODE_PREFIXES.includes(first) || isKitFile(segments))
|
|
32
|
+
return { kind: 'code', prefix: first, rest };
|
|
33
|
+
if (first === 'media')
|
|
34
|
+
return REMOTE_MEDIA_PATTERN.test(rawPath) ? { kind: 'media', path: rawPath } : { kind: 'not-found' };
|
|
35
|
+
if (first === 'code')
|
|
36
|
+
return { kind: 'deployed-code' };
|
|
37
|
+
if (first === '_dev' || rawPath === BLOCK_CATALOG_PATH || rawPath.startsWith(`${BLOCK_CATALOG_PATH}/`))
|
|
38
|
+
return { kind: 'dev', path: rawPath };
|
|
39
|
+
// `//host` (an empty first segment) and empty inner segments are never forwarded.
|
|
40
|
+
if (segments.slice(0, -1).some((s) => s === ''))
|
|
41
|
+
return { kind: 'not-found' };
|
|
42
|
+
if (segments.some((s) => s.startsWith('.')))
|
|
43
|
+
return { kind: 'not-found' };
|
|
44
|
+
if (/[\u0000-\u0020\u007f]/.test(rawPath))
|
|
45
|
+
return { kind: 'not-found' };
|
|
46
|
+
return { kind: 'page', path: rawPath };
|
|
47
|
+
}
|
|
48
|
+
/** The remote URL of a page or media path: always on `origin`, or null. */
|
|
49
|
+
export function remoteUrl(origin, rawPath, query) {
|
|
50
|
+
if (query.length > MAX_QUERY_LENGTH || /[\u0000-\u0020\u007f#]/.test(query))
|
|
51
|
+
return null;
|
|
52
|
+
let url;
|
|
53
|
+
try {
|
|
54
|
+
url = new URL(rawPath + (query ? `?${query}` : ''), origin);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return url.origin === origin ? url : null;
|
|
60
|
+
}
|
|
61
|
+
// Host header: a loopback name with an explicit port.
|
|
62
|
+
function hostPort(hostHeader) {
|
|
63
|
+
const match = /^(?:\[[^\]]+\]|[^:]+):(\d{1,5})$/.exec(hostHeader.trim());
|
|
64
|
+
return match ? Number(match[1]) : null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The browser request may reach this listener only from itself: Host must be a
|
|
68
|
+
* loopback name with the listening port (DNS rebinding), and an Origin header,
|
|
69
|
+
* when present, must be this listener's own origin.
|
|
70
|
+
*/
|
|
71
|
+
export function checkLocalRequest(headers, port) {
|
|
72
|
+
const host = headers.host;
|
|
73
|
+
if (!isLoopbackHost(host) || hostPort(host ?? '') !== port) {
|
|
74
|
+
return { ok: false, status: 421, message: `${MISDIRECTED_TEXT.trimEnd()} Use http://127.0.0.1:${port}/.\n` };
|
|
75
|
+
}
|
|
76
|
+
const origin = headers.origin;
|
|
77
|
+
if (origin !== undefined && origin.toLowerCase() !== `http://${(host ?? '').trim().toLowerCase()}`) {
|
|
78
|
+
return { ok: false, status: 403, message: 'Requests from other origins are refused by foliwake dev --remote.\n' };
|
|
79
|
+
}
|
|
80
|
+
return { ok: true };
|
|
81
|
+
}
|
|
82
|
+
const ACCEPT_LANGUAGE = /^[A-Za-z0-9*,;=. -]{1,256}$/;
|
|
83
|
+
/**
|
|
84
|
+
* The complete set of headers sent to the remote site: fixed values, a
|
|
85
|
+
* validated Accept-Language and the configured Authorization. Nothing else
|
|
86
|
+
* from the browser request is forwarded (no cookies, no browser credentials).
|
|
87
|
+
*/
|
|
88
|
+
export function remoteRequestHeaders({ kind, acceptLanguage, authorization, }) {
|
|
89
|
+
const headers = {
|
|
90
|
+
Accept: kind === 'page' ? 'text/html,application/xhtml+xml;q=0.9,*/*;q=0.1' : 'image/avif,image/webp,image/*;q=0.8',
|
|
91
|
+
'User-Agent': 'foliwake-dev',
|
|
92
|
+
};
|
|
93
|
+
if (kind === 'page')
|
|
94
|
+
headers['Cache-Control'] = 'no-cache';
|
|
95
|
+
if (typeof acceptLanguage === 'string' && ACCEPT_LANGUAGE.test(acceptLanguage))
|
|
96
|
+
headers['Accept-Language'] = acceptLanguage;
|
|
97
|
+
if (authorization)
|
|
98
|
+
headers.Authorization = authorization;
|
|
99
|
+
return headers;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The only remote response headers passed to the browser: the release IDs of
|
|
103
|
+
* the deployed site (validated). Set-Cookie, WWW-Authenticate, caching,
|
|
104
|
+
* hop-by-hop and every other header are dropped.
|
|
105
|
+
*/
|
|
106
|
+
export function pickRemoteHeaders(headers) {
|
|
107
|
+
const picked = {};
|
|
108
|
+
for (const name of ['X-Preview-Release', 'X-Code-Release']) {
|
|
109
|
+
const value = headers.get(name);
|
|
110
|
+
if (value && RELEASE_HEADER_VALUE.test(value))
|
|
111
|
+
picked[name] = value;
|
|
112
|
+
}
|
|
113
|
+
return picked;
|
|
114
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Server } from 'node:http';
|
|
2
|
+
export type StopListeners = () => Promise<void>;
|
|
3
|
+
/** How a server registers its stop. */
|
|
4
|
+
export type OnStop = (stop: StopListeners) => void;
|
|
5
|
+
/** How long a stop waits for the work that runs. */
|
|
6
|
+
export declare const STOP_TIMEOUT_MS = 30000;
|
|
7
|
+
/** Closes `server`: settles when it has stopped listening and its open connections have ended. */
|
|
8
|
+
export declare function closed(server: Pick<Server, 'close'>): Promise<void>;
|
|
9
|
+
export interface SignalStop {
|
|
10
|
+
stop: StopListeners;
|
|
11
|
+
exit: (code: number) => void;
|
|
12
|
+
warn: (line: string) => void;
|
|
13
|
+
signals?: Pick<NodeJS.EventEmitter, 'on'>;
|
|
14
|
+
timeoutMs?: number;
|
|
15
|
+
}
|
|
16
|
+
/** Installs the SIGINT/SIGTERM handlers of a server command; resolves when it has stopped. */
|
|
17
|
+
export declare function stopOnSignals({ stop, exit, warn, signals, timeoutMs }: SignalStop): Promise<void>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** How long a stop waits for the work that runs. */
|
|
2
|
+
export const STOP_TIMEOUT_MS = 30_000;
|
|
3
|
+
/** Closes `server`: settles when it has stopped listening and its open connections have ended. */
|
|
4
|
+
export function closed(server) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
server.close((error) => (error ? reject(error) : resolve()));
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
/** Runs `stop` within `timeoutMs`: resolves to the exit code (0, or 1 with a warning). */
|
|
10
|
+
async function stopWithin(stop, timeoutMs, warn) {
|
|
11
|
+
let timer;
|
|
12
|
+
const timeout = new Promise((resolve) => {
|
|
13
|
+
timer = setTimeout(() => resolve('timeout'), timeoutMs);
|
|
14
|
+
});
|
|
15
|
+
try {
|
|
16
|
+
const outcome = await Promise.race([stop().then(() => 'stopped'), timeout]);
|
|
17
|
+
if (outcome === 'stopped')
|
|
18
|
+
return 0;
|
|
19
|
+
warn(`Warning: the work still running did not finish within ${timeoutMs / 1000} s; stopping without it.`);
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
warn(`Warning: stopping failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
clearTimeout(timer);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Installs the SIGINT/SIGTERM handlers of a server command; resolves when it has stopped. */
|
|
31
|
+
export function stopOnSignals({ stop, exit, warn, signals = process, timeoutMs = STOP_TIMEOUT_MS }) {
|
|
32
|
+
return new Promise((resolve) => {
|
|
33
|
+
let stopping = false;
|
|
34
|
+
const onSignal = () => {
|
|
35
|
+
if (stopping)
|
|
36
|
+
return warn('Stopping already: waiting for the work that runs; this signal is ignored.');
|
|
37
|
+
stopping = true;
|
|
38
|
+
void stopWithin(stop, timeoutMs, warn).then((code) => {
|
|
39
|
+
resolve();
|
|
40
|
+
exit(code);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
signals.on('SIGINT', onSignal);
|
|
44
|
+
signals.on('SIGTERM', onSignal);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type RemoteDevServer } from './remote-dev.js';
|
|
2
|
+
import { type OnStop } from './signal-stop.js';
|
|
3
|
+
export declare const DEFAULT_PORT = 3000;
|
|
4
|
+
/** A refused command line or configuration: printed as it is, exit 2. */
|
|
5
|
+
export declare class UsageError extends Error {
|
|
6
|
+
}
|
|
7
|
+
export interface RemoteDevOptions {
|
|
8
|
+
remote: 'preview' | 'live';
|
|
9
|
+
port?: number | undefined;
|
|
10
|
+
watch?: boolean | undefined;
|
|
11
|
+
polling?: boolean | undefined;
|
|
12
|
+
remoteUrl?: string | undefined;
|
|
13
|
+
remoteConfig?: string | undefined;
|
|
14
|
+
remoteAuthEnv?: string | undefined;
|
|
15
|
+
remoteAuthUser?: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** Starts remote mode and prints where it is; `onStop` gets what Ctrl+C runs. */
|
|
18
|
+
export declare function startRemoteDev(options: RemoteDevOptions, log: (line: string) => void, onStop: OnStop): Promise<RemoteDevServer>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// `foliwake dev --remote [preview|live]`: reads ./foliwake.remote.json (or --remote-url) and the named
|
|
2
|
+
// password variable only, starts the dev server and says where it is.
|
|
3
|
+
import { RemoteConfigError, readRemoteCredential, redactor, resolveRemoteTarget, } from './remote-config.js';
|
|
4
|
+
import { startRemoteDevServer } from './remote-dev.js';
|
|
5
|
+
import { closed } from './signal-stop.js';
|
|
6
|
+
export const DEFAULT_PORT = 3000;
|
|
7
|
+
/** A refused command line or configuration: printed as it is, exit 2. */
|
|
8
|
+
export class UsageError extends Error {
|
|
9
|
+
}
|
|
10
|
+
function liveReloadOf({ watch, polling }) {
|
|
11
|
+
if (watch !== true)
|
|
12
|
+
return false;
|
|
13
|
+
return polling === undefined ? true : { polling };
|
|
14
|
+
}
|
|
15
|
+
const defined = (name, value) => (value === undefined ? {} : { [name]: value });
|
|
16
|
+
function targetOf(options, cwd) {
|
|
17
|
+
const selection = {
|
|
18
|
+
channel: options.remote,
|
|
19
|
+
...defined('url', options.remoteUrl),
|
|
20
|
+
...defined('configFile', options.remoteConfig),
|
|
21
|
+
...defined('authEnv', options.remoteAuthEnv),
|
|
22
|
+
...defined('authUser', options.remoteAuthUser),
|
|
23
|
+
};
|
|
24
|
+
return resolveRemoteTarget(selection, cwd);
|
|
25
|
+
}
|
|
26
|
+
/** The target and its credential; a configuration problem is a UsageError. */
|
|
27
|
+
async function configured(options, cwd) {
|
|
28
|
+
try {
|
|
29
|
+
const target = await targetOf(options, cwd);
|
|
30
|
+
return { target, credential: readRemoteCredential(target, process.env) };
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (error instanceof RemoteConfigError)
|
|
34
|
+
throw new UsageError(error.message);
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function portOf(server) {
|
|
39
|
+
const address = server.address();
|
|
40
|
+
return address && typeof address === 'object' ? address.port : 0;
|
|
41
|
+
}
|
|
42
|
+
const WATCHING = 'Watching components/, scripts/ and styles/; open pages reload after changes and fetch the current remote ' +
|
|
43
|
+
'page. The remote site is never polled. Press Ctrl+C to stop.';
|
|
44
|
+
const NOT_WATCHING = 'Refresh the browser to see code edits and the current remote content (or start with --watch). ' +
|
|
45
|
+
'Press Ctrl+C to stop.';
|
|
46
|
+
function startLines(target, cwd, port, watching) {
|
|
47
|
+
const auth = target.auth
|
|
48
|
+
? `user "${target.auth.username}", password from $${target.auth.passwordEnv}`
|
|
49
|
+
: 'no credentials';
|
|
50
|
+
const base = `http://127.0.0.1:${port}`;
|
|
51
|
+
return [
|
|
52
|
+
`Remote ${target.channel}: ${target.origin} (${target.from}; ${auth})`,
|
|
53
|
+
`Local code: ${cwd}/components, scripts, styles`,
|
|
54
|
+
`Open ${base}/ (diagnostics: ${base}/_dev/diagnostics; the block catalog needs the engine)`,
|
|
55
|
+
watching ? WATCHING : NOT_WATCHING,
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
async function listen(options) {
|
|
59
|
+
try {
|
|
60
|
+
return await startRemoteDevServer(options);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error?.code !== 'EADDRINUSE')
|
|
64
|
+
throw error;
|
|
65
|
+
throw new UsageError(`Port ${options.port} is already in use. Stop the other process or pass --port <n>.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Starts remote mode and prints where it is; `onStop` gets what Ctrl+C runs. */
|
|
69
|
+
export async function startRemoteDev(options, log, onStop) {
|
|
70
|
+
const cwd = process.cwd();
|
|
71
|
+
const { target, credential } = await configured(options, cwd);
|
|
72
|
+
const liveReload = liveReloadOf(options);
|
|
73
|
+
const port = options.port ?? DEFAULT_PORT;
|
|
74
|
+
const redact = redactor(credential.secrets);
|
|
75
|
+
const server = await listen({ cwd, port, target, authorization: credential.authorization, redact, liveReload });
|
|
76
|
+
for (const line of startLines(target, cwd, portOf(server), liveReload !== false))
|
|
77
|
+
log(line);
|
|
78
|
+
onStop(() => closed(server));
|
|
79
|
+
return server;
|
|
80
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createRemoteCaller, type RemoteCallerOptions } from './remote/remote-caller.js';
|
|
2
|
+
export { type CoreError, CoreFailure } from './remote/core-failure.js';
|
|
3
|
+
export { remoteCallerFor, tokenFor } from './remote/session.js';
|
|
4
|
+
export { type Target, resolveTarget, serverOrigin } from './remote/servers.js';
|
|
5
|
+
export { main } from './main.js';
|
|
6
|
+
export { chooseTarget, type TargetFlags } from './local-target.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @foliwake/cli as a library: the remote caller and the server selection the `foliwake` command uses, for
|
|
2
|
+
// tools that call a Foliwake server the same way (same sign-ins, same FOLIWAKE_SERVER/FOLIWAKE_TOKEN rules).
|
|
3
|
+
export { createRemoteCaller } from './remote/remote-caller.js';
|
|
4
|
+
export { CoreFailure } from './remote/core-failure.js';
|
|
5
|
+
export { remoteCallerFor, tokenFor } from './remote/session.js';
|
|
6
|
+
export { resolveTarget, serverOrigin } from './remote/servers.js';
|
|
7
|
+
export { main } from './main.js';
|
|
8
|
+
export { chooseTarget } from './local-target.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type Severity = 'error' | 'warning';
|
|
2
|
+
/** A diagnostic: every key present. */
|
|
3
|
+
export interface Diagnostic {
|
|
4
|
+
code: string;
|
|
5
|
+
severity: Severity;
|
|
6
|
+
file: string;
|
|
7
|
+
line: number;
|
|
8
|
+
column: number;
|
|
9
|
+
component: string | null;
|
|
10
|
+
field: string | null;
|
|
11
|
+
message: string;
|
|
12
|
+
fix: string | null;
|
|
13
|
+
}
|
|
14
|
+
/** `file:line:column severity CODE component field: message`, and the fix on its own line. */
|
|
15
|
+
export declare function formatDiagnostic(diagnostic: Diagnostic): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// A diagnostic of the content rules, as the engine reports it, and its one-line form for a terminal.
|
|
2
|
+
/** `file:line:column severity CODE component field: message`, and the fix on its own line. */
|
|
3
|
+
export function formatDiagnostic(diagnostic) {
|
|
4
|
+
const { file, line, column, severity, code, component, field, message, fix } = diagnostic;
|
|
5
|
+
let head = `${file}:${line}:${column} ${severity} ${code}`;
|
|
6
|
+
if (component)
|
|
7
|
+
head += ` ${component}`;
|
|
8
|
+
if (field)
|
|
9
|
+
head += ` ${field}`;
|
|
10
|
+
head += `: ${message}`;
|
|
11
|
+
return fix ? `${head}\n fix: ${fix}` : head;
|
|
12
|
+
}
|