@foliwake/cli 0.0.0-stage → 0.6.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 +35 -0
- package/LICENSE +202 -0
- package/README.md +643 -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 +30 -0
- package/dist/commands/create.js +163 -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 +25 -0
- package/dist/commands/dev.js +89 -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 +49 -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 +21 -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 +91 -0
- package/dist/core-command.js +262 -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 +15 -0
- package/dist/dev/flags.js +43 -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 +5 -0
- package/dist/index.js +7 -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/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 +108 -3
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { CoreCaller, Operation, SiteCreateResult } from './core-types.js';
|
|
2
|
+
/** At most 512 KiB of bundle (the API's body is 1 MB, base64); the same limit as core's. */
|
|
3
|
+
export declare const MAX_BUNDLE_BYTES: number;
|
|
4
|
+
export interface ConnectRequest {
|
|
5
|
+
cwd: string;
|
|
6
|
+
/** Origin or host; default: FOLIWAKE_SERVER, then the only signed-in server (several: `pick`, else refused). */
|
|
7
|
+
server?: string | undefined;
|
|
8
|
+
/** In a terminal: asks which server when this computer is signed in to several. */
|
|
9
|
+
pick?: ServerPicker | undefined;
|
|
10
|
+
/** Replace a link of the folder to another server or site without asking (`--relink`). */
|
|
11
|
+
relink?: boolean | undefined;
|
|
12
|
+
/** In a terminal: asks whether to replace a link of the folder to another server or site. */
|
|
13
|
+
confirmRelink?: RelinkConfirm | undefined;
|
|
14
|
+
site: string;
|
|
15
|
+
org?: string | undefined;
|
|
16
|
+
repository?: string | null | undefined;
|
|
17
|
+
/** false: create the site without code; release 1 waits for the first `code prepare`. */
|
|
18
|
+
code: boolean;
|
|
19
|
+
env: NodeJS.ProcessEnv;
|
|
20
|
+
}
|
|
21
|
+
export interface ConnectIO {
|
|
22
|
+
out(text?: string): void;
|
|
23
|
+
err(text?: string): void;
|
|
24
|
+
/** For tests: the caller of a server (default: the signed-in remote caller). */
|
|
25
|
+
callerFor?: (origin: string) => CoreCaller;
|
|
26
|
+
}
|
|
27
|
+
export interface ConnectOutcome {
|
|
28
|
+
exit: number;
|
|
29
|
+
server: string | null;
|
|
30
|
+
operation: Operation | null;
|
|
31
|
+
result: SiteCreateResult | null;
|
|
32
|
+
}
|
|
33
|
+
export declare class ConnectRefused extends Error {
|
|
34
|
+
}
|
|
35
|
+
/** The project's commit as a bundle, or why there is none (then the site is created without code). */
|
|
36
|
+
/** `codeOnly`: changes in content/ do not count as dirty (pages are pushed as they are). */
|
|
37
|
+
export declare function projectCommit(cwd: string, env: NodeJS.ProcessEnv, { codeOnly }?: {
|
|
38
|
+
codeOnly?: boolean;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
bundle: string;
|
|
41
|
+
commit: string;
|
|
42
|
+
dirty: boolean;
|
|
43
|
+
} | {
|
|
44
|
+
none: string;
|
|
45
|
+
}>;
|
|
46
|
+
/** A server this computer knows: signed in (its account's e-mail when known), or signed out of. */
|
|
47
|
+
export interface KnownServer {
|
|
48
|
+
origin: string;
|
|
49
|
+
signedIn: boolean;
|
|
50
|
+
/** The signed-in account's e-mail address, when the server said it. */
|
|
51
|
+
account: string | null;
|
|
52
|
+
/** The server of the last `login` (the default of other commands). */
|
|
53
|
+
lastUsed: boolean;
|
|
54
|
+
/** How it is named in a list instead of its origin ("Foliwake Cloud (cloud)"). */
|
|
55
|
+
title?: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The servers to offer: those signed in to (the last used first, then by origin; a
|
|
59
|
+
* FOLIWAKE_SERVER with FOLIWAKE_TOKEN counts), then those signed out of, then Foliwake Cloud
|
|
60
|
+
* when not signed in to it (`withCloud`). Reads no token.
|
|
61
|
+
*/
|
|
62
|
+
export declare function knownServers(env: NodeJS.ProcessEnv, { withCloud }?: {
|
|
63
|
+
withCloud?: boolean;
|
|
64
|
+
}): Promise<KnownServer[]>;
|
|
65
|
+
/** How a server is shown in a list: its name or origin, the account and whether it was used last. */
|
|
66
|
+
export declare function serverLabel(server: KnownServer): string;
|
|
67
|
+
/** Asks which of these signed-in servers to use (in a terminal); null when no answer was given. */
|
|
68
|
+
export type ServerPicker = (servers: KnownServer[]) => Promise<string | null>;
|
|
69
|
+
/**
|
|
70
|
+
* Where a connect goes: --server, then FOLIWAKE_SERVER, then the only server this computer is
|
|
71
|
+
* signed in to. Signed in to several: asked with `pick` (a terminal), else refused with the list:
|
|
72
|
+
* never silently the last login.
|
|
73
|
+
*/
|
|
74
|
+
export declare function chooseServer(request: Pick<ConnectRequest, 'server' | 'env'>, pick?: ServerPicker): Promise<string>;
|
|
75
|
+
export declare function nextSteps(result: SiteCreateResult, { repository }: {
|
|
76
|
+
repository: string | null;
|
|
77
|
+
}): string[];
|
|
78
|
+
/** The signed-in caller of the server a request names. */
|
|
79
|
+
export declare function signedInTo(request: Pick<ConnectRequest, 'server' | 'env' | 'pick'>, io: ConnectIO): Promise<{
|
|
80
|
+
server: string;
|
|
81
|
+
core: CoreCaller;
|
|
82
|
+
}>;
|
|
83
|
+
/** The folder's link as read from .foliwake/connection.json: server and site when the file names them. */
|
|
84
|
+
export interface ExistingLink {
|
|
85
|
+
server: string | null;
|
|
86
|
+
site: string | null;
|
|
87
|
+
}
|
|
88
|
+
/** Asks whether to replace the folder's link `from` with `to`; true: replace. */
|
|
89
|
+
export type RelinkConfirm = (from: ExistingLink, to: {
|
|
90
|
+
server: string;
|
|
91
|
+
site: string;
|
|
92
|
+
}) => Promise<boolean>;
|
|
93
|
+
/**
|
|
94
|
+
* The folder's current link, or null when there is no .foliwake/connection.json. Any other content counts as a link
|
|
95
|
+
* (never silently replaced).
|
|
96
|
+
*/
|
|
97
|
+
export declare function existingLink(cwd: string): Promise<ExistingLink | null>;
|
|
98
|
+
export declare const describeLink: (link: ExistingLink) => string;
|
|
99
|
+
/**
|
|
100
|
+
* `site unlink`: removes the folder's .foliwake/connection.json. Nothing is sent and nothing changes
|
|
101
|
+
* on the server. Exit 0 unlinked, and 0 when the folder had no link (nothing to do, said plainly);
|
|
102
|
+
* 1 for a file this version cannot read, unless `force`.
|
|
103
|
+
*/
|
|
104
|
+
export declare function unlinkSite(request: {
|
|
105
|
+
cwd: string;
|
|
106
|
+
force: boolean;
|
|
107
|
+
env: NodeJS.ProcessEnv;
|
|
108
|
+
}, io: ConnectIO): Promise<{
|
|
109
|
+
exit: number;
|
|
110
|
+
unlinked: ExistingLink | null;
|
|
111
|
+
}>;
|
|
112
|
+
/** What `create` may offer: a new site when an admin somewhere, and the sites to link to. */
|
|
113
|
+
export declare function connectChoices(request: Pick<ConnectRequest, 'server' | 'env'>, io: ConnectIO): Promise<{
|
|
114
|
+
server: string;
|
|
115
|
+
mayCreate: boolean;
|
|
116
|
+
sites: string[];
|
|
117
|
+
}>;
|
|
118
|
+
/**
|
|
119
|
+
* `site link <id>`: the folder to an existing site the account may develop (admin or developer of its
|
|
120
|
+
* organisation). Nothing changes on the server. Exit 0 linked, 1 refused.
|
|
121
|
+
*/
|
|
122
|
+
export declare function linkSite(request: Pick<ConnectRequest, 'cwd' | 'server' | 'site' | 'env' | 'pick' | 'relink' | 'confirmRelink'>, io: ConnectIO): Promise<{
|
|
123
|
+
exit: number;
|
|
124
|
+
server: string | null;
|
|
125
|
+
site: {
|
|
126
|
+
id: string;
|
|
127
|
+
org: string;
|
|
128
|
+
liveUrl: string;
|
|
129
|
+
previewUrl: string;
|
|
130
|
+
} | null;
|
|
131
|
+
}>;
|
|
132
|
+
/** `site create <id>`: the project's site on the server. Exit 0 created, 1 refused or failed. */
|
|
133
|
+
export declare function createSite(request: ConnectRequest, io: ConnectIO): Promise<ConnectOutcome>;
|
package/dist/connect.js
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
// `foliwake site create <id>` and `foliwake site link <id>`, and `foliwake
|
|
2
|
+
// create`'s «Connect to a Foliwake server?». Create: the
|
|
3
|
+
// project's site on the signed-in server with `sites.create`, the project's
|
|
4
|
+
// commit sent as a Git bundle so release 1 has its code and pages, and what the
|
|
5
|
+
// user sets up next. Link: the folder to an existing site. Either works with any
|
|
6
|
+
// server the CLI is signed in to; it never prints a token, a key or a server path.
|
|
7
|
+
import { codeTokenName } from './lib/rules.js';
|
|
8
|
+
import { execFile } from 'node:child_process';
|
|
9
|
+
import { randomBytes } from 'node:crypto';
|
|
10
|
+
import { mkdir, mkdtemp, readFile, realpath, rm, stat, unlink, writeFile } from 'node:fs/promises';
|
|
11
|
+
import os from 'node:os';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { promisify } from 'node:util';
|
|
14
|
+
import { setting } from './settings.js';
|
|
15
|
+
import { COMMAND } from './settings.js';
|
|
16
|
+
import { CLOUD, CLOUD_NOTE, CLOUD_TITLE, cloudOrigin, issuerOf, nameOrigin, readProfiles, serverDisplay, serverName, serverOrigin, signInMoved, } from './remote/servers.js';
|
|
17
|
+
const C = COMMAND;
|
|
18
|
+
const run = promisify(execFile);
|
|
19
|
+
/** At most 512 KiB of bundle (the API's body is 1 MB, base64); the same limit as core's. */
|
|
20
|
+
export const MAX_BUNDLE_BYTES = 512 * 1024;
|
|
21
|
+
/** core's rule on the server, checked before anything is sent. */
|
|
22
|
+
const CREATED_SITE_ID = /^(?=.{1,12}$)[a-z](?:-?[a-z0-9])*$/;
|
|
23
|
+
const CONNECT_WAIT_MS = 10 * 60 * 1000;
|
|
24
|
+
export class ConnectRefused extends Error {
|
|
25
|
+
}
|
|
26
|
+
async function git(cwd, args) {
|
|
27
|
+
return (await run('git', args, { cwd, env: { ...process.env, GIT_TERMINAL_PROMPT: '0' }, maxBuffer: 16 << 20 })).stdout.trim();
|
|
28
|
+
}
|
|
29
|
+
/** The project's commit as a bundle, or why there is none (then the site is created without code). */
|
|
30
|
+
/** `codeOnly`: changes in content/ do not count as dirty (pages are pushed as they are). */
|
|
31
|
+
export async function projectCommit(cwd, env, { codeOnly = false } = {}) {
|
|
32
|
+
let top;
|
|
33
|
+
try {
|
|
34
|
+
top = await git(cwd, ['rev-parse', '--show-toplevel']);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return { none: 'the folder is not a Git repository' };
|
|
38
|
+
}
|
|
39
|
+
if ((await realpath(top)) !== (await realpath(cwd)))
|
|
40
|
+
return { none: 'the folder is inside another Git repository' };
|
|
41
|
+
let commit;
|
|
42
|
+
try {
|
|
43
|
+
commit = await git(cwd, ['rev-parse', '--verify', 'HEAD^{commit}']);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return { none: 'the repository has no commit yet' };
|
|
47
|
+
}
|
|
48
|
+
const dirty = (await git(cwd, [
|
|
49
|
+
'status',
|
|
50
|
+
'--porcelain',
|
|
51
|
+
'--untracked-files=no',
|
|
52
|
+
'--',
|
|
53
|
+
'.',
|
|
54
|
+
...(codeOnly ? [':(exclude)content'] : []),
|
|
55
|
+
])) !== '';
|
|
56
|
+
const dir = await mkdtemp(path.join(env.TMPDIR ?? os.tmpdir(), 'foliwake-connect-'));
|
|
57
|
+
try {
|
|
58
|
+
const file = path.join(dir, 'project.bundle');
|
|
59
|
+
await git(cwd, ['bundle', 'create', '--quiet', file, 'HEAD']);
|
|
60
|
+
if ((await stat(file)).size > MAX_BUNDLE_BYTES)
|
|
61
|
+
return { none: `its Git history is larger than ${MAX_BUNDLE_BYTES / 1024} KiB` };
|
|
62
|
+
return { bundle: (await readFile(file)).toString('base64'), commit, dirty };
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
await rm(dir, { recursive: true, force: true });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The servers to offer: those signed in to (the last used first, then by origin; a
|
|
70
|
+
* FOLIWAKE_SERVER with FOLIWAKE_TOKEN counts), then those signed out of, then Foliwake Cloud
|
|
71
|
+
* when not signed in to it (`withCloud`). Reads no token.
|
|
72
|
+
*/
|
|
73
|
+
export async function knownServers(env, { withCloud = false } = {}) {
|
|
74
|
+
const profiles = readProfiles(env);
|
|
75
|
+
const cloud = cloudOrigin(env);
|
|
76
|
+
const titled = (entry) => entry.origin === cloud ? { ...entry, title: `${CLOUD_TITLE} (${CLOUD})` } : entry;
|
|
77
|
+
const signed = [];
|
|
78
|
+
const moved = [];
|
|
79
|
+
for (const [name, profile] of Object.entries(profiles.servers)) {
|
|
80
|
+
const origin = nameOrigin(name, env);
|
|
81
|
+
if (!origin)
|
|
82
|
+
continue;
|
|
83
|
+
// Signed in only where its token was issued: a "cloud" sign-in made elsewhere needs a new login.
|
|
84
|
+
if (issuerOf(name, profile) !== origin)
|
|
85
|
+
moved.push(titled({ origin, signedIn: false, account: null, lastUsed: false }));
|
|
86
|
+
else if (!signed.some((known) => known.origin === origin))
|
|
87
|
+
signed.push(titled({
|
|
88
|
+
origin,
|
|
89
|
+
signedIn: true,
|
|
90
|
+
account: typeof profile.email === 'string' ? profile.email : null,
|
|
91
|
+
lastUsed: name === profiles.default,
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
const envServer = setting('SERVER', env);
|
|
95
|
+
if (envServer && setting('TOKEN', env)) {
|
|
96
|
+
const origin = nameOrigin(envServer, env);
|
|
97
|
+
if (origin && !signed.some((known) => known.origin === origin))
|
|
98
|
+
signed.push(titled({ origin, signedIn: true, account: null, lastUsed: false }));
|
|
99
|
+
}
|
|
100
|
+
signed.sort((a, b) => Number(b.lastUsed) - Number(a.lastUsed) || a.origin.localeCompare(b.origin));
|
|
101
|
+
const all = [...signed];
|
|
102
|
+
for (const entry of moved)
|
|
103
|
+
if (!all.some((known) => known.origin === entry.origin))
|
|
104
|
+
all.push(entry);
|
|
105
|
+
for (const name of profiles.signedOut) {
|
|
106
|
+
const origin = nameOrigin(name, env);
|
|
107
|
+
if (origin && !all.some((known) => known.origin === origin))
|
|
108
|
+
all.push(titled({ origin, signedIn: false, account: null, lastUsed: false }));
|
|
109
|
+
}
|
|
110
|
+
if (withCloud && !all.some((known) => known.origin === cloud))
|
|
111
|
+
all.push(titled({ origin: cloud, signedIn: false, account: null, lastUsed: false }));
|
|
112
|
+
return all;
|
|
113
|
+
}
|
|
114
|
+
/** How a server is shown in a list: its name or origin, the account and whether it was used last. */
|
|
115
|
+
export function serverLabel(server) {
|
|
116
|
+
const notes = [server.account, server.lastUsed ? 'last used' : null, server.signedIn ? null : 'signed out'].filter(Boolean);
|
|
117
|
+
const name = server.title ? `${server.title}, ${server.origin}` : server.origin;
|
|
118
|
+
return notes.length ? `${name} (${notes.join(', ')})` : name;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Where a connect goes: --server, then FOLIWAKE_SERVER, then the only server this computer is
|
|
122
|
+
* signed in to. Signed in to several: asked with `pick` (a terminal), else refused with the list:
|
|
123
|
+
* never silently the last login.
|
|
124
|
+
*/
|
|
125
|
+
export async function chooseServer(request, pick) {
|
|
126
|
+
if (request.server)
|
|
127
|
+
return serverOrigin(request.server, request.env);
|
|
128
|
+
const typed = setting('SERVER', request.env);
|
|
129
|
+
if (typed)
|
|
130
|
+
return serverOrigin(typed, request.env);
|
|
131
|
+
const signed = (await knownServers(request.env)).filter((server) => server.signedIn);
|
|
132
|
+
if (signed.length === 0)
|
|
133
|
+
throw new ConnectRefused(`Not signed in to a Foliwake server. Sign in first: \`${C} login [<server>]\`, then run this command again.`);
|
|
134
|
+
if (signed.length === 1)
|
|
135
|
+
return signed[0].origin;
|
|
136
|
+
if (pick) {
|
|
137
|
+
const chosen = await pick(signed);
|
|
138
|
+
if (!chosen)
|
|
139
|
+
throw new ConnectRefused('No server was chosen; nothing was done.');
|
|
140
|
+
return chosen;
|
|
141
|
+
}
|
|
142
|
+
throw new ConnectRefused([
|
|
143
|
+
`This computer is signed in to ${signed.length} Foliwake servers; say which one with --server <origin> (or ` +
|
|
144
|
+
`set FOLIWAKE_SERVER):`,
|
|
145
|
+
...signed.map((server) => ` ${serverLabel(server)}`),
|
|
146
|
+
].join('\n'));
|
|
147
|
+
}
|
|
148
|
+
/** How commits reach the server: it fetches them, CI names them with a key. */
|
|
149
|
+
function codeOnServer(site) {
|
|
150
|
+
return [
|
|
151
|
+
" 2. Code on the server: it fetches the commit a deploy names from the site's repository. A private one needs",
|
|
152
|
+
` a read token: \`foliwake credential set ${codeTokenName(site)} --from-stdin\`; the workflow a CI key:`,
|
|
153
|
+
` \`foliwake account keys create --site ${site} --label <pipeline>\`.`,
|
|
154
|
+
];
|
|
155
|
+
}
|
|
156
|
+
/** The next steps, for what v1 does not set up itself. */
|
|
157
|
+
/** The repository variables of the workflows: the site id and the addresses the server gave the site. */
|
|
158
|
+
function workflowVariables(site, result) {
|
|
159
|
+
const preview = result.addresses.preview ? `, FOLIWAKE_PREVIEW_URL=${result.addresses.preview}` : '';
|
|
160
|
+
const live = result.addresses.live ? `, FOLIWAKE_PRODUCTION_URL=${result.addresses.live}` : '';
|
|
161
|
+
return `FOLIWAKE_SITE_ID=${site}${preview}${live}`;
|
|
162
|
+
}
|
|
163
|
+
export function nextSteps(result, { repository }) {
|
|
164
|
+
const site = result.site;
|
|
165
|
+
const lines = [
|
|
166
|
+
'Next steps (nothing of this was done for you):',
|
|
167
|
+
` 1. GitHub: create the repository and push this project, e.g. \`gh repo create <owner>/${site} --private ` +
|
|
168
|
+
`--source . --push\` (or \`git remote add origin <url>\` and \`git push -u origin ` +
|
|
169
|
+
`main\`).${repository ? '' : ` Then tell the server's operator the repository URL.`}`,
|
|
170
|
+
...codeOnServer(site),
|
|
171
|
+
` 3. Workflows (.github/workflows, inert until enabled): repository variables ${workflowVariables(site, result)}` +
|
|
172
|
+
'; secrets BRANCH_PREVIEW_SSH_KEY, BRANCH_PREVIEW_KNOWN_HOSTS, BRANCH_PREVIEW_SSH_TARGET in the environment ' +
|
|
173
|
+
'`branch-previews` and PRODUCTION_DEPLOY_SSH_KEY, PRODUCTION_DEPLOY_KNOWN_HOSTS, PRODUCTION_DEPLOY_SSH_TARGET ' +
|
|
174
|
+
"in `production` (the keys and targets come from the server's operator); then BRANCH_PREVIEWS_ENABLED=true " +
|
|
175
|
+
'and FRONTEND_PRODUCTION_DEPLOY_ENABLED=true.',
|
|
176
|
+
` 4. Preview and publish: the pages of content/ ` +
|
|
177
|
+
`${result.releaseOne.state === 'done' ? 'are on the server' : 'reach the server with the first code'}; build ` +
|
|
178
|
+
`the preview in the admin (Publish → Preview), review it, then publish.`,
|
|
179
|
+
' 5. Content sources: the site reads content/ of this project. Google Drive, Git Markdown or Drupal are added ' +
|
|
180
|
+
'later by an admin (admin → Content sources); nothing was connected.',
|
|
181
|
+
' The new site is served at once on a server that keeps its sites in a database; one that lists them in its ' +
|
|
182
|
+
'file serves it after its listeners restart.',
|
|
183
|
+
];
|
|
184
|
+
return lines;
|
|
185
|
+
}
|
|
186
|
+
/** The signed-in caller of the server a request names. */
|
|
187
|
+
export async function signedInTo(request, io) {
|
|
188
|
+
const server = await chooseServer(request, request.pick);
|
|
189
|
+
const { tokenFor, remoteCallerFor } = await import('./remote/session.js');
|
|
190
|
+
if (!io.callerFor && !tokenFor(server, request.env))
|
|
191
|
+
throw new ConnectRefused(signInMoved(server, request.env) ?? `Not signed in to ${server}. Sign in first: \`${C} login ${server}\`.`);
|
|
192
|
+
return { server, core: (io.callerFor ?? remoteCallerFor)(server) };
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The folder's current link, or null when there is no .foliwake/connection.json. Any other content counts as a link
|
|
196
|
+
* (never silently replaced).
|
|
197
|
+
*/
|
|
198
|
+
export async function existingLink(cwd) {
|
|
199
|
+
let text;
|
|
200
|
+
try {
|
|
201
|
+
text = await readFile(path.join(cwd, '.foliwake', 'connection.json'), 'utf8');
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
if (error.code === 'ENOENT')
|
|
205
|
+
return null;
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
let raw = {};
|
|
209
|
+
try {
|
|
210
|
+
const parsed = JSON.parse(text);
|
|
211
|
+
if (parsed && typeof parsed === 'object')
|
|
212
|
+
raw = parsed;
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
raw = {};
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
server: typeof raw.server === 'string' ? raw.server : null,
|
|
219
|
+
site: typeof raw.site === 'string' ? raw.site : null,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
export const describeLink = (link) => link.server && link.site ? `site ${link.site} on ${link.server}` : 'a link this version cannot read';
|
|
223
|
+
/**
|
|
224
|
+
* Before .foliwake/connection.json is replaced with a link to another server or site: the same
|
|
225
|
+
* link stays silent; another one is replaced with --relink, after a yes in a terminal, or refused.
|
|
226
|
+
* Checked before anything is sent, so a refused `site create` creates nothing.
|
|
227
|
+
*/
|
|
228
|
+
async function checkRelink(cwd, to, request, io) {
|
|
229
|
+
const env = request.env;
|
|
230
|
+
const from = await existingLink(cwd);
|
|
231
|
+
if (!from || (from.server !== null && nameOrigin(from.server, env) === to.server && from.site === to.site))
|
|
232
|
+
return;
|
|
233
|
+
const change = `${describeLink(from)} → site ${to.site} on ${to.server}`;
|
|
234
|
+
if (request.relink) {
|
|
235
|
+
io.err(`Replacing this folder's link (.foliwake/connection.json): ${change}.`);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (request.confirmRelink) {
|
|
239
|
+
if (await request.confirmRelink(from, to))
|
|
240
|
+
return;
|
|
241
|
+
throw new ConnectRefused(`Kept this folder's link to ${describeLink(from)}; nothing was done.`);
|
|
242
|
+
}
|
|
243
|
+
throw new ConnectRefused(`This folder is linked to ${describeLink(from)} (.foliwake/connection.json); this would replace it with site ` +
|
|
244
|
+
`${to.site} on ${to.server}. Pass --relink to replace it, or run the command in another folder.`);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* `site unlink`: removes the folder's .foliwake/connection.json. Nothing is sent and nothing changes
|
|
248
|
+
* on the server. Exit 0 unlinked, and 0 when the folder had no link (nothing to do, said plainly);
|
|
249
|
+
* 1 for a file this version cannot read, unless `force`.
|
|
250
|
+
*/
|
|
251
|
+
export async function unlinkSite(request, io) {
|
|
252
|
+
const file = path.join(request.cwd, '.foliwake', 'connection.json');
|
|
253
|
+
const link = await existingLink(request.cwd);
|
|
254
|
+
if (!link) {
|
|
255
|
+
io.out('This folder is not linked to a site (there is no .foliwake/connection.json); nothing to unlink.');
|
|
256
|
+
return { exit: 0, unlinked: null };
|
|
257
|
+
}
|
|
258
|
+
const readable = link.server !== null && link.site !== null;
|
|
259
|
+
if (!readable && !request.force) {
|
|
260
|
+
io.err(`This folder's .foliwake/connection.json is ${describeLink(link)}; it was left as it is. Pass --force to ` +
|
|
261
|
+
`remove it anyway.`);
|
|
262
|
+
return { exit: 1, unlinked: null };
|
|
263
|
+
}
|
|
264
|
+
await unlink(file);
|
|
265
|
+
if (!readable)
|
|
266
|
+
io.out('Removed .foliwake/connection.json (a link this version cannot read). Nothing changed on any server.');
|
|
267
|
+
else {
|
|
268
|
+
const origin = nameOrigin(link.server, request.env);
|
|
269
|
+
io.out(`Unlinked this folder from site ${link.site} on ${origin ? serverDisplay(origin, request.env) : link.server} ` +
|
|
270
|
+
`(.foliwake/connection.json removed). Nothing changed on the server; the site is still there.`);
|
|
271
|
+
io.out(`Link it again with \`${C} site link <id>\`, or create a site elsewhere with \`${C} site create <id> --server ` +
|
|
272
|
+
`<server>\`.`);
|
|
273
|
+
}
|
|
274
|
+
return { exit: 0, unlinked: link };
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* The folder's link; the server by its name ("cloud" for Foliwake Cloud, else its origin), so a move of the cloud keeps
|
|
278
|
+
* it.
|
|
279
|
+
*/
|
|
280
|
+
async function writeConnection(cwd, connection, env) {
|
|
281
|
+
connection = { ...connection, server: serverName(connection.server, env) };
|
|
282
|
+
await mkdir(path.join(cwd, '.foliwake'), { recursive: true });
|
|
283
|
+
await writeFile(path.join(cwd, '.foliwake', 'connection.json'), `${JSON.stringify(connection, null, 2)}\n`);
|
|
284
|
+
}
|
|
285
|
+
/** The refused or failed answer of a command, or a throw for what is not one. */
|
|
286
|
+
function failed(error, server, io, cloud = null) {
|
|
287
|
+
if (error instanceof ConnectRefused) {
|
|
288
|
+
io.err(error.message);
|
|
289
|
+
return { exit: 1, server, operation: null, result: null };
|
|
290
|
+
}
|
|
291
|
+
const coreError = error.coreError;
|
|
292
|
+
if (!coreError)
|
|
293
|
+
throw error;
|
|
294
|
+
io.err(`${coreError.code}: ${coreError.message}`);
|
|
295
|
+
if (coreError.category === 'unauthorized' && server)
|
|
296
|
+
io.err(`Sign in with \`${C} login ${server}\`.`);
|
|
297
|
+
if (coreError.code === 'SERVER_UNREACHABLE' && server !== null && server === cloud)
|
|
298
|
+
io.err(CLOUD_NOTE);
|
|
299
|
+
return { exit: 1, server, operation: null, result: null };
|
|
300
|
+
}
|
|
301
|
+
/** What `create` may offer: a new site when an admin somewhere, and the sites to link to. */
|
|
302
|
+
export async function connectChoices(request, io) {
|
|
303
|
+
const { server, core } = await signedInTo(request, io);
|
|
304
|
+
const grant = await core.whoami();
|
|
305
|
+
const mayCreate = grant.installation || grant.memberships.some((m) => m.role === 'admin' && m.sites === null);
|
|
306
|
+
const sites = (await core.sites.list()).sites.filter((site) => mayDevelop(grant, site)).map((site) => site.id);
|
|
307
|
+
return { server, mayCreate, sites };
|
|
308
|
+
}
|
|
309
|
+
/** Admin or developer of the site's organisation (a membership limited to sites must name it), or the installation. */
|
|
310
|
+
function mayDevelop(grant, site) {
|
|
311
|
+
if (grant.installation)
|
|
312
|
+
return true;
|
|
313
|
+
return grant.memberships.some((m) => m.org === site.org &&
|
|
314
|
+
(m.sites === null || m.sites.includes(site.id)) &&
|
|
315
|
+
(m.role === 'admin' || m.role === 'developer'));
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* `site link <id>`: the folder to an existing site the account may develop (admin or developer of its
|
|
319
|
+
* organisation). Nothing changes on the server. Exit 0 linked, 1 refused.
|
|
320
|
+
*/
|
|
321
|
+
export async function linkSite(request, io) {
|
|
322
|
+
let server = null;
|
|
323
|
+
try {
|
|
324
|
+
// The server and the folder's link are settled before anything is sent there.
|
|
325
|
+
server = await chooseServer(request, request.pick);
|
|
326
|
+
await checkRelink(request.cwd, { server, site: request.site }, request, io);
|
|
327
|
+
const signed = await signedInTo({ ...request, server }, io);
|
|
328
|
+
const grant = await signed.core.whoami();
|
|
329
|
+
const site = (await signed.core.sites.list()).sites.find((candidate) => candidate.id === request.site);
|
|
330
|
+
if (!site)
|
|
331
|
+
throw new ConnectRefused(`There is no site "${request.site}" on ${server} that this account may see. \`${C} site list --server ` +
|
|
332
|
+
`${server}\` lists them.`);
|
|
333
|
+
if (!mayDevelop(grant, site))
|
|
334
|
+
throw new ConnectRefused(`Linking a project to ${site.id} needs the developer or admin role in organisation ${site.org}.`);
|
|
335
|
+
await writeConnection(request.cwd, { server, site: site.id, org: site.org }, request.env);
|
|
336
|
+
io.out(`Linked this folder to site ${site.id} (organisation ${site.org}) on ${serverDisplay(server, request.env)}.`);
|
|
337
|
+
if (site.previewUrl !== '-')
|
|
338
|
+
io.out(`Preview: ${site.previewUrl}`);
|
|
339
|
+
if (site.liveUrl !== '-')
|
|
340
|
+
io.out(`Live: ${site.liveUrl}`);
|
|
341
|
+
return {
|
|
342
|
+
exit: 0,
|
|
343
|
+
server,
|
|
344
|
+
site: { id: site.id, org: site.org, liveUrl: site.liveUrl, previewUrl: site.previewUrl },
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
const outcome = failed(error, server, io, cloudOrigin(request.env));
|
|
349
|
+
return { exit: outcome.exit, server, site: null };
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/** `site create <id>`: the project's site on the server. Exit 0 created, 1 refused or failed. */
|
|
353
|
+
export async function createSite(request, io) {
|
|
354
|
+
let server = null;
|
|
355
|
+
try {
|
|
356
|
+
const signed = await signedInTo(request, io);
|
|
357
|
+
server = signed.server;
|
|
358
|
+
const site = request.site;
|
|
359
|
+
if (!CREATED_SITE_ID.test(site))
|
|
360
|
+
throw new ConnectRefused(`The site id "${site}" cannot be used on a server: at most 12 lowercase letters, digits and single inner ` +
|
|
361
|
+
`hyphens, starting with a letter.`);
|
|
362
|
+
await checkRelink(request.cwd, { server, site }, request, io);
|
|
363
|
+
let code = null;
|
|
364
|
+
if (request.code) {
|
|
365
|
+
const commit = await projectCommit(request.cwd, request.env);
|
|
366
|
+
if ('none' in commit)
|
|
367
|
+
io.err(`No code is sent (${commit.none}): release 1 waits for the first \`${C} code prepare\` on the server.`);
|
|
368
|
+
else {
|
|
369
|
+
if (commit.dirty)
|
|
370
|
+
io.err(`Uncommitted changes are not sent: release 1 is commit ${commit.commit.slice(0, 7)}.`);
|
|
371
|
+
code = { bundle: commit.bundle, commit: commit.commit };
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const core = signed.core;
|
|
375
|
+
io.out(`Creating site ${site} on ${serverDisplay(server, request.env)}…`);
|
|
376
|
+
const accepted = await core.sites.create({
|
|
377
|
+
site,
|
|
378
|
+
...(request.org ? { org: request.org } : {}),
|
|
379
|
+
repository: request.repository ?? null,
|
|
380
|
+
code,
|
|
381
|
+
expect: { absent: true },
|
|
382
|
+
idempotencyKey: `connect-${randomBytes(12).toString('hex')}`,
|
|
383
|
+
});
|
|
384
|
+
const { waitInSlices } = await import('./remote/wait-slices.js');
|
|
385
|
+
const operation = await waitInSlices((sliceMs) => core.operations.wait({ site, id: accepted.id, until: 'commit', timeoutMs: sliceMs }), { until: 'commit', timeoutMs: CONNECT_WAIT_MS });
|
|
386
|
+
if (operation.state !== 'succeeded') {
|
|
387
|
+
const error = operation.error;
|
|
388
|
+
const after = operation.state === 'failed'
|
|
389
|
+
? `What this attempt made was undone; \`${C} site create ${site}\` may be run again.`
|
|
390
|
+
: 'Whether release 1 was made is not known yet; the server operator runs `foliwake operation recover`.';
|
|
391
|
+
io.err(`The site was not created (${operation.state}${error ? `: ${error.code}: ${error.message}` : ''}). ${after}`);
|
|
392
|
+
return { exit: 1, server, operation, result: null };
|
|
393
|
+
}
|
|
394
|
+
const result = operation.result;
|
|
395
|
+
await writeConnection(request.cwd, { server, site: result.site, org: result.org }, request.env);
|
|
396
|
+
io.out(`Created site ${result.site} in organisation ${result.org} on ${serverDisplay(server, request.env)}.`);
|
|
397
|
+
if (result.releaseOne.state === 'done')
|
|
398
|
+
io.out(`Release 1: ${result.releaseOne.siteRelease} with code ${result.releaseOne.codeRelease} (commit ` +
|
|
399
|
+
`${result.releaseOne.commit.slice(0, 7)}); nothing is published yet.`);
|
|
400
|
+
else
|
|
401
|
+
io.out(`Release 1 waits for the first \`${C} code prepare\` on the server.`);
|
|
402
|
+
if (result.addresses.preview)
|
|
403
|
+
io.out(`Preview: ${result.addresses.preview}`);
|
|
404
|
+
if (result.addresses.live)
|
|
405
|
+
io.out(`Live: ${result.addresses.live}`);
|
|
406
|
+
if (result.addresses.branchPattern)
|
|
407
|
+
io.out(`Branches: ${result.addresses.branchPattern}`);
|
|
408
|
+
io.out();
|
|
409
|
+
for (const line of nextSteps(result, { repository: request.repository ?? null }))
|
|
410
|
+
io.out(line);
|
|
411
|
+
return { exit: 0, server, operation, result };
|
|
412
|
+
}
|
|
413
|
+
catch (error) {
|
|
414
|
+
return failed(error, server, io, cloudOrigin(request.env));
|
|
415
|
+
}
|
|
416
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
import type { CoreCaller } from '@foliwake/core-contract';
|
|
3
|
+
import type { Target } from './remote/servers.js';
|
|
4
|
+
import { type Operation } from './remote/wait-slices.js';
|
|
5
|
+
/** What a command that needs the engine says, with exit 2. */
|
|
6
|
+
export declare const NEEDS_ENGINE: string;
|
|
7
|
+
export declare abstract class CoreCommand extends Command {
|
|
8
|
+
static enableJsonFlag: boolean;
|
|
9
|
+
static baseFlags: {
|
|
10
|
+
debug: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
server: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
};
|
|
13
|
+
/** Accepted so that scripts written for the engine's CLI get a clear answer: a local configuration. */
|
|
14
|
+
static configFlag: {
|
|
15
|
+
config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
};
|
|
17
|
+
/** For commands that act on a site. Without `--site`: the folder's linked site, else the server's only one. */
|
|
18
|
+
static siteFlags: {
|
|
19
|
+
site: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
|
+
config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
21
|
+
};
|
|
22
|
+
/** Reading this computer's working files instead of the site's sources needs the engine. */
|
|
23
|
+
static contentFlag: {
|
|
24
|
+
content: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
25
|
+
};
|
|
26
|
+
/** The whole input of the operation as JSON, for what flags cannot express. Its schema checks it. */
|
|
27
|
+
static inputFlag: {
|
|
28
|
+
input: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
29
|
+
};
|
|
30
|
+
static refreshWaitFlag: {
|
|
31
|
+
'wait-timeout': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
32
|
+
};
|
|
33
|
+
static expectLiveFlags: {
|
|
34
|
+
expect: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
35
|
+
'latest-live': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
36
|
+
};
|
|
37
|
+
static expectBranchFlags: {
|
|
38
|
+
expect: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
39
|
+
'latest-selection': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
40
|
+
sequence: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
41
|
+
};
|
|
42
|
+
/** Accepted as in the engine's CLI; only the total time is known here (phase timings need the engine). */
|
|
43
|
+
static timingsFlag: {
|
|
44
|
+
timings: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
45
|
+
};
|
|
46
|
+
protected core: CoreCaller;
|
|
47
|
+
/** The server this command's calls go to. */
|
|
48
|
+
protected target: Target;
|
|
49
|
+
private coreError;
|
|
50
|
+
init(): Promise<void>;
|
|
51
|
+
private resolveServer;
|
|
52
|
+
protected resolveInput<TInput>(rawInput: string | undefined, fromFlags: () => TInput | Promise<TInput>): Promise<TInput>;
|
|
53
|
+
/** The site: `--site`, else the folder's linked site on this server, else the server's only site. */
|
|
54
|
+
protected siteInput(site: string | undefined): Promise<{
|
|
55
|
+
site: string;
|
|
56
|
+
}>;
|
|
57
|
+
private linkedSite;
|
|
58
|
+
/** The settle delay that default waits start from; a server's own is not known here, so a fixed one. */
|
|
59
|
+
protected settleDelayMs(_siteId: string): Promise<number>;
|
|
60
|
+
/** The `expect.live` of a write: `--expect`, or with `--latest-live` the live release read now. */
|
|
61
|
+
protected expectedLive(site: string, flags: {
|
|
62
|
+
expect?: string | undefined;
|
|
63
|
+
'latest-live'?: boolean | undefined;
|
|
64
|
+
}): Promise<string>;
|
|
65
|
+
/** The `expect` of a branch write: `--sequence`, `--expect`, or with `--latest-selection` the selection now. */
|
|
66
|
+
protected expectedBranch(site: string, branch: string, flags: {
|
|
67
|
+
expect?: string | undefined;
|
|
68
|
+
'latest-selection'?: boolean | undefined;
|
|
69
|
+
sequence?: number | undefined;
|
|
70
|
+
}): Promise<{
|
|
71
|
+
sequence: number;
|
|
72
|
+
} | {
|
|
73
|
+
selection: string | null;
|
|
74
|
+
}>;
|
|
75
|
+
/** Follows an accepted operation to its commit (or end) and, with `--wait`, its cache refresh. */
|
|
76
|
+
protected follow(operation: Operation, { wait, waitTimeout }: {
|
|
77
|
+
wait: boolean;
|
|
78
|
+
waitTimeout: number | undefined;
|
|
79
|
+
}): Promise<Operation>;
|
|
80
|
+
/** `operations.wait` against a server, in slices under its request timeout. */
|
|
81
|
+
private waitOperation;
|
|
82
|
+
/** Runs `fn`; with `--timings` (or FOLIWAKE_TIMINGS=1) reports its total time on stderr. */
|
|
83
|
+
protected timed<T>(name: string, requested: boolean, fn: () => Promise<T>): Promise<T>;
|
|
84
|
+
private reportTotal;
|
|
85
|
+
protected noteProvisional(provisional: boolean): void;
|
|
86
|
+
protected toErrorJson(error: unknown): unknown;
|
|
87
|
+
protected catch(error: Error & {
|
|
88
|
+
exitCode?: number;
|
|
89
|
+
}): Promise<unknown>;
|
|
90
|
+
private errorText;
|
|
91
|
+
}
|