@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,37 @@
|
|
|
1
|
+
import { COMMAND } from '../settings.js';
|
|
2
|
+
const C = COMMAND;
|
|
3
|
+
/** The lines `foliwake source list` prints. */
|
|
4
|
+
function notSyncedNote(source) {
|
|
5
|
+
if (source.mode !== 'snapshot')
|
|
6
|
+
return ' (preview and publish read the folder at command start)';
|
|
7
|
+
return ` — preview and publish need \`${C} source sync --source ${source.id}\``;
|
|
8
|
+
}
|
|
9
|
+
export function sourceListLines({ site, sources, identity, registryProblems }) {
|
|
10
|
+
const lines = [`Site ${site}: ${sources.length} content source(s)`];
|
|
11
|
+
for (const source of sources) {
|
|
12
|
+
const flags = [source.status, source.enabled ? 'enabled' : 'disabled'].join(', ');
|
|
13
|
+
lines.push(`\n${source.id} ${source.displayName} (${source.plugin}) owns ${source.owns.join(' ')} ${flags}`);
|
|
14
|
+
if (source.problem)
|
|
15
|
+
lines.push(` ${source.problem}`);
|
|
16
|
+
const selected = source.selected;
|
|
17
|
+
lines.push(selected
|
|
18
|
+
? ` selected ${selected.snapshot} (sequence ${selected.sequence}) · ${selected.selected_at} · ` +
|
|
19
|
+
`${selected.items} page(s), ${selected.warnings} ` +
|
|
20
|
+
`warning(s)${selected.current ? '' : ' · configuration changed since'}`
|
|
21
|
+
: ` not synced${notSyncedNote(source)}`);
|
|
22
|
+
const latest = source.latestAttempt;
|
|
23
|
+
if (latest?.status === 'running' && latest.runner === 'foreign-host')
|
|
24
|
+
lines.push(` attempt ${latest.sequence} is running on another host (cannot be checked from here)`);
|
|
25
|
+
if (source.stale && latest)
|
|
26
|
+
lines.push(` latest sync (attempt ${latest.sequence}, ${latest.finished_at ?? '?'}) was NOT accepted: ` +
|
|
27
|
+
`${latest.code ?? latest.status}, ${latest.errors} error(s)`);
|
|
28
|
+
}
|
|
29
|
+
const { ledger, verifiedHeads } = identity;
|
|
30
|
+
if (ledger.observed + ledger.bound + ledger.published > 0)
|
|
31
|
+
lines.push(`\nPage ledger: ${ledger.published} published, ${ledger.bound} reserved, ${ledger.observed} observed without ` +
|
|
32
|
+
`owner; verified ${verifiedHeads.map((h) => `${h.channel} generation ${h.generation}`).join(', ') || 'never'}.`);
|
|
33
|
+
for (const problem of registryProblems)
|
|
34
|
+
lines.push(`\nPlugin registry: ${problem.code}: ${problem.pluginId ?? problem.package ?? 'the file'}: ${problem.message} ` +
|
|
35
|
+
`(--debug says why)`);
|
|
36
|
+
return lines;
|
|
37
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// `source sync` for people: per source a header line (what happened, what did not change, how many
|
|
2
|
+
// problems), then every problem grouped by page with its code; snapshot, attempt and the engine's text with --verbose.
|
|
3
|
+
import { COMMAND } from '../settings.js';
|
|
4
|
+
import { syncProblems } from '../lib/sync-problems.js';
|
|
5
|
+
import { canDim, headerLine, problemLines } from './problems.js';
|
|
6
|
+
const C = COMMAND;
|
|
7
|
+
// Results stored before `problems` existed: made from their diagnostics (no page facts: the rules are not at hand).
|
|
8
|
+
const problemsOf = (result) => result.problems ?? syncProblems(result.diagnostics);
|
|
9
|
+
function header(result, problems) {
|
|
10
|
+
const name = `Source ${result.source}`;
|
|
11
|
+
if (result.status === 'selected')
|
|
12
|
+
return headerLine([
|
|
13
|
+
`${name}: new changes accepted (${result.items.length} page(s))`,
|
|
14
|
+
'preview and live unchanged until you update them',
|
|
15
|
+
], problems);
|
|
16
|
+
if (result.status === 'unchanged')
|
|
17
|
+
return headerLine([`${name}: no changes (${result.items.length} page(s))`], problems);
|
|
18
|
+
if (result.status === 'skipped')
|
|
19
|
+
return `${name}: skipped (${result.message}).`;
|
|
20
|
+
if (result.status === 'cancelled')
|
|
21
|
+
return headerLine([`${name}: sync cancelled`, 'nothing changed'], problems);
|
|
22
|
+
const kept = result.selected ? 'the previously accepted content stays' : 'nothing was accepted before';
|
|
23
|
+
return headerLine([`${name}: new changes not accepted`, kept, 'preview and published pages unchanged'], problems);
|
|
24
|
+
}
|
|
25
|
+
function details(result) {
|
|
26
|
+
const lines = [
|
|
27
|
+
` status ${result.status}${result.code ? ` (${result.code})` : ''}` +
|
|
28
|
+
(result.attempt === null ? '' : `, attempt ${result.attempt}`),
|
|
29
|
+
];
|
|
30
|
+
if (result.snapshot)
|
|
31
|
+
lines.push(` snapshot ${result.snapshot}`);
|
|
32
|
+
if (result.selected)
|
|
33
|
+
lines.push(` selected snapshot ${result.selected.snapshot} (since ${result.selected.selected_at})`);
|
|
34
|
+
if (result.mode === 'working-folder')
|
|
35
|
+
lines.push(' working folder: preview and publish read the folder at command start; this snapshot validates it');
|
|
36
|
+
if (result.revision)
|
|
37
|
+
lines.push(` upstream revision ${result.revision}`);
|
|
38
|
+
lines.push(` engine: ${result.message}`);
|
|
39
|
+
return lines;
|
|
40
|
+
}
|
|
41
|
+
export function syncLines(operation, validationCode, { verbose = false, dim = canDim() } = {}) {
|
|
42
|
+
const results = (operation.result ?? { results: [] }).results;
|
|
43
|
+
if (results.length === 0 && operation.state !== 'succeeded')
|
|
44
|
+
return [
|
|
45
|
+
`sync ${operation.state}${operation.error ? ` (${operation.error.code}): ${operation.error.message}` : ''}`,
|
|
46
|
+
];
|
|
47
|
+
const lines = [];
|
|
48
|
+
for (const result of results) {
|
|
49
|
+
const problems = problemsOf(result);
|
|
50
|
+
lines.push(header(result, problems));
|
|
51
|
+
// A failure without any diagnostic (a refused or failed attempt): its reason is the engine's message.
|
|
52
|
+
if (!result.accepted && result.status !== 'skipped' && problems.length === 0 && !verbose)
|
|
53
|
+
lines.push(` ${result.message}`);
|
|
54
|
+
lines.push(...problemLines(problems, { verbose, indent: ' ', dim }));
|
|
55
|
+
if (verbose)
|
|
56
|
+
lines.push(...details(result));
|
|
57
|
+
}
|
|
58
|
+
lines.push('Sync changes neither preview nor live.');
|
|
59
|
+
if (validationCode)
|
|
60
|
+
lines.push(`Checked against code ${validationCode}, for its migration: continue with \`${C} migration prepare ` +
|
|
61
|
+
`${validationCode}\`. Until it commits, preview and publish compile with live code and can refuse this ` +
|
|
62
|
+
`content.`);
|
|
63
|
+
if (!verbose && results.some((result) => !result.accepted && result.status !== 'skipped'))
|
|
64
|
+
lines.push('Technical details (snapshot, attempt, engine text): --verbose.');
|
|
65
|
+
return lines;
|
|
66
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The command people type. */
|
|
2
|
+
export declare const COMMAND = "foliwake";
|
|
3
|
+
/** Reads `FOLIWAKE_<name>` from the environment, e.g. setting('SERVER'). Empty counts as unset. */
|
|
4
|
+
export declare function setting(name: string, env?: NodeJS.ProcessEnv): string | undefined;
|
|
5
|
+
/** `$FOLIWAKE_CONFIG_DIR`, else `$XDG_CONFIG_HOME/foliwake`, else `~/.config/foliwake`. */
|
|
6
|
+
export declare function configDir(env?: NodeJS.ProcessEnv): string;
|
|
7
|
+
/** True for 127.0.0.1, localhost, [::1] and *.localhost, with or without a port. */
|
|
8
|
+
export declare function isLoopbackHost(hostHeader: string | undefined): boolean;
|
|
9
|
+
/** Opens a URL in this computer's browser (open, xdg-open; nothing on Windows); callers print it too. */
|
|
10
|
+
export declare function openBrowser(url: string): void;
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// The environment and local folders this CLI reads: FOLIWAKE_* settings, the settings folder, the
|
|
2
|
+
// browser, and loopback hosts (the only ones plain http may name).
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
/** The command people type. */
|
|
7
|
+
export const COMMAND = 'foliwake';
|
|
8
|
+
const ENV_PREFIX = 'FOLIWAKE_';
|
|
9
|
+
/** Reads `FOLIWAKE_<name>` from the environment, e.g. setting('SERVER'). Empty counts as unset. */
|
|
10
|
+
export function setting(name, env = process.env) {
|
|
11
|
+
const value = env[`${ENV_PREFIX}${name}`];
|
|
12
|
+
return value === '' ? undefined : value;
|
|
13
|
+
}
|
|
14
|
+
/** `$FOLIWAKE_CONFIG_DIR`, else `$XDG_CONFIG_HOME/foliwake`, else `~/.config/foliwake`. */
|
|
15
|
+
export function configDir(env = process.env) {
|
|
16
|
+
const own = setting('CONFIG_DIR', env);
|
|
17
|
+
if (own)
|
|
18
|
+
return path.resolve(own);
|
|
19
|
+
const xdg = env.XDG_CONFIG_HOME;
|
|
20
|
+
return path.join(xdg && path.isAbsolute(xdg) ? xdg : path.join(os.homedir(), '.config'), 'foliwake');
|
|
21
|
+
}
|
|
22
|
+
/** True for 127.0.0.1, localhost, [::1] and *.localhost, with or without a port. */
|
|
23
|
+
export function isLoopbackHost(hostHeader) {
|
|
24
|
+
if (typeof hostHeader !== 'string')
|
|
25
|
+
return false;
|
|
26
|
+
const host = hostHeader.trim().toLowerCase();
|
|
27
|
+
if (host === '')
|
|
28
|
+
return false;
|
|
29
|
+
if (host.startsWith('['))
|
|
30
|
+
return /^\[::1\](:\d+)?$/.test(host);
|
|
31
|
+
const match = /^([^:]+)(:\d+)?$/.exec(host);
|
|
32
|
+
if (!match)
|
|
33
|
+
return false;
|
|
34
|
+
const name = match[1].endsWith('.') ? match[1].slice(0, -1) : match[1];
|
|
35
|
+
return name === '127.0.0.1' || name === 'localhost' || name.endsWith('.localhost');
|
|
36
|
+
}
|
|
37
|
+
/** Opens a URL in this computer's browser (open, xdg-open; nothing on Windows); callers print it too. */
|
|
38
|
+
export function openBrowser(url) {
|
|
39
|
+
const command = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? null : 'xdg-open';
|
|
40
|
+
if (!command)
|
|
41
|
+
return;
|
|
42
|
+
const child = spawn(command, [url], { stdio: 'ignore', detached: true });
|
|
43
|
+
child.on('error', () => { });
|
|
44
|
+
child.unref();
|
|
45
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type Json = Record<string, unknown>;
|
|
2
|
+
export declare function parseValue(text: string): unknown;
|
|
3
|
+
/** A copy of `entry` with `dotted` set to `value`, or removed when `value` is undefined. */
|
|
4
|
+
export declare function withPath(entry: Json, dotted: string, value: unknown): Json;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function parseValue(text) {
|
|
2
|
+
try {
|
|
3
|
+
return JSON.parse(text);
|
|
4
|
+
}
|
|
5
|
+
catch {
|
|
6
|
+
return text;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const isContainer = (value) => value !== null && typeof value === 'object';
|
|
10
|
+
/** A copy of `entry` with `dotted` set to `value`, or removed when `value` is undefined. */
|
|
11
|
+
export function withPath(entry, dotted, value) {
|
|
12
|
+
const keys = dotted.split('.');
|
|
13
|
+
if (keys.some((key) => key === '' || key === '__proto__' || key === 'constructor' || key === 'prototype'))
|
|
14
|
+
throw new Error(`"${dotted}" is not a settings path`);
|
|
15
|
+
const copy = structuredClone(entry);
|
|
16
|
+
let at = copy;
|
|
17
|
+
for (const key of keys.slice(0, -1)) {
|
|
18
|
+
const next = Array.isArray(at) ? at[Number(key)] : at[key];
|
|
19
|
+
if (!isContainer(next)) {
|
|
20
|
+
if (value === undefined)
|
|
21
|
+
return copy;
|
|
22
|
+
const made = {};
|
|
23
|
+
if (Array.isArray(at))
|
|
24
|
+
at[Number(key)] = made;
|
|
25
|
+
else
|
|
26
|
+
at[key] = made;
|
|
27
|
+
at = made;
|
|
28
|
+
}
|
|
29
|
+
else
|
|
30
|
+
at = next;
|
|
31
|
+
}
|
|
32
|
+
const last = keys[keys.length - 1];
|
|
33
|
+
if (Array.isArray(at)) {
|
|
34
|
+
if (value === undefined)
|
|
35
|
+
at.splice(Number(last), 1);
|
|
36
|
+
else
|
|
37
|
+
at[Number(last)] = value;
|
|
38
|
+
}
|
|
39
|
+
else if (value === undefined)
|
|
40
|
+
delete at[last];
|
|
41
|
+
else
|
|
42
|
+
at[last] = value;
|
|
43
|
+
return copy;
|
|
44
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const DRIVE_PLUGIN = "google-drive-markdown";
|
|
2
|
+
export declare const DEFAULT_DRIVE_KEY = "FOLIWAKE_GOOGLE_SA_KEY";
|
|
3
|
+
export type Parsed<T> = {
|
|
4
|
+
ok: true;
|
|
5
|
+
value: T;
|
|
6
|
+
} | {
|
|
7
|
+
ok: false;
|
|
8
|
+
problem: string;
|
|
9
|
+
};
|
|
10
|
+
/** The folder ID of a Drive folder link (`/drive/folders/<id>`, `/drive/u/N/folders/<id>`, `?id=`) or a bare ID. */
|
|
11
|
+
export declare function driveFolderId(text: string): Parsed<string>;
|
|
12
|
+
export interface EntryFlags {
|
|
13
|
+
plugin: string;
|
|
14
|
+
id: string;
|
|
15
|
+
'display-name'?: string | undefined;
|
|
16
|
+
owns?: string[] | undefined;
|
|
17
|
+
folder?: string | undefined;
|
|
18
|
+
subfolder?: string | undefined;
|
|
19
|
+
identity?: string | undefined;
|
|
20
|
+
key?: string | undefined;
|
|
21
|
+
repository?: string | undefined;
|
|
22
|
+
branch?: string | undefined;
|
|
23
|
+
token?: string | undefined;
|
|
24
|
+
'base-url'?: string | undefined;
|
|
25
|
+
language?: string[] | undefined;
|
|
26
|
+
'basic-user'?: string | undefined;
|
|
27
|
+
'basic-password'?: string | undefined;
|
|
28
|
+
}
|
|
29
|
+
type Entry = Record<string, unknown>;
|
|
30
|
+
/** The entry of the flags, or the first problem. `mappings`: the rules of `--mappings`, as written. */
|
|
31
|
+
export declare function entryOf(flags: EntryFlags, mappings: unknown): Parsed<Entry>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// The source entry `foliwake source add` builds from its flags: the same entry a person would write
|
|
2
|
+
// into the site's `sources`, checked afterwards by core (sources.probe, sources.add). A Drive folder
|
|
3
|
+
// link is reduced to its folder ID here and never requested.
|
|
4
|
+
export const DRIVE_PLUGIN = 'google-drive-markdown';
|
|
5
|
+
export const DEFAULT_DRIVE_KEY = 'FOLIWAKE_GOOGLE_SA_KEY';
|
|
6
|
+
const DRIVE_ID = /^[A-Za-z0-9_-]{10,200}$/;
|
|
7
|
+
const FILE_LINK = /\/(?:file|document|spreadsheets|presentation)\/d\//;
|
|
8
|
+
function driveUrlId(url) {
|
|
9
|
+
const folder = /\/drive\/(?:u\/\d+\/)?folders\/([^/?#]+)/.exec(url.pathname)?.[1];
|
|
10
|
+
return folder ?? url.searchParams.get('id');
|
|
11
|
+
}
|
|
12
|
+
/** The folder ID of a Drive folder link (`/drive/folders/<id>`, `/drive/u/N/folders/<id>`, `?id=`) or a bare ID. */
|
|
13
|
+
export function driveFolderId(text) {
|
|
14
|
+
const trimmed = text.trim();
|
|
15
|
+
if (DRIVE_ID.test(trimmed))
|
|
16
|
+
return { ok: true, value: trimmed };
|
|
17
|
+
let url;
|
|
18
|
+
try {
|
|
19
|
+
url = new URL(trimmed);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return { ok: false, problem: 'Paste the folder link from the browser, or its ID.' };
|
|
23
|
+
}
|
|
24
|
+
if (FILE_LINK.test(url.pathname))
|
|
25
|
+
return { ok: false, problem: 'This is a file link; paste the folder that holds the pages.' };
|
|
26
|
+
const id = driveUrlId(url);
|
|
27
|
+
if (id === null || !DRIVE_ID.test(id))
|
|
28
|
+
return { ok: false, problem: 'This link names no Drive folder; paste the folder link or its ID.' };
|
|
29
|
+
return { ok: true, value: id };
|
|
30
|
+
}
|
|
31
|
+
function driveEntry(flags) {
|
|
32
|
+
if (flags.folder === undefined)
|
|
33
|
+
return { ok: false, problem: '--folder is required: the Drive folder link or ID.' };
|
|
34
|
+
const folder = driveFolderId(flags.folder);
|
|
35
|
+
if (!folder.ok)
|
|
36
|
+
return folder;
|
|
37
|
+
const settings = { auth: 'service-account', folderId: folder.value, identity: flags.identity ?? 'file-id' };
|
|
38
|
+
if (flags.subfolder)
|
|
39
|
+
settings.subfolder = flags.subfolder;
|
|
40
|
+
return { ok: true, value: { settings, credentials: { serviceAccountKey: flags.key ?? DEFAULT_DRIVE_KEY } } };
|
|
41
|
+
}
|
|
42
|
+
function gitEntry(flags) {
|
|
43
|
+
if (flags.repository === undefined)
|
|
44
|
+
return { ok: false, problem: '--repository is required: the https address of the repository.' };
|
|
45
|
+
if (/^(?:git@|ssh:|git:)/.test(flags.repository)) {
|
|
46
|
+
return {
|
|
47
|
+
ok: false,
|
|
48
|
+
problem: 'Use the https address; Foliwake reads over HTTPS with a token, no SSH key is needed.',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const settings = { repository: flags.repository, branch: flags.branch ?? 'main' };
|
|
52
|
+
if (flags.subfolder)
|
|
53
|
+
settings.subfolder = flags.subfolder;
|
|
54
|
+
return { ok: true, value: { settings, ...(flags.token ? { credentials: { token: flags.token } } : {}) } };
|
|
55
|
+
}
|
|
56
|
+
function drupalEntry(flags) {
|
|
57
|
+
if (flags['base-url'] === undefined)
|
|
58
|
+
return { ok: false, problem: '--base-url is required: the Drupal site address.' };
|
|
59
|
+
const languages = (flags.language ?? []).map((langcode) => ({ langcode }));
|
|
60
|
+
if (languages.length === 0)
|
|
61
|
+
return { ok: false, problem: 'Name at least one --language, the default one first.' };
|
|
62
|
+
const credentials = {};
|
|
63
|
+
if (flags['basic-user'])
|
|
64
|
+
credentials.username = flags['basic-user'];
|
|
65
|
+
if (flags['basic-password'])
|
|
66
|
+
credentials.password = flags['basic-password'];
|
|
67
|
+
const extra = Object.keys(credentials).length ? { credentials } : {};
|
|
68
|
+
return { ok: true, value: { settings: { baseUrl: flags['base-url'], languages }, ...extra } };
|
|
69
|
+
}
|
|
70
|
+
const BUILDERS = {
|
|
71
|
+
[DRIVE_PLUGIN]: driveEntry,
|
|
72
|
+
'git-markdown': gitEntry,
|
|
73
|
+
drupal: drupalEntry,
|
|
74
|
+
};
|
|
75
|
+
/** The entry of the flags, or the first problem. `mappings`: the rules of `--mappings`, as written. */
|
|
76
|
+
export function entryOf(flags, mappings) {
|
|
77
|
+
const build = BUILDERS[flags.plugin];
|
|
78
|
+
if (!build)
|
|
79
|
+
return { ok: false, problem: `--plugin must be one of ${Object.keys(BUILDERS).join(', ')}.` };
|
|
80
|
+
const built = build(flags);
|
|
81
|
+
if (!built.ok)
|
|
82
|
+
return built;
|
|
83
|
+
const entry = { id: flags.id, plugin: flags.plugin, owns: flags.owns ?? [], ...built.value };
|
|
84
|
+
if (flags['display-name'])
|
|
85
|
+
entry.displayName = flags['display-name'];
|
|
86
|
+
if (mappings !== undefined)
|
|
87
|
+
entry.mappings = mappings;
|
|
88
|
+
return { ok: true, value: entry };
|
|
89
|
+
}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// This package's name and version, as a server sees them: `X-Foliwake-Cli: @foliwake/cli/0.6.0`.
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
let own = null;
|
|
4
|
+
function packageJson() {
|
|
5
|
+
own ??= JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
6
|
+
return own;
|
|
7
|
+
}
|
|
8
|
+
export const cliVersion = () => packageJson().version;
|
|
9
|
+
/** `@foliwake/cli/<version>`: the client name sent to servers and shown on their approval page. */
|
|
10
|
+
export const clientName = () => `${packageJson().name}/${packageJson().version}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,115 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foliwake/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "The foliwake command without the engine: sign in to a Foliwake server and run its commands there (site status, sync, preview, publish, code deploy, branches, releases, sources, credentials, CI keys), and develop blocks against a remote preview.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=22.22"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/foliwake/foliwake-js.git",
|
|
14
|
+
"directory": "packages/cli"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://sdk.foliwake.dev/reference/packages/cli",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/foliwake/foliwake-js/issues"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"foliwake",
|
|
22
|
+
"cms",
|
|
23
|
+
"cli",
|
|
24
|
+
"deploy",
|
|
25
|
+
"preview"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"provenance": true
|
|
30
|
+
},
|
|
31
|
+
"foliwake": {
|
|
32
|
+
"coreApi": 1
|
|
33
|
+
},
|
|
34
|
+
"bin": {
|
|
35
|
+
"foliwake": "./dist/bin.js"
|
|
36
|
+
},
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"default": "./dist/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./bin": {
|
|
43
|
+
"types": "./dist/bin.d.ts",
|
|
44
|
+
"default": "./dist/bin.js"
|
|
45
|
+
},
|
|
46
|
+
"./local-runtime": {
|
|
47
|
+
"types": "./dist/local-runtime.d.ts",
|
|
48
|
+
"default": "./dist/local-runtime.js"
|
|
49
|
+
},
|
|
50
|
+
"./package.json": "./package.json"
|
|
51
|
+
},
|
|
52
|
+
"oclif": {
|
|
53
|
+
"bin": "foliwake",
|
|
54
|
+
"dirname": "foliwake",
|
|
55
|
+
"commands": "./dist/commands",
|
|
56
|
+
"topicSeparator": " ",
|
|
57
|
+
"topics": {
|
|
58
|
+
"account": {
|
|
59
|
+
"description": "Accounts of this server: CI keys"
|
|
60
|
+
},
|
|
61
|
+
"branch": {
|
|
62
|
+
"description": "Branch previews"
|
|
63
|
+
},
|
|
64
|
+
"code": {
|
|
65
|
+
"description": "Code releases: prepare, release and roll back the site's JS/CSS"
|
|
66
|
+
},
|
|
67
|
+
"credential": {
|
|
68
|
+
"description": "Credential values the content sources name (stored on the server, never shown)"
|
|
69
|
+
},
|
|
70
|
+
"migration": {
|
|
71
|
+
"description": "Whole-site rebuilds against new code, released as one"
|
|
72
|
+
},
|
|
73
|
+
"operation": {
|
|
74
|
+
"description": "Long operations: their state, cancellation and recovery"
|
|
75
|
+
},
|
|
76
|
+
"page": {
|
|
77
|
+
"description": "Working pages"
|
|
78
|
+
},
|
|
79
|
+
"project": {
|
|
80
|
+
"description": "This project folder and the site it is linked to"
|
|
81
|
+
},
|
|
82
|
+
"release": {
|
|
83
|
+
"description": "Live site releases"
|
|
84
|
+
},
|
|
85
|
+
"site": {
|
|
86
|
+
"description": "Sites on the server"
|
|
87
|
+
},
|
|
88
|
+
"source": {
|
|
89
|
+
"description": "Content sources and their plugins"
|
|
90
|
+
},
|
|
91
|
+
"servers": {
|
|
92
|
+
"description": "The Foliwake servers this computer is signed in to"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"dependencies": {
|
|
97
|
+
"@clack/prompts": "1.8.1",
|
|
98
|
+
"@oclif/core": "4.14.0",
|
|
99
|
+
"chokidar": "6.0.0",
|
|
100
|
+
"parse5": "7.3.0",
|
|
101
|
+
"@foliwake/blocks-contract": "0.7.0",
|
|
102
|
+
"@foliwake/server": "0.7.0",
|
|
103
|
+
"@foliwake/core-contract": "0.7.0",
|
|
104
|
+
"@foliwake/site-check": "0.7.0",
|
|
105
|
+
"create-foliwake": "0.7.0",
|
|
106
|
+
"@foliwake/block-kit": "0.7.0"
|
|
107
|
+
},
|
|
108
|
+
"files": [
|
|
109
|
+
"dist/",
|
|
110
|
+
"!dist/**/*.map",
|
|
111
|
+
"LICENSE",
|
|
112
|
+
"README.md",
|
|
113
|
+
"CHANGELOG.md"
|
|
114
|
+
]
|
|
6
115
|
}
|