@foliwake/cli 0.8.0 → 0.10.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 +72 -0
- package/README.md +82 -5
- package/dist/commands/connect.d.ts +2 -0
- package/dist/commands/connect.js +13 -0
- package/dist/commands/create.d.ts +1 -0
- package/dist/commands/create.js +5 -0
- package/dist/commands/next/init.d.ts +10 -0
- package/dist/commands/next/init.js +41 -0
- package/dist/commands/org/create.d.ts +13 -0
- package/dist/commands/org/create.js +30 -0
- package/dist/commands/org/list.d.ts +9 -0
- package/dist/commands/org/list.js +25 -0
- package/dist/commands/site/create.js +9 -4
- package/dist/commands/site/delete.d.ts +14 -0
- package/dist/commands/site/delete.js +52 -0
- package/dist/commands/site/preview-token.d.ts +10 -0
- package/dist/commands/site/preview-token.js +18 -0
- package/dist/commands/source/add.d.ts +19 -4
- package/dist/commands/source/add.js +42 -29
- package/dist/commands/source/check.d.ts +21 -0
- package/dist/commands/source/check.js +32 -2
- package/dist/connect-choices.d.ts +30 -0
- package/dist/connect-choices.js +100 -0
- package/dist/connect-prompts.d.ts +1 -1
- package/dist/connect-prompts.js +7 -0
- package/dist/connect.d.ts +9 -3
- package/dist/connect.js +40 -33
- package/dist/core-command.js +2 -1
- package/dist/create-connect.d.ts +3 -0
- package/dist/create-connect.js +2 -2
- package/dist/local-target.d.ts +3 -1
- package/dist/local-target.js +7 -4
- package/dist/source-entry.d.ts +8 -0
- package/dist/source-entry.js +67 -3
- package/dist/source-flags.d.ts +24 -0
- package/dist/source-flags.js +48 -0
- package/package.json +13 -7
package/dist/source-entry.js
CHANGED
|
@@ -53,12 +53,24 @@ function gitEntry(flags) {
|
|
|
53
53
|
settings.subfolder = flags.subfolder;
|
|
54
54
|
return { ok: true, value: { settings, ...(flags.token ? { credentials: { token: flags.token } } : {}) } };
|
|
55
55
|
}
|
|
56
|
+
/** The languages of a Drupal source; `--list-title` gives each its list page heading, in the same order. */
|
|
57
|
+
function drupalLanguages(flags) {
|
|
58
|
+
const codes = flags.language ?? [];
|
|
59
|
+
const titles = flags['list-title'] ?? [];
|
|
60
|
+
if (codes.length === 0)
|
|
61
|
+
return { ok: false, problem: 'Name at least one --language, the default one first.' };
|
|
62
|
+
if (titles.length > codes.length)
|
|
63
|
+
return { ok: false, problem: 'Give at most one --list-title per --language, in the same order.' };
|
|
64
|
+
const languages = codes.map((langcode, i) => (titles[i] ? { langcode, listTitle: titles[i] } : { langcode }));
|
|
65
|
+
return { ok: true, value: languages };
|
|
66
|
+
}
|
|
56
67
|
function drupalEntry(flags) {
|
|
57
68
|
if (flags['base-url'] === undefined)
|
|
58
69
|
return { ok: false, problem: '--base-url is required: the Drupal site address.' };
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
return
|
|
70
|
+
const parsed = drupalLanguages(flags);
|
|
71
|
+
if (!parsed.ok)
|
|
72
|
+
return parsed;
|
|
73
|
+
const languages = parsed.value;
|
|
62
74
|
const credentials = {};
|
|
63
75
|
if (flags['basic-user'])
|
|
64
76
|
credentials.username = flags['basic-user'];
|
|
@@ -67,10 +79,59 @@ function drupalEntry(flags) {
|
|
|
67
79
|
const extra = Object.keys(credentials).length ? { credentials } : {};
|
|
68
80
|
return { ok: true, value: { settings: { baseUrl: flags['base-url'], languages }, ...extra } };
|
|
69
81
|
}
|
|
82
|
+
const DOC_ID = /^[A-Za-z0-9_-]{10,200}$/;
|
|
83
|
+
/** A Google document link (`/document/d/<id>/…`, its `tab=` if any) or a bare ID. */
|
|
84
|
+
export function googleDocument(text) {
|
|
85
|
+
const trimmed = text.trim();
|
|
86
|
+
if (DOC_ID.test(trimmed))
|
|
87
|
+
return { ok: true, value: { documentId: trimmed } };
|
|
88
|
+
let url;
|
|
89
|
+
try {
|
|
90
|
+
url = new URL(trimmed);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return { ok: false, problem: `${trimmed}: paste the document link from the browser, or its ID.` };
|
|
94
|
+
}
|
|
95
|
+
const id = /\/document\/(?:u\/\d+\/)?d\/([^/?#]+)/.exec(url.pathname)?.[1];
|
|
96
|
+
if (!id || !DOC_ID.test(id))
|
|
97
|
+
return { ok: false, problem: `${trimmed}: this link names no Google document.` };
|
|
98
|
+
const tab = url.searchParams.get('tab');
|
|
99
|
+
return { ok: true, value: tab ? { documentId: id, tabId: tab } : { documentId: id } };
|
|
100
|
+
}
|
|
101
|
+
/** `--page <document link or ID>=<path>`: one published page of a Google Docs source. */
|
|
102
|
+
function googlePage(text) {
|
|
103
|
+
const at = text.lastIndexOf('=');
|
|
104
|
+
if (at <= 0 || !text.slice(at + 1).startsWith('/'))
|
|
105
|
+
return { ok: false, problem: `--page ${text}: write <document link or ID>=<page path>, e.g. <link>=/intro.` };
|
|
106
|
+
const document = googleDocument(text.slice(0, at));
|
|
107
|
+
if (!document.ok)
|
|
108
|
+
return document;
|
|
109
|
+
return { ok: true, value: { ...document.value, path: text.slice(at + 1) } };
|
|
110
|
+
}
|
|
111
|
+
function googleDocsEntry(flags) {
|
|
112
|
+
const pages = [];
|
|
113
|
+
for (const text of flags.page ?? []) {
|
|
114
|
+
const page = googlePage(text);
|
|
115
|
+
if (!page.ok)
|
|
116
|
+
return page;
|
|
117
|
+
pages.push(page.value);
|
|
118
|
+
}
|
|
119
|
+
if (pages.length === 0 && flags.folder === undefined)
|
|
120
|
+
return { ok: false, problem: 'Name the pages: --page <document link>=<path> (repeatable), or --folder.' };
|
|
121
|
+
const settings = { auth: 'service-account', pages };
|
|
122
|
+
if (flags.folder !== undefined) {
|
|
123
|
+
const folder = driveFolderId(flags.folder);
|
|
124
|
+
if (!folder.ok)
|
|
125
|
+
return folder;
|
|
126
|
+
settings.folderId = folder.value;
|
|
127
|
+
}
|
|
128
|
+
return { ok: true, value: { settings, credentials: { serviceAccountKey: flags.key ?? DEFAULT_DRIVE_KEY } } };
|
|
129
|
+
}
|
|
70
130
|
const BUILDERS = {
|
|
71
131
|
[DRIVE_PLUGIN]: driveEntry,
|
|
72
132
|
'git-markdown': gitEntry,
|
|
73
133
|
drupal: drupalEntry,
|
|
134
|
+
'google-docs': googleDocsEntry,
|
|
74
135
|
};
|
|
75
136
|
/** The entry of the flags, or the first problem. `mappings`: the rules of `--mappings`, as written. */
|
|
76
137
|
export function entryOf(flags, mappings) {
|
|
@@ -85,5 +146,8 @@ export function entryOf(flags, mappings) {
|
|
|
85
146
|
entry.displayName = flags['display-name'];
|
|
86
147
|
if (mappings !== undefined)
|
|
87
148
|
entry.mappings = mappings;
|
|
149
|
+
const hosts = flags['allow-private-host'] ?? [];
|
|
150
|
+
if (hosts.length)
|
|
151
|
+
entry.operator = { allowPrivateHosts: hosts };
|
|
88
152
|
return { ok: true, value: entry };
|
|
89
153
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** `required`: --id and --owns must be given (`source add`); `source check` takes them only for a candidate. */
|
|
2
|
+
export declare function entryFlags({ required }: {
|
|
3
|
+
required: boolean;
|
|
4
|
+
}): {
|
|
5
|
+
plugin: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
'display-name': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
owns: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
mappings: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
folder: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
subfolder: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
identity: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
key: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
repository: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
branch: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
language: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
+
'basic-user': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
|
+
'basic-password': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
21
|
+
'list-title': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
22
|
+
page: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
23
|
+
'allow-private-host': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
24
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// The flags that describe a new source entry (source-entry.ts): `source add` saves it, `source check` checks it.
|
|
2
|
+
import { Flags } from '@oclif/core';
|
|
3
|
+
import { DEFAULT_DRIVE_KEY, DRIVE_PLUGIN } from './source-entry.js';
|
|
4
|
+
/** `required`: --id and --owns must be given (`source add`); `source check` takes them only for a candidate. */
|
|
5
|
+
export function entryFlags({ required }) {
|
|
6
|
+
return {
|
|
7
|
+
plugin: Flags.string({ description: 'the connector', default: DRIVE_PLUGIN }),
|
|
8
|
+
id: Flags.string({ description: 'the new source id (lower case, digits, "-")', required }),
|
|
9
|
+
'display-name': Flags.string({ description: 'the name the dashboard shows' }),
|
|
10
|
+
owns: Flags.string({
|
|
11
|
+
description: 'a path the source owns, such as /lessons or "=/" (repeatable)',
|
|
12
|
+
multiple: true,
|
|
13
|
+
required,
|
|
14
|
+
}),
|
|
15
|
+
mappings: Flags.string({
|
|
16
|
+
description: 'a JSON file with path mapping rules (default: each file names its address)',
|
|
17
|
+
}),
|
|
18
|
+
folder: Flags.string({ description: 'Google Drive or Google Docs: the folder link or ID' }),
|
|
19
|
+
subfolder: Flags.string({ description: 'Google Drive or Git: the folder inside that holds the pages' }),
|
|
20
|
+
identity: Flags.string({
|
|
21
|
+
description: 'Google Drive: file-id (default; renames keep the page) or front-matter',
|
|
22
|
+
options: ['file-id', 'front-matter'],
|
|
23
|
+
}),
|
|
24
|
+
key: Flags.string({
|
|
25
|
+
description: `Google Drive or Docs: the credential name of the service-account key (default ${DEFAULT_DRIVE_KEY})`,
|
|
26
|
+
}),
|
|
27
|
+
repository: Flags.string({ description: 'Git: the https address of the repository' }),
|
|
28
|
+
branch: Flags.string({ description: 'Git: the branch (default main)' }),
|
|
29
|
+
token: Flags.string({ description: 'Git: the credential name of a read-only token (private repository)' }),
|
|
30
|
+
'base-url': Flags.string({ description: 'Drupal: the site address' }),
|
|
31
|
+
language: Flags.string({ description: 'Drupal: a language code, the default first (repeatable)', multiple: true }),
|
|
32
|
+
'basic-user': Flags.string({ description: 'Drupal: the credential name of a read-only user name (HTTP Basic)' }),
|
|
33
|
+
'basic-password': Flags.string({ description: 'Drupal: the credential name of its password' }),
|
|
34
|
+
'list-title': Flags.string({
|
|
35
|
+
description: 'Drupal: the heading of the article list page, per --language in the same order (repeatable)',
|
|
36
|
+
multiple: true,
|
|
37
|
+
}),
|
|
38
|
+
page: Flags.string({
|
|
39
|
+
description: 'Google Docs: <document link or ID>=<page path>, one published page (repeatable)',
|
|
40
|
+
multiple: true,
|
|
41
|
+
}),
|
|
42
|
+
'allow-private-host': Flags.string({
|
|
43
|
+
description: "a host on a private network the source may reach, e.g. a Drupal inside the server's network " +
|
|
44
|
+
"(operator.allowPrivateHosts; the installation's owner only; repeatable)",
|
|
45
|
+
multiple: true,
|
|
46
|
+
}),
|
|
47
|
+
};
|
|
48
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foliwake/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
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
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -67,12 +67,18 @@
|
|
|
67
67
|
"credential": {
|
|
68
68
|
"description": "Credential values the content sources name (stored on the server, never shown)"
|
|
69
69
|
},
|
|
70
|
+
"next": {
|
|
71
|
+
"description": "Next.js apps that show Foliwake pages"
|
|
72
|
+
},
|
|
70
73
|
"migration": {
|
|
71
74
|
"description": "Whole-site rebuilds against new code, released as one"
|
|
72
75
|
},
|
|
73
76
|
"operation": {
|
|
74
77
|
"description": "Long operations: their state, cancellation and recovery"
|
|
75
78
|
},
|
|
79
|
+
"org": {
|
|
80
|
+
"description": "Organisations of the server"
|
|
81
|
+
},
|
|
76
82
|
"page": {
|
|
77
83
|
"description": "Working pages"
|
|
78
84
|
},
|
|
@@ -98,12 +104,12 @@
|
|
|
98
104
|
"@oclif/core": "4.14.0",
|
|
99
105
|
"chokidar": "6.0.0",
|
|
100
106
|
"parse5": "7.3.0",
|
|
101
|
-
"@foliwake/block-kit": "0.
|
|
102
|
-
"@foliwake/
|
|
103
|
-
"@foliwake/
|
|
104
|
-
"@foliwake/site-check": "0.
|
|
105
|
-
"create-foliwake": "0.
|
|
106
|
-
"@foliwake/
|
|
107
|
+
"@foliwake/block-kit": "0.10.0",
|
|
108
|
+
"@foliwake/core-contract": "0.10.0",
|
|
109
|
+
"@foliwake/server": "0.10.0",
|
|
110
|
+
"@foliwake/site-check": "0.10.0",
|
|
111
|
+
"create-foliwake": "0.10.0",
|
|
112
|
+
"@foliwake/blocks-contract": "0.10.0"
|
|
107
113
|
},
|
|
108
114
|
"files": [
|
|
109
115
|
"dist/",
|