@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,262 @@
|
|
|
1
|
+
// Base class of every command that maps to one core operation on a server. A command is a thin wrapper: it
|
|
2
|
+
// turns flags into the operation's input, calls it, writes text for people with `this.log` and returns the
|
|
3
|
+
// raw answer, which `--json` prints. Flags, texts and JSON are the engine CLI's own for the same command.
|
|
4
|
+
import { Command, Errors, Flags } from '@oclif/core';
|
|
5
|
+
import { CoreFailure, toCoreFailure } from './remote/core-failure.js';
|
|
6
|
+
import { waitInSlices } from './remote/wait-slices.js';
|
|
7
|
+
import { COMMAND } from './settings.js';
|
|
8
|
+
import { cliVersion } from './version.js';
|
|
9
|
+
/** Commit or end: a long sync or publication finishes long before; the wait stops nothing. */
|
|
10
|
+
const COMMIT_WAIT_MS = 24 * 60 * 60 * 1000;
|
|
11
|
+
/** Default waits start from this settle delay (the server's own is not known here). */
|
|
12
|
+
const REMOTE_SETTLE_DELAY_MS = 30_000;
|
|
13
|
+
/** What a command that needs the engine says, with exit 2. */
|
|
14
|
+
export const NEEDS_ENGINE = `needs the Foliwake engine: the Docker image (\`${COMMAND} docker install\`) or the ` + `engine checkout.`;
|
|
15
|
+
const NO_SERVER = `No Foliwake server is named: pass --server, link this folder (\`${COMMAND} site link <id>\`), ` +
|
|
16
|
+
`set FOLIWAKE_SERVER, or sign in with \`${COMMAND} login\`.`;
|
|
17
|
+
const engineOnly = (name, description) => Flags.string({ description: `${description} (${NEEDS_ENGINE.replace(/\.$/, '')})`, hidden: true, name });
|
|
18
|
+
export class CoreCommand extends Command {
|
|
19
|
+
static enableJsonFlag = true;
|
|
20
|
+
static baseFlags = {
|
|
21
|
+
debug: Flags.boolean({ description: 'print the underlying error on stderr', helpGroup: 'GLOBAL' }),
|
|
22
|
+
server: Flags.string({
|
|
23
|
+
description: "call this Foliwake server (origin or host; default: the folder's .foliwake/connection.json, " +
|
|
24
|
+
'then $FOLIWAKE_SERVER, then the last `login`)',
|
|
25
|
+
helpGroup: 'GLOBAL',
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
/** Accepted so that scripts written for the engine's CLI get a clear answer: a local configuration. */
|
|
29
|
+
static configFlag = {
|
|
30
|
+
config: engineOnly('config', 'a local project configuration'),
|
|
31
|
+
};
|
|
32
|
+
/** For commands that act on a site. Without `--site`: the folder's linked site, else the server's only one. */
|
|
33
|
+
static siteFlags = {
|
|
34
|
+
...CoreCommand.configFlag,
|
|
35
|
+
site: Flags.string({
|
|
36
|
+
description: 'site id (default: the site this folder is linked to, else the only site on the server)',
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
/** Reading this computer's working files instead of the site's sources needs the engine. */
|
|
40
|
+
static contentFlag = {
|
|
41
|
+
content: engineOnly('content', "this folder instead of the site's content sources"),
|
|
42
|
+
};
|
|
43
|
+
/** The whole input of the operation as JSON, for what flags cannot express. Its schema checks it. */
|
|
44
|
+
static inputFlag = {
|
|
45
|
+
input: Flags.string({ description: 'raw JSON for the full operation input; overrides the other input flags' }),
|
|
46
|
+
};
|
|
47
|
+
static refreshWaitFlag = {
|
|
48
|
+
'wait-timeout': Flags.integer({
|
|
49
|
+
min: 0,
|
|
50
|
+
description: "limit of the wait for this write's cache refresh, in seconds (default: settle delay + 30 s); " +
|
|
51
|
+
'still pending then: exit 3, `operation recover` finishes it',
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
static expectLiveFlags = {
|
|
55
|
+
expect: Flags.string({
|
|
56
|
+
description: 'the live site release you saw (sr_…, as `site status` shows it); refused when live is another one',
|
|
57
|
+
exclusive: ['latest-live'],
|
|
58
|
+
}),
|
|
59
|
+
'latest-live': Flags.boolean({
|
|
60
|
+
description: 'expect the live release as it is now (read once, before the request)',
|
|
61
|
+
exclusive: ['expect'],
|
|
62
|
+
}),
|
|
63
|
+
};
|
|
64
|
+
static expectBranchFlags = {
|
|
65
|
+
expect: Flags.string({
|
|
66
|
+
helpValue: 'sel_…|none',
|
|
67
|
+
description: 'the selection of the branch you saw (`branch list --json` shows it; `none`: the branch had no preview); ' +
|
|
68
|
+
'refused when it is another one',
|
|
69
|
+
exclusive: ['latest-selection', 'sequence'],
|
|
70
|
+
}),
|
|
71
|
+
'latest-selection': Flags.boolean({
|
|
72
|
+
description: "expect the branch's selection as it is now (read once, before the request)",
|
|
73
|
+
exclusive: ['expect', 'sequence'],
|
|
74
|
+
}),
|
|
75
|
+
sequence: Flags.integer({
|
|
76
|
+
min: 1,
|
|
77
|
+
description: 'deployment ordering (a positive integer such as the CI run id), instead of --expect: refused as ' +
|
|
78
|
+
'superseded when a request with a higher sequence already updated or deleted this branch',
|
|
79
|
+
exclusive: ['expect', 'latest-selection'],
|
|
80
|
+
}),
|
|
81
|
+
};
|
|
82
|
+
/** Accepted as in the engine's CLI; only the total time is known here (phase timings need the engine). */
|
|
83
|
+
static timingsFlag = {
|
|
84
|
+
timings: Flags.boolean({
|
|
85
|
+
description: 'report the total time on stderr (one JSON line with --json); also FOLIWAKE_TIMINGS=1 ' +
|
|
86
|
+
'(phase timings need the engine)',
|
|
87
|
+
}),
|
|
88
|
+
};
|
|
89
|
+
core;
|
|
90
|
+
/** The server this command's calls go to. */
|
|
91
|
+
target;
|
|
92
|
+
coreError = null;
|
|
93
|
+
async init() {
|
|
94
|
+
await super.init();
|
|
95
|
+
// `parse()` without its command cannot type the flags of the subclass.
|
|
96
|
+
const { flags } = await this.parse();
|
|
97
|
+
for (const name of ['config', 'content']) {
|
|
98
|
+
if (typeof flags[name] === 'string')
|
|
99
|
+
this.error(`--${name} ${NEEDS_ENGINE}`, { exit: 2 });
|
|
100
|
+
}
|
|
101
|
+
this.target = await this.resolveServer(typeof flags.server === 'string' ? flags.server : undefined);
|
|
102
|
+
const { SignInMovedError, remoteCallerFor } = await import('./remote/session.js');
|
|
103
|
+
try {
|
|
104
|
+
this.core = remoteCallerFor(this.target.origin);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (error instanceof SignInMovedError)
|
|
108
|
+
this.error(error.message, { exit: 1 });
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async resolveServer(server) {
|
|
113
|
+
const { CLOUD_NOTE, CLOUD_ORIGIN, ServerAddressError, cloudConfigured, resolveTarget } = await import('./remote/servers.js');
|
|
114
|
+
try {
|
|
115
|
+
const target = resolveTarget({ server });
|
|
116
|
+
if (target === null)
|
|
117
|
+
this.error(NO_SERVER, { exit: 2 });
|
|
118
|
+
if (target.origin === CLOUD_ORIGIN && !cloudConfigured())
|
|
119
|
+
this.error(CLOUD_NOTE, { exit: 1 });
|
|
120
|
+
return target;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (error instanceof ServerAddressError)
|
|
124
|
+
this.error(error.message, { exit: 2 });
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async resolveInput(rawInput, fromFlags) {
|
|
129
|
+
if (rawInput == null)
|
|
130
|
+
return fromFlags();
|
|
131
|
+
try {
|
|
132
|
+
// The untyped boundary: the operation's own schema checks what the JSON holds.
|
|
133
|
+
return JSON.parse(rawInput);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
this.error('--input is not valid JSON.');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** The site: `--site`, else the folder's linked site on this server, else the server's only site. */
|
|
140
|
+
async siteInput(site) {
|
|
141
|
+
if (site != null)
|
|
142
|
+
return { site };
|
|
143
|
+
const linked = await this.linkedSite();
|
|
144
|
+
if (linked !== null)
|
|
145
|
+
return { site: linked };
|
|
146
|
+
const { sites } = await this.core.sites.list();
|
|
147
|
+
if (sites.length !== 1)
|
|
148
|
+
this.error(`${sites.length} sites are available on this server; choose one with --site.`);
|
|
149
|
+
return { site: sites[0].id };
|
|
150
|
+
}
|
|
151
|
+
async linkedSite() {
|
|
152
|
+
const { readConnection } = await import('./remote/connection.js');
|
|
153
|
+
const { nameOrigin } = await import('./remote/servers.js');
|
|
154
|
+
const connection = readConnection(process.cwd());
|
|
155
|
+
if (!connection || nameOrigin(connection.server) !== this.target.origin)
|
|
156
|
+
return null;
|
|
157
|
+
return connection.site;
|
|
158
|
+
}
|
|
159
|
+
/** The settle delay that default waits start from; a server's own is not known here, so a fixed one. */
|
|
160
|
+
async settleDelayMs(_siteId) {
|
|
161
|
+
return REMOTE_SETTLE_DELAY_MS;
|
|
162
|
+
}
|
|
163
|
+
/** The `expect.live` of a write: `--expect`, or with `--latest-live` the live release read now. */
|
|
164
|
+
async expectedLive(site, flags) {
|
|
165
|
+
if (flags.expect !== undefined)
|
|
166
|
+
return flags.expect;
|
|
167
|
+
if (!flags['latest-live']) {
|
|
168
|
+
this.error('Name the live release you expect: --expect <sr_…> (as `site status` shows it), or --latest-live.', {
|
|
169
|
+
exit: 2,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
const { live } = await this.core.sites.status({ site });
|
|
173
|
+
if (!live)
|
|
174
|
+
this.error('This site has no live release yet.');
|
|
175
|
+
return live.site_release;
|
|
176
|
+
}
|
|
177
|
+
/** The `expect` of a branch write: `--sequence`, `--expect`, or with `--latest-selection` the selection now. */
|
|
178
|
+
async expectedBranch(site, branch, flags) {
|
|
179
|
+
if (flags.sequence !== undefined)
|
|
180
|
+
return { sequence: flags.sequence };
|
|
181
|
+
if (flags.expect !== undefined)
|
|
182
|
+
return { selection: flags.expect === 'none' ? null : flags.expect };
|
|
183
|
+
if (!flags['latest-selection']) {
|
|
184
|
+
this.error('Name the branch selection you expect: --expect <sel_…|none> (as `branch list --json` shows it), ' +
|
|
185
|
+
'--latest-selection, or --sequence <n> for a deployment.', { exit: 2 });
|
|
186
|
+
}
|
|
187
|
+
const rows = await this.core.branches.list({ site });
|
|
188
|
+
const row = rows.find((candidate) => candidate.branch === branch);
|
|
189
|
+
return { selection: row && row.retired === null ? row.selection : null };
|
|
190
|
+
}
|
|
191
|
+
/** Follows an accepted operation to its commit (or end) and, with `--wait`, its cache refresh. */
|
|
192
|
+
async follow(operation, { wait, waitTimeout }) {
|
|
193
|
+
const { site, id } = operation;
|
|
194
|
+
const committed = await this.waitOperation({ site, id, until: 'commit', timeoutMs: COMMIT_WAIT_MS });
|
|
195
|
+
if (!wait || committed.delivery?.state !== 'pending')
|
|
196
|
+
return committed;
|
|
197
|
+
const timeoutMs = waitTimeout === undefined ? (await this.settleDelayMs(site)) + 30_000 : waitTimeout * 1000;
|
|
198
|
+
const seconds = Math.ceil(timeoutMs / 1000);
|
|
199
|
+
if (!this.jsonEnabled())
|
|
200
|
+
this.log(`Cache refresh pending; waiting up to ${seconds} s for it…`);
|
|
201
|
+
const delivered = await this.waitOperation({ site, id, until: 'delivery', timeoutMs });
|
|
202
|
+
if (delivered.delivery?.state !== 'pending' || delivered.delivery.reason !== undefined)
|
|
203
|
+
return delivered;
|
|
204
|
+
return this.core.operations.get({ site, id });
|
|
205
|
+
}
|
|
206
|
+
/** `operations.wait` against a server, in slices under its request timeout. */
|
|
207
|
+
waitOperation(input) {
|
|
208
|
+
return waitInSlices((sliceMs) => this.core.operations.wait({ ...input, timeoutMs: sliceMs }), input);
|
|
209
|
+
}
|
|
210
|
+
/** Runs `fn`; with `--timings` (or FOLIWAKE_TIMINGS=1) reports its total time on stderr. */
|
|
211
|
+
async timed(name, requested, fn) {
|
|
212
|
+
if (!requested && process.env.FOLIWAKE_TIMINGS !== '1')
|
|
213
|
+
return fn();
|
|
214
|
+
const started = performance.now();
|
|
215
|
+
try {
|
|
216
|
+
return await fn();
|
|
217
|
+
}
|
|
218
|
+
finally {
|
|
219
|
+
this.reportTotal(name, Math.round(performance.now() - started));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
reportTotal(name, totalMs) {
|
|
223
|
+
const line = this.jsonEnabled()
|
|
224
|
+
? JSON.stringify({ timings: { command: name, totalMs } })
|
|
225
|
+
: `timings: ${name} ${totalMs} ms in total (phase timings need the engine)`;
|
|
226
|
+
process.stderr.write(`${line}\n`);
|
|
227
|
+
}
|
|
228
|
+
noteProvisional(provisional) {
|
|
229
|
+
if (!provisional || this.jsonEnabled())
|
|
230
|
+
return;
|
|
231
|
+
this.logToStderr('Note: page IDs of new pages are provisional here (the published pages were not consulted); ' +
|
|
232
|
+
'preview/publish decide them.');
|
|
233
|
+
}
|
|
234
|
+
toErrorJson(error) {
|
|
235
|
+
return { error: this.coreError ?? { message: error instanceof Error ? error.message : String(error) } };
|
|
236
|
+
}
|
|
237
|
+
// Anything that is not oclif's own goes through core's error shape and exits 1. Parse errors keep exit 2.
|
|
238
|
+
async catch(error) {
|
|
239
|
+
if (error instanceof Errors.CLIError)
|
|
240
|
+
return super.catch(error);
|
|
241
|
+
const failure = toCoreFailure(error);
|
|
242
|
+
this.coreError = failure.coreError;
|
|
243
|
+
if (process.argv.includes('--debug'))
|
|
244
|
+
this.logToStderr(String(debugStack(failure)));
|
|
245
|
+
return super.catch(new Errors.CLIError(this.errorText(failure.coreError), { exit: 1 }));
|
|
246
|
+
}
|
|
247
|
+
errorText({ code, message, category, fields = [] }) {
|
|
248
|
+
const details = fields.map((field) => (field.path ? `${field.path}: ${field.message}` : field.message));
|
|
249
|
+
const origin = this.target?.origin;
|
|
250
|
+
const signIn = origin && category === 'unauthorized' ? [`Sign in with \`${COMMAND} login ${origin}\`.`] : [];
|
|
251
|
+
const older = code === 'PROCEDURE_UNKNOWN'
|
|
252
|
+
? [
|
|
253
|
+
`The server is older than this CLI (@foliwake/cli ${cliVersion()}): update the server, or use ` +
|
|
254
|
+
'an older @foliwake/cli that matches it (`GET /api/version` names its engine).',
|
|
255
|
+
]
|
|
256
|
+
: [];
|
|
257
|
+
return [`${code}: ${message}`, ...details, ...signIn, ...older, 'Run again with --debug for details.'].join('\n');
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function debugStack(failure) {
|
|
261
|
+
return (failure.cause instanceof Error ? failure.cause : failure).stack;
|
|
262
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CoreOutput } from '@foliwake/core-contract';
|
|
2
|
+
export type { CoreCaller } from '@foliwake/core-contract';
|
|
3
|
+
export type { BranchResultCore, OperationResult, ResetStorageResult, SiteCreateResult, SyncResultCore, } from './lib/result-types.js';
|
|
4
|
+
export type Grant = CoreOutput<'whoami'>;
|
|
5
|
+
export type Operation = CoreOutput<'operations.get'>;
|
|
6
|
+
export type Recovery = CoreOutput<'operations.recover'>;
|
|
7
|
+
export type SiteStatus = CoreOutput<'sites.status'>;
|
|
8
|
+
export type SiteList = CoreOutput<'sites.list'>;
|
|
9
|
+
export type ResetStoragePlan = CoreOutput<'sites.resetStoragePlan'>;
|
|
10
|
+
export type SourceList = CoreOutput<'sources.list'>;
|
|
11
|
+
export type PluginList = CoreOutput<'sources.plugins'>;
|
|
12
|
+
export type PendingAnswer = CoreOutput<'sources.pending'>;
|
|
13
|
+
export type ProbeAnswer = CoreOutput<'sources.probe'>;
|
|
14
|
+
export type AddAnswer = CoreOutput<'sources.add'>;
|
|
15
|
+
export type BranchList = CoreOutput<'branches.list'>;
|
|
16
|
+
export type BranchHistory = CoreOutput<'branches.history'>;
|
|
17
|
+
export type Changes = CoreOutput<'content.changes'>;
|
|
18
|
+
export type Validation = CoreOutput<'content.validate'>;
|
|
19
|
+
export type CredentialList = CoreOutput<'credentials.list'>;
|
|
20
|
+
export type CredentialSetResult = CoreOutput<'credentials.set'>;
|
|
21
|
+
export type CredentialRemoveResult = CoreOutput<'credentials.remove'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ConnectIO } from './connect.js';
|
|
2
|
+
import { type PromptStreams } from './lib/prompts.js';
|
|
3
|
+
export interface ConnectStep {
|
|
4
|
+
/** The project folder, as created. */
|
|
5
|
+
target: string;
|
|
6
|
+
/** The site id the answers named, if any. */
|
|
7
|
+
siteId: string | null;
|
|
8
|
+
/** The project has its first commit (a new site gets its code from it). */
|
|
9
|
+
committed: boolean;
|
|
10
|
+
interactive: boolean;
|
|
11
|
+
createSite: boolean;
|
|
12
|
+
linkSite: string | undefined;
|
|
13
|
+
/** An origin, from --server. */
|
|
14
|
+
server: string | undefined;
|
|
15
|
+
relink: boolean;
|
|
16
|
+
prompts: PromptStreams;
|
|
17
|
+
signIn: (origin: string) => Promise<boolean>;
|
|
18
|
+
/** Told the server and site the folder was linked to (`connect --json`). */
|
|
19
|
+
onLinked?: (linked: {
|
|
20
|
+
server: string | null;
|
|
21
|
+
site: string;
|
|
22
|
+
created: boolean;
|
|
23
|
+
}) => void;
|
|
24
|
+
}
|
|
25
|
+
/** The connect step; its exit status, or null when nothing ran (not now, a failed sign-in, no answer). */
|
|
26
|
+
export declare function connectStep(step: ConnectStep, io: ConnectIO): Promise<number | null>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// The last step of `foliwake create`: «Connect to a Foliwake server?». In a terminal: which server (each
|
|
2
|
+
// signed in to, those signed out of, another one, or not now; not asked with --server or FOLIWAKE_SERVER), the
|
|
3
|
+
// sign-in when it is needed (as `login`), then a new site (offered to admins), an existing one, or not now.
|
|
4
|
+
// Without a terminal: only --create-site or --link-site, on the server `site create` would choose. Runs the
|
|
5
|
+
// same code as `site create` and `site link` in the new folder.
|
|
6
|
+
import { localSiteId } from 'create-foliwake';
|
|
7
|
+
import { connectChoices, createSite, knownServers, linkSite } from './connect.js';
|
|
8
|
+
import { terminalQuestions } from './connect-prompts.js';
|
|
9
|
+
import { askConnect, askServer } from './lib/prompts.js';
|
|
10
|
+
import { cloudConfigured, serverOrigin } from './remote/servers.js';
|
|
11
|
+
import { COMMAND, setting } from './settings.js';
|
|
12
|
+
function relinkOf(step) {
|
|
13
|
+
const ask = terminalQuestions({ input: process.stdin, output: process.stdout }, { ask: step.interactive });
|
|
14
|
+
return { relink: step.relink, confirmRelink: ask.confirmRelink };
|
|
15
|
+
}
|
|
16
|
+
function runner(step, io, site) {
|
|
17
|
+
const base = { cwd: step.target, env: process.env, ...relinkOf(step) };
|
|
18
|
+
return async (server) => {
|
|
19
|
+
const on = server ?? undefined;
|
|
20
|
+
if (step.linkSite) {
|
|
21
|
+
const linked = await linkSite({ ...base, site: step.linkSite, server: on }, io);
|
|
22
|
+
if (linked.exit === 0)
|
|
23
|
+
step.onLinked?.({ server: linked.server, site: step.linkSite, created: false });
|
|
24
|
+
return linked.exit;
|
|
25
|
+
}
|
|
26
|
+
const created = await createSite({ ...base, site, server: on, code: true }, io);
|
|
27
|
+
if (created.exit === 0)
|
|
28
|
+
step.onLinked?.({ server: created.server, site, created: true });
|
|
29
|
+
return created.exit;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** FOLIWAKE_SERVER as an origin, or null (a value that is no address is said and not used). */
|
|
33
|
+
function presetServer() {
|
|
34
|
+
const typed = setting('SERVER', process.env);
|
|
35
|
+
if (!typed)
|
|
36
|
+
return null;
|
|
37
|
+
try {
|
|
38
|
+
return serverOrigin(typed);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
process.stderr.write(`FOLIWAKE_SERVER is not used: ${error.message}\n`);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function choicesOn(server, io) {
|
|
46
|
+
try {
|
|
47
|
+
const { mayCreate, sites } = await connectChoices({ server, env: process.env }, io);
|
|
48
|
+
return { mayCreate, sites };
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
const code = error.coreError?.code ?? error.message;
|
|
52
|
+
const later = `connect later with \`${COMMAND} site create\` or \`site link\``;
|
|
53
|
+
process.stderr.write(`${server} could not list your sites (${code}); ${later}.\n`);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** The connect step; its exit status, or null when nothing ran (not now, a failed sign-in, no answer). */
|
|
58
|
+
export async function connectStep(step, io) {
|
|
59
|
+
const site = localSiteId(step.siteId, step.target);
|
|
60
|
+
const run = runner(step, io, site);
|
|
61
|
+
const asked = step.createSite || step.linkSite !== undefined;
|
|
62
|
+
if (!step.interactive)
|
|
63
|
+
return asked ? run(step.server ?? null) : null;
|
|
64
|
+
const known = await knownServers(process.env, { withCloud: cloudConfigured() });
|
|
65
|
+
const server = step.server ?? presetServer() ?? (await askServer(step.prompts, known, (typed) => serverOrigin(typed)));
|
|
66
|
+
if (server === null)
|
|
67
|
+
return null;
|
|
68
|
+
if (!known.some((entry) => entry.origin === server && entry.signedIn)) {
|
|
69
|
+
io.out(`\nSigning in to ${server} (as \`${COMMAND} login ${server}\`).`);
|
|
70
|
+
if (!(await step.signIn(server)))
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
if (asked)
|
|
74
|
+
return run(server);
|
|
75
|
+
if (!step.committed) {
|
|
76
|
+
io.out(`There is no first commit: a new site gets no code until \`${COMMAND} code prepare\` on the server.`);
|
|
77
|
+
}
|
|
78
|
+
const choices = await choicesOn(server, io);
|
|
79
|
+
if (!choices)
|
|
80
|
+
return null;
|
|
81
|
+
const answer = await askConnect(step.prompts, { server, site, ...choices });
|
|
82
|
+
if (!answer)
|
|
83
|
+
return null;
|
|
84
|
+
io.out('');
|
|
85
|
+
return 'create' in answer ? run(server) : linkWith(step, io, answer.link, server);
|
|
86
|
+
}
|
|
87
|
+
async function linkWith(step, io, site, server) {
|
|
88
|
+
const request = { cwd: step.target, env: process.env, site, server, ...relinkOf(step) };
|
|
89
|
+
const linked = await linkSite(request, io);
|
|
90
|
+
if (linked.exit === 0)
|
|
91
|
+
step.onLinked?.({ server: linked.server, site, created: false });
|
|
92
|
+
return linked.exit;
|
|
93
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** The code directories served (and watched) under the code root. */
|
|
2
|
+
export declare const CODE_DIRECTORIES: readonly ["components", "scripts", "styles", "templates"];
|
|
3
|
+
/** The file types served from them. */
|
|
4
|
+
export declare const CODE_EXTENSIONS: readonly string[];
|
|
5
|
+
/** Default polling interval (ms) when polling is chosen. */
|
|
6
|
+
export declare const DEFAULT_CODE_POLLING_INTERVAL_MS = 1000;
|
|
7
|
+
export interface CodeWatcherOptions {
|
|
8
|
+
/** absolute code root */
|
|
9
|
+
cwd: string;
|
|
10
|
+
/** called with the changed cwd-relative posix paths (added, changed or removed) */
|
|
11
|
+
onChange: (files: string[]) => void;
|
|
12
|
+
onError?: (error: unknown) => void;
|
|
13
|
+
/** stat polling (true) or native fs.watch events (false); see resolveWatchPolling */
|
|
14
|
+
usePolling: boolean;
|
|
15
|
+
/** polling interval in ms (default 1000; polling only) */
|
|
16
|
+
pollingIntervalMs?: number;
|
|
17
|
+
/** quiet window that merges watcher events into one batch (default 50) */
|
|
18
|
+
eventDelayMs?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface CodeWatcher {
|
|
21
|
+
start(): Promise<void>;
|
|
22
|
+
/** Re-reads every known and watched code file now; resolves with the files that changed. */
|
|
23
|
+
rescan(): Promise<string[]>;
|
|
24
|
+
stop(): Promise<void>;
|
|
25
|
+
/** The backend Chokidar actually runs ('polling' or 'auto'); null before start / after stop. */
|
|
26
|
+
backend(): string | null;
|
|
27
|
+
}
|
|
28
|
+
export type WatchModeSource = 'option' | 'env' | 'chokidar-env' | 'platform';
|
|
29
|
+
export interface WatchModeChoice {
|
|
30
|
+
usePolling: boolean;
|
|
31
|
+
/** which setting decided */
|
|
32
|
+
source: WatchModeSource;
|
|
33
|
+
/** one line for the start-up log: the mode, what decided it and what it overrode */
|
|
34
|
+
description: string;
|
|
35
|
+
/** a FOLIWAKE_WATCH_POLLING value that is not recognised (ignored) */
|
|
36
|
+
invalid?: string;
|
|
37
|
+
/** environment variables that were set but did not decide (lower precedence) */
|
|
38
|
+
overridden: string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Chooses polling or native events for the code watcher. Precedence (first that is set wins):
|
|
42
|
+
* 1. the command line: `dev --watch --watch-polling` / `--no-watch-polling`;
|
|
43
|
+
* 2. FOLIWAKE_WATCH_POLLING=1|true|yes or 0|false|no (any other value is ignored and reported);
|
|
44
|
+
* 3. CHOKIDAR_USEPOLLING (Chokidar's own variable; same reading as Chokidar);
|
|
45
|
+
* 4. the platform: polling on macOS (native directory events / FSEvents were measured silent
|
|
46
|
+
* on a development Mac), native events elsewhere (Linux measured; Windows not measured).
|
|
47
|
+
* The watcher is always created with this decision: createCodeWatcher hides CHOKIDAR_USEPOLLING
|
|
48
|
+
* and CHOKIDAR_INTERVAL from Chokidar, which would otherwise override it.
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveWatchPolling({ option, env, platform, }?: {
|
|
51
|
+
option?: boolean;
|
|
52
|
+
env?: NodeJS.ProcessEnv;
|
|
53
|
+
platform?: NodeJS.Platform;
|
|
54
|
+
}): WatchModeChoice;
|
|
55
|
+
/** Whether a cwd-relative posix path is watched code (no dot segments, served extension) or a block example. */
|
|
56
|
+
export declare function isCodeFile(relative: string): boolean;
|
|
57
|
+
export declare function createCodeWatcher({ cwd, onChange, onError, usePolling, pollingIntervalMs, eventDelayMs, }: CodeWatcherOptions): CodeWatcher;
|
|
58
|
+
/**
|
|
59
|
+
* The code watcher of `dev --watch` (local and remote mode): decides polling vs native events
|
|
60
|
+
* (resolveWatchPolling, `polling` = the CLI flag), logs the decision and what it overrode, and
|
|
61
|
+
* creates the watcher. `log` receives one line without the command tag.
|
|
62
|
+
*/
|
|
63
|
+
export declare function createLiveCodeWatcher({ polling, log, ...options }: Omit<CodeWatcherOptions, 'usePolling'> & {
|
|
64
|
+
polling?: boolean;
|
|
65
|
+
log: (line: string) => void;
|
|
66
|
+
}): CodeWatcher;
|