@foliwake/cli 0.8.0 → 0.9.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 CHANGED
@@ -1,5 +1,45 @@
1
1
  # @foliwake/cli
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0cfb15c: Organisations and site deletion: `foliwake org list`, `foliwake org create <id> [--name]` (the installation's owner;
8
+ core `org.create`) and `foliwake site delete --site <id> [--confirm <id>] [--force]` (core `sites.delete`: refused
9
+ while the site works, has live pages or is named by memberships, invitations or CI keys; its bucket is kept and the
10
+ command says how to go on).
11
+
12
+ `site create`, `connect --create` and `create --create-site` never leave the organisation to the server: `--org`, or
13
+ the only organisation where the account may create sites (said), or asked in a terminal when there are several
14
+ (refused without one, listing them). `connect --create` gets `--org` and `--repository`; the repository defaults to
15
+ the folder's Git `origin` as an https:// address (`--repository none`: none). The "Next steps" after a new site no
16
+ longer mention SSH secrets: a public repository needs no code token, a private one a read token; the workflows take
17
+ a CI key made with `account keys create --site <id> --label github-actions`.
18
+
19
+ The core contract adds `org.create` and `sites.delete` and their error codes.
20
+ - 69dee17: `source add`: `--list-title` (Drupal, per `--language`), `--plugin google-docs` with `--page <document link or
21
+ ID>=<path>` (repeatable) and an optional `--folder`, and `--allow-private-host <host>` (the source's
22
+ `operator.allowPrivateHosts`; the installation's owner only). A source whose connection check fails is no longer
23
+ saved unless `--force`. When another source owns the whole site (`/`), it prints how to narrow that one first.
24
+ `source check` checks a new source described with the same flags (`--id …`) without saving it.
25
+
26
+ ### Patch Changes
27
+
28
+ - c8e7363: With the engine, `page check --content <dir>` (and every command with `--content`) in a folder linked to a site
29
+ checks the local files with the folder's `foliwake.config.json` instead of refusing: `--content` names a folder on
30
+ this computer, so it chooses the local runtime before the folder's link. `--server` with `--content` is still
31
+ refused.
32
+ - Updated dependencies [003f643]
33
+ - Updated dependencies [0cfb15c]
34
+ - Updated dependencies [5a7ffdf]
35
+ - Updated dependencies [6dd1fd4]
36
+ - @foliwake/server@0.9.0
37
+ - @foliwake/core-contract@0.9.0
38
+ - create-foliwake@0.9.0
39
+ - @foliwake/blocks-contract@0.9.0
40
+ - @foliwake/block-kit@0.9.0
41
+ - @foliwake/site-check@0.9.0
42
+
3
43
  ## 0.8.0
4
44
 
5
45
  ### Patch Changes
package/README.md CHANGED
@@ -127,6 +127,18 @@ engine and contract.
127
127
  renderer exists (the engine's `foliwake dev` has it).
128
128
  - `dev --remote` signs in to a protected site with HTTP Basic only, not with your `foliwake login`.
129
129
  - `dev --remote` shows no content errors: the content is the deployed site's, checked when it was published.
130
+ - `site create` / `connect --create` always name the organisation: the only one where you may create sites, or the
131
+ one chosen (`--org`, or asked in a terminal); a server still answers a call without `org` with its own default.
132
+ The repository defaults to the folder's Git `origin` as an https:// address; there is no check that the server
133
+ can fetch it until the first `code deploy --rev`.
134
+ - `site delete` keeps the site's bucket: the operator empties it before a site with the same id can be created.
135
+ Organisations cannot be renamed or deleted, and only the installation's owner creates them.
136
+ - `org list` / `org create` / `site delete` need a server with core `org.create` and `sites.delete`
137
+ (`PROCEDURE_UNKNOWN` on an older one).
138
+ - `source add` does not narrow another source for you: when the project's `content` source owns the whole site
139
+ (`/`), it prints the `site set … owns` to run first. `--allow-private-host` is accepted only from the
140
+ installation's owner, and only by a server that takes a new source's `operator` settings (older ones refuse
141
+ it at the field).
130
142
 
131
143
  ## Command reference
132
144
 
@@ -260,6 +272,10 @@ Link this project folder to a site on your Foliwake server: a new one or an exis
260
272
  - `--interactive` / --no-interactive: ask for what the flags leave open (default: only when stdin and stdout are a
261
273
  terminal)
262
274
  - `--link <value>`: link the folder to this existing site
275
+ - `--org <value>`: the new site's organisation (default: the only one where you may create sites; several: asked in a
276
+ terminal, refused without one)
277
+ - `--repository <value>`: the new site's repository (default: this folder's Git origin as an https:// address; `none`:
278
+ no repository yet)
263
279
 
264
280
  ### `foliwake create [folder]`
265
281
 
@@ -274,6 +290,7 @@ Create a new site frontend: blocks, styles, local pages, checks and workflows
274
290
  - `--interactive` / --no-interactive: ask for missing values (default: only when stdin and stdout are a terminal)
275
291
  - `--keep-existing`: the folder is not empty: add the project next to its files (refused if one would be replaced)
276
292
  - `--link-site <value>`: at the end, link the project to this existing site on your Foliwake server, as `site link`
293
+ - `--org <value>`: with --create-site: the site's organisation (default: the only one where you may create sites)
277
294
  - `--overwrite`: the folder is not empty: remove its files first (.git is kept)
278
295
  - `--react` / --no-react: add React support: React and ReactDOM vendored in scripts/vendor/ and the React example block
279
296
  poll; default: asked in a terminal, else no
@@ -392,6 +409,17 @@ never runs an operation again (core operations.recover)
392
409
  is 3
393
410
  - `--wait-timeout <value>`: limit of --wait in seconds (default: settle delay + 90 s)
394
411
 
412
+ ### `foliwake org create [id]`
413
+
414
+ Create an organisation (the installation's owner only); your account becomes its admin. Sites are then created in it
415
+ with `site create --org <id>` (core org.create)
416
+
417
+ - `--name <value>`: the name people see (default: the id)
418
+
419
+ ### `foliwake org list`
420
+
421
+ The organisations you are a member of, with your role (the installation's owner sees every one; core org.list)
422
+
395
423
  ### `foliwake page changes`
396
424
 
397
425
  Compare working pages (text and images) with the live site (core content.changes)
@@ -494,9 +522,21 @@ Bind an existing bucket and its state to a configured site; publishes nothing (c
494
522
  Create this project's site on your Foliwake server (core sites.create; admin)
495
523
 
496
524
  - `--code` / --no-code: send the last commit for release 1 (--no-code: release 1 waits for the first code prepare)
497
- - `--org <value>`: the organisation (default: your only one where you are admin)
525
+ - `--org <value>`: the organisation (default: the only one where you may create sites; several: asked in a terminal,
526
+ refused without one)
498
527
  - `--relink`: replace the link of this folder (.foliwake/connection.json) to another server or site without asking
499
- - `--repository <value>`: where the code will live, e.g. https://github.com/acme/mytest (the server checkout's origin)
528
+ - `--repository <value>`: where the code lives, e.g. https://github.com/acme/mytest (the server checkout's origin;
529
+ default: this folder's Git origin as an https:// address; `none`: no repository yet)
530
+
531
+ ### `foliwake site delete`
532
+
533
+ Delete a site from the server (an admin of its organisation): its settings and history go, its state and checkout are
534
+ set aside, its bucket is kept for the operator to empty. Refused while it works, has live pages (unless --force) or
535
+ memberships, invitations or CI keys name it (core sites.delete)
536
+
537
+ - `--confirm <value>`: the site id, typed again: confirms without a question (needed without a terminal)
538
+ - `--force`: delete a site whose live release has pages (they stop being served)
539
+ - `--site <value>`: site id (default: the site this folder is linked to, else the only site on the server)
500
540
 
501
541
  ### `foliwake site edit`
502
542
 
@@ -565,19 +605,24 @@ Remove this project folder's link to its site (.foliwake/connection.json); the s
565
605
  Adds a content source to a site: checks it first (settings, credentials, connection, files and their addresses), then
566
606
  saves it after a confirmation; nothing is fetched (core sources.probe, sources.add)
567
607
 
608
+ - `--allow-private-host <value>`: a host on a private network the source may reach, e.g. a Drupal inside the server's
609
+ network (operator.allowPrivateHosts; the installation's owner only; repeatable)
568
610
  - `--base-url <value>`: Drupal: the site address
569
611
  - `--basic-password <value>`: Drupal: the credential name of its password
570
612
  - `--basic-user <value>`: Drupal: the credential name of a read-only user name (HTTP Basic)
571
613
  - `--branch <value>`: Git: the branch (default main)
572
614
  - `--check-only`: check and print, save nothing
573
615
  - `--display-name <value>`: the name the dashboard shows
574
- - `--folder <value>`: Google Drive: the folder link or ID
616
+ - `--folder <value>`: Google Drive or Google Docs: the folder link or ID
617
+ - `--force`: save even when the connection check fails
575
618
  - `--id <value>`: the new source id (lower case, digits, "-")
576
619
  - `--identity <value>`: Google Drive: file-id (default; renames keep the page) or front-matter
577
- - `--key <value>`: Google Drive: the credential name of the service-account key (default FOLIWAKE_GOOGLE_SA_KEY)
620
+ - `--key <value>`: Google Drive or Docs: the credential name of the service-account key (default FOLIWAKE_GOOGLE_SA_KEY)
578
621
  - `--language <value>`: Drupal: a language code, the default first (repeatable)
622
+ - `--list-title <value>`: Drupal: the heading of the article list page, per --language in the same order (repeatable)
579
623
  - `--mappings <value>`: a JSON file with path mapping rules (default: each file names its address)
580
624
  - `--owns <value>`: a path the source owns, such as /lessons or "=/" (repeatable)
625
+ - `--page <value>`: Google Docs: <document link or ID>=<page path>, one published page (repeatable)
581
626
  - `--plugin <value>`: the connector
582
627
  - `--repository <value>`: Git: the https address of the repository
583
628
  - `--site <value>`: site id (default: the site this folder is linked to, else the only site on the server)
@@ -596,13 +641,34 @@ paths it owns; preview and live are unchanged (core sources.adoptPages)
596
641
  ### `foliwake source check`
597
642
 
598
643
  Checks content sources without changing anything: settings, credentials, the connection and, with --listing, the files
599
- and the page addresses they would get (core sources.probe)
644
+ and the page addresses they would get; a saved source (--source) or a new one described with the flags of `source add`
645
+ (--id …) (core sources.probe)
600
646
 
647
+ - `--allow-private-host <value>`: a host on a private network the source may reach, e.g. a Drupal inside the server's
648
+ network (operator.allowPrivateHosts; the installation's owner only; repeatable)
649
+ - `--base-url <value>`: Drupal: the site address
650
+ - `--basic-password <value>`: Drupal: the credential name of its password
651
+ - `--basic-user <value>`: Drupal: the credential name of a read-only user name (HTTP Basic)
652
+ - `--branch <value>`: Git: the branch (default main)
653
+ - `--display-name <value>`: the name the dashboard shows
654
+ - `--folder <value>`: Google Drive or Google Docs: the folder link or ID
655
+ - `--id <value>`: the new source id (lower case, digits, "-")
656
+ - `--identity <value>`: Google Drive: file-id (default; renames keep the page) or front-matter
601
657
  - `--input <value>`: raw JSON for the full operation input; overrides the other input flags
658
+ - `--key <value>`: Google Drive or Docs: the credential name of the service-account key (default FOLIWAKE_GOOGLE_SA_KEY)
659
+ - `--language <value>`: Drupal: a language code, the default first (repeatable)
660
+ - `--list-title <value>`: Drupal: the heading of the article list page, per --language in the same order (repeatable)
602
661
  - `--listing`: also list the files and their page addresses (slower: reads the whole source)
662
+ - `--mappings <value>`: a JSON file with path mapping rules (default: each file names its address)
603
663
  - `--max <value>`: at most this many files in the listing (default 500)
664
+ - `--owns <value>`: a path the source owns, such as /lessons or "=/" (repeatable)
665
+ - `--page <value>`: Google Docs: <document link or ID>=<page path>, one published page (repeatable)
666
+ - `--plugin <value>`: the connector
667
+ - `--repository <value>`: Git: the https address of the repository
604
668
  - `--site <value>`: site id (default: the site this folder is linked to, else the only site on the server)
605
669
  - `--source <value>`: one source of the site (default: every enabled source)
670
+ - `--subfolder <value>`: Google Drive or Git: the folder inside that holds the pages
671
+ - `--token <value>`: Git: the credential name of a read-only token (private repository)
606
672
 
607
673
  ### `foliwake source list`
608
674
 
@@ -8,6 +8,8 @@ export default class Connect extends Command {
8
8
  create: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
9
  link: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
10
  server: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ org: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ repository: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
13
  force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
14
  interactive: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
15
  };
@@ -24,6 +24,7 @@ export default class Connect extends Command {
24
24
  static examples = [
25
25
  '<%= config.bin %> connect',
26
26
  '<%= config.bin %> connect --create mysite --server https://foliwake.example',
27
+ '<%= config.bin %> connect --create mysite --org acme --repository https://github.com/acme/mysite',
27
28
  '<%= config.bin %> connect --link docs-en --json',
28
29
  ];
29
30
  static enableJsonFlag = true;
@@ -33,6 +34,16 @@ export default class Connect extends Command {
33
34
  server: Flags.string({
34
35
  description: 'the Foliwake server (origin or host; default: $FOLIWAKE_SERVER, else asked or the only one)',
35
36
  }),
37
+ org: Flags.string({
38
+ dependsOn: ['create'],
39
+ description: "the new site's organisation (default: the only one where you may create sites; several: asked in a " +
40
+ 'terminal, refused without one)',
41
+ }),
42
+ repository: Flags.string({
43
+ dependsOn: ['create'],
44
+ description: "the new site's repository (default: this folder's Git origin as an https:// address; `none`: no " +
45
+ 'repository yet)',
46
+ }),
36
47
  force: Flags.boolean({ description: 'replace the link of a folder that is linked already' }),
37
48
  interactive: Flags.boolean({
38
49
  allowNo: true,
@@ -81,6 +92,8 @@ export default class Connect extends Command {
81
92
  linkSite: flags.link,
82
93
  server: flags.server === undefined ? undefined : this.originOf(flags.server),
83
94
  relink: flags.force,
95
+ org: flags.org,
96
+ repository: flags.repository,
84
97
  prompts: { input: process.stdin, output: process.stdout },
85
98
  signIn: signInHere,
86
99
  onLinked,
@@ -19,6 +19,7 @@ export default class Create extends Command {
19
19
  'link-site': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
20
  server: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
21
21
  relink: import("@oclif/core/interfaces").BooleanFlag<boolean>;
22
+ org: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
22
23
  connect: import("@oclif/core/interfaces").BooleanFlag<boolean>;
23
24
  interactive: import("@oclif/core/interfaces").BooleanFlag<boolean>;
24
25
  help: import("@oclif/core/interfaces").BooleanFlag<void>;
@@ -72,6 +72,10 @@ At the end it can create or link the site on your Foliwake server (--create-site
72
72
  relink: Flags.boolean({
73
73
  description: 'with --create-site or --link-site in a folder already linked elsewhere: replace that link',
74
74
  }),
75
+ org: Flags.string({
76
+ dependsOn: ['create-site'],
77
+ description: "with --create-site: the site's organisation (default: the only one where you may create sites)",
78
+ }),
75
79
  connect: Flags.boolean({
76
80
  allowNo: true,
77
81
  description: '--no-connect: never ask «Connect to a Foliwake server?» (default: asked at the end in a terminal)',
@@ -159,6 +163,7 @@ At the end it can create or link the site on your Foliwake server (--create-site
159
163
  linkSite: flags['link-site'],
160
164
  server,
161
165
  relink: flags.relink,
166
+ org: flags.org,
162
167
  prompts: { input: process.stdin, output: process.stdout },
163
168
  signIn: (await import('../remote/sign-in-here.js')).signInHere,
164
169
  }, io);
@@ -0,0 +1,13 @@
1
+ import { CoreCommand } from '../../core-command.js';
2
+ export default class OrgCreate extends CoreCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static args: {
6
+ id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
7
+ };
8
+ static flags: {
9
+ name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ };
12
+ run(): Promise<unknown>;
13
+ }
@@ -0,0 +1,30 @@
1
+ // `foliwake org create <id>`: a new organisation (core org.create; the installation's owner only).
2
+ import { Args, Flags } from '@oclif/core';
3
+ import { CoreCommand } from '../../core-command.js';
4
+ export default class OrgCreate extends CoreCommand {
5
+ static description = "Create an organisation (the installation's owner only); your account becomes its admin. Sites are then " +
6
+ 'created in it with `site create --org <id>` (core org.create)';
7
+ static examples = [
8
+ '<%= config.bin %> org create acme --name "Acme Ltd"',
9
+ '<%= config.bin %> org create acme --json',
10
+ ];
11
+ static args = {
12
+ id: Args.string({
13
+ required: true,
14
+ description: 'the organisation id: at most 12 lowercase letters, digits and single inner hyphens, starting with a ' +
15
+ 'letter (it is part of branch preview hosts and bucket names)',
16
+ }),
17
+ };
18
+ static flags = {
19
+ ...CoreCommand.configFlag,
20
+ name: Flags.string({ description: 'the name people see (default: the id)' }),
21
+ };
22
+ async run() {
23
+ const { args, flags } = await this.parse(OrgCreate);
24
+ const created = await this.core.org.create({ id: args.id, name: flags.name ?? args.id });
25
+ const role = created.membership ? `; you are its ${created.membership.role}` : '';
26
+ this.log(`Created organisation ${created.id} (${created.name})${role}.`);
27
+ this.log(`Create a site in it: \`foliwake site create <id> --org ${created.id}\`.`);
28
+ return created;
29
+ }
30
+ }
@@ -0,0 +1,9 @@
1
+ import { CoreCommand } from '../../core-command.js';
2
+ export default class OrgList extends CoreCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ };
8
+ run(): Promise<unknown>;
9
+ }
@@ -0,0 +1,25 @@
1
+ // `foliwake org list`: the organisations of the signed-in account, with its role there (core org.list).
2
+ import { CoreCommand } from '../../core-command.js';
3
+ function lineOf(org) {
4
+ const name = org.name && org.name !== org.id ? ` (${org.name})` : '';
5
+ const member = org.membership;
6
+ if (!member)
7
+ return `${org.id}${name} installation, no membership`;
8
+ const live = member.role === 'developer' && member.live ? ', live' : '';
9
+ const sites = member.sites === null ? 'every site' : `sites ${member.sites.join(', ')}`;
10
+ return `${org.id}${name} ${member.role}${live}, ${sites}`;
11
+ }
12
+ export default class OrgList extends CoreCommand {
13
+ static description = "The organisations you are a member of, with your role (the installation's owner sees every one; core org.list)";
14
+ static examples = ['<%= config.bin %> org list', '<%= config.bin %> org list --json'];
15
+ static flags = { ...CoreCommand.configFlag };
16
+ async run() {
17
+ await this.parse(OrgList);
18
+ const orgs = await this.core.org.list();
19
+ for (const org of orgs)
20
+ this.log(lineOf(org));
21
+ if (orgs.length === 0)
22
+ this.log('No organisations.');
23
+ return orgs;
24
+ }
25
+ }
@@ -4,7 +4,8 @@ import { Args, Command, Flags } from '@oclif/core';
4
4
  export default class SiteCreate extends Command {
5
5
  static summary = "Create this project's site on your Foliwake server (core sites.create; admin)";
6
6
  static description = `In a project folder (as \`foliwake create\` makes it), signed in with \`foliwake login\` to ` +
7
- `any Foliwake server: creates the site in your organisation (you must be its admin), with release 1 from the ` +
7
+ `any Foliwake server: creates the site in an organisation where you are admin (--org; never chosen silently), ` +
8
+ `with its repository (--repository, default: the folder's Git origin), and release 1 from the ` +
8
9
  `folder's last commit (its code and pages, sent as a Git bundle), links the folder to it and prints what to ` +
9
10
  `set up next (GitHub, workflows, content sources). Nothing on GitHub is changed. To use a site that exists ` +
10
11
  `already: \`foliwake site link <id>\`.`;
@@ -28,9 +29,13 @@ export default class SiteCreate extends Command {
28
29
  relink: Flags.boolean({
29
30
  description: 'replace the link of this folder (.foliwake/connection.json) to another server or site without asking',
30
31
  }),
31
- org: Flags.string({ description: 'the organisation (default: your only one where you are admin)' }),
32
+ org: Flags.string({
33
+ description: 'the organisation (default: the only one where you may create sites; several: asked in a terminal, ' +
34
+ 'refused without one)',
35
+ }),
32
36
  repository: Flags.string({
33
- description: "where the code will live, e.g. https://github.com/acme/mytest (the server checkout's origin)",
37
+ description: "where the code lives, e.g. https://github.com/acme/mytest (the server checkout's origin; default: this " +
38
+ "folder's Git origin as an https:// address; `none`: no repository yet)",
34
39
  }),
35
40
  code: Flags.boolean({
36
41
  allowNo: true,
@@ -49,7 +54,7 @@ export default class SiteCreate extends Command {
49
54
  server: flags.server,
50
55
  site: args.id,
51
56
  org: flags.org,
52
- repository: flags.repository ?? null,
57
+ repository: flags.repository,
53
58
  code: flags.code,
54
59
  env: process.env,
55
60
  relink: flags.relink,
@@ -0,0 +1,14 @@
1
+ import { CoreCommand } from '../../core-command.js';
2
+ export default class SiteDelete extends CoreCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ confirm: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
8
+ site: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ };
11
+ run(): Promise<unknown>;
12
+ /** The site id typed in a terminal; without one, --confirm is needed. */
13
+ private askSiteId;
14
+ }
@@ -0,0 +1,52 @@
1
+ // `foliwake site delete --site <id>`: remove a site from the server (core sites.delete). Its bucket is kept.
2
+ import { Flags } from '@oclif/core';
3
+ import { CoreCommand } from '../../core-command.js';
4
+ import { COMMAND } from '../../settings.js';
5
+ function resultLines(deleted) {
6
+ const pages = deleted.livePages > 0 ? ` Its ${deleted.livePages} live page(s) are no longer served here.` : '';
7
+ return [
8
+ `Deleted site ${deleted.site} (organisation ${deleted.org}) from the server.${pages}`,
9
+ `Its state and code checkout were set aside on the server (${deleted.foldersSetAside} folder(s), ` +
10
+ 'renamed `<folder>.deleted-<time>`); the operator removes them.',
11
+ "Its bucket was NOT touched: it still holds the site's pages and releases. The installation's operator " +
12
+ "empties or deletes it with the storage provider's tools; a site with this id can be created again only " +
13
+ 'after that.',
14
+ `A folder linked to it keeps its .foliwake/connection.json: \`${COMMAND} site unlink\` there.`,
15
+ ];
16
+ }
17
+ export default class SiteDelete extends CoreCommand {
18
+ static description = 'Delete a site from the server (an admin of its organisation): its settings and history go, its state and ' +
19
+ 'checkout are set aside, its bucket is kept for the operator to empty. Refused while it works, has live pages ' +
20
+ '(unless --force) or memberships, invitations or CI keys name it (core sites.delete)';
21
+ static examples = [
22
+ '<%= config.bin %> site delete --site old-site',
23
+ '<%= config.bin %> site delete --site old-site --confirm old-site --json',
24
+ ];
25
+ static flags = {
26
+ ...CoreCommand.siteFlags,
27
+ confirm: Flags.string({
28
+ description: 'the site id, typed again: confirms without a question (needed without a terminal)',
29
+ }),
30
+ force: Flags.boolean({ description: 'delete a site whose live release has pages (they stop being served)' }),
31
+ };
32
+ async run() {
33
+ const { flags } = await this.parse(SiteDelete);
34
+ const { site } = await this.siteInput(flags.site);
35
+ const confirm = flags.confirm ?? (await this.askSiteId(site));
36
+ const deleted = await this.core.sites.delete({ site, confirm, ...(flags.force ? { force: true } : {}) });
37
+ if (!this.jsonEnabled())
38
+ for (const line of resultLines(deleted))
39
+ this.log(line);
40
+ return deleted;
41
+ }
42
+ /** The site id typed in a terminal; without one, --confirm is needed. */
43
+ async askSiteId(site) {
44
+ if (!process.stdin.isTTY || !process.stdout.isTTY)
45
+ this.error('Not a terminal: pass --confirm <site-id> to delete without being asked.', { exit: 2 });
46
+ const { isCancel, text } = await import('@clack/prompts');
47
+ const answer = await text({ message: `Type the site id (${site}) to delete the site`, placeholder: site });
48
+ if (isCancel(answer))
49
+ this.error('Cancelled; nothing was changed.', { exit: 1 });
50
+ return String(answer).trim();
51
+ }
52
+ }
@@ -1,12 +1,23 @@
1
+ import type { ProbeAnswer } from '../../core-types.js';
1
2
  import { CoreCommand } from '../../core-command.js';
3
+ /** The source that owns the whole site, when that is why the candidate was refused. */
4
+ export declare const wholeSiteOwner: (probe: ProbeAnswer) => string | null;
5
+ /**
6
+ * When another source owns the whole site (`/`, as the project's `content` source of a new site), how to make
7
+ * room: that source keeps the home page and the prefixes its pages use; the new source then owns its own.
8
+ */
9
+ export declare function ownershipHints(owner: string, index: number, site: string): string[];
2
10
  export default class SourceAdd extends CoreCommand {
3
11
  static description: string;
4
12
  static examples: string[];
5
13
  static flags: {
14
+ 'check-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
+ force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
+ yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
6
17
  plugin: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
7
- id: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
18
+ id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
19
  'display-name': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
- owns: import("@oclif/core/interfaces").OptionFlag<string[], import("@oclif/core/interfaces").CustomOptions>;
20
+ owns: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
21
  mappings: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
22
  folder: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
23
  subfolder: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -19,13 +30,17 @@ export default class SourceAdd extends CoreCommand {
19
30
  language: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
31
  'basic-user': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
21
32
  'basic-password': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
22
- 'check-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
23
- yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
33
+ 'list-title': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
34
+ page: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
35
+ 'allow-private-host': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
24
36
  site: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
25
37
  config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
26
38
  };
27
39
  run(): Promise<unknown>;
28
40
  private print;
41
+ private explainOwnership;
42
+ /** A source whose connection check failed is not saved unless --force. */
43
+ private refuseFailed;
29
44
  private finishCheck;
30
45
  /** --yes, or a person who says yes in a terminal; a failed connection is said before the question. */
31
46
  private confirmed;
@@ -4,8 +4,27 @@ import { Errors, Flags } from '@oclif/core';
4
4
  import { CoreCommand } from '../../core-command.js';
5
5
  import { addLines } from '../../render/add.js';
6
6
  import { probeLines } from '../../render/probe.js';
7
- import { DEFAULT_DRIVE_KEY, DRIVE_PLUGIN, entryOf } from '../../source-entry.js';
7
+ import { entryOf } from '../../source-entry.js';
8
+ import { entryFlags } from '../../source-flags.js';
8
9
  const usable = (probe) => Object.keys(probe.fields).length === 0;
10
+ const WHOLE_SITE = /"([a-z0-9-]+)" owns the whole site/;
11
+ /** The source that owns the whole site, when that is why the candidate was refused. */
12
+ export const wholeSiteOwner = (probe) => Object.values(probe.fields)
13
+ .map((message) => WHOLE_SITE.exec(message)?.[1])
14
+ .find((owner) => Boolean(owner)) ?? null;
15
+ /**
16
+ * When another source owns the whole site (`/`, as the project's `content` source of a new site), how to make
17
+ * room: that source keeps the home page and the prefixes its pages use; the new source then owns its own.
18
+ */
19
+ export function ownershipHints(owner, index, site) {
20
+ return [
21
+ '',
22
+ `Source "${owner}" owns the whole site (/), so no other source can own pages beside it. Narrow it to the home`,
23
+ 'page and the prefixes its pages use (`source check --source <id> --listing` shows them), then add this',
24
+ 'source again, e.g.:',
25
+ ` foliwake site set --site ${site} sources.${index}.owns '["=/", "/blocks"]'`,
26
+ ];
27
+ }
9
28
  async function readRules(file) {
10
29
  if (file === undefined)
11
30
  return undefined;
@@ -25,38 +44,15 @@ export default class SourceAdd extends CoreCommand {
25
44
  '<%= config.bin %> source add --site docs --plugin git-markdown --id docs --owns /docs ' +
26
45
  '--repository https://github.com/acme/docs',
27
46
  '<%= config.bin %> source add --site news --plugin drupal --id news --owns /articles ' +
28
- '--base-url https://cms.example.org --language en',
47
+ '--base-url https://cms.example.org --language en --list-title "News"',
48
+ '<%= config.bin %> source add --site docs --plugin google-docs --id guides --owns /guides ' +
49
+ '--page https://docs.google.com/document/d/1AbC…/edit=/guides/intro',
29
50
  ];
30
51
  static flags = {
31
52
  ...CoreCommand.siteFlags,
32
- plugin: Flags.string({ description: 'the connector', default: DRIVE_PLUGIN }),
33
- id: Flags.string({ description: 'the new source id (lower case, digits, "-")', required: true }),
34
- 'display-name': Flags.string({ description: 'the name the dashboard shows' }),
35
- owns: Flags.string({
36
- description: 'a path the source owns, such as /lessons or "=/" (repeatable)',
37
- multiple: true,
38
- required: true,
39
- }),
40
- mappings: Flags.string({
41
- description: 'a JSON file with path mapping rules (default: each file names its address)',
42
- }),
43
- folder: Flags.string({ description: 'Google Drive: the folder link or ID' }),
44
- subfolder: Flags.string({ description: 'Google Drive or Git: the folder inside that holds the pages' }),
45
- identity: Flags.string({
46
- description: 'Google Drive: file-id (default; renames keep the page) or front-matter',
47
- options: ['file-id', 'front-matter'],
48
- }),
49
- key: Flags.string({
50
- description: `Google Drive: the credential name of the service-account key (default ${DEFAULT_DRIVE_KEY})`,
51
- }),
52
- repository: Flags.string({ description: 'Git: the https address of the repository' }),
53
- branch: Flags.string({ description: 'Git: the branch (default main)' }),
54
- token: Flags.string({ description: 'Git: the credential name of a read-only token (private repository)' }),
55
- 'base-url': Flags.string({ description: 'Drupal: the site address' }),
56
- language: Flags.string({ description: 'Drupal: a language code, the default first (repeatable)', multiple: true }),
57
- 'basic-user': Flags.string({ description: 'Drupal: the credential name of a read-only user name (HTTP Basic)' }),
58
- 'basic-password': Flags.string({ description: 'Drupal: the credential name of its password' }),
53
+ ...entryFlags({ required: true }),
59
54
  'check-only': Flags.boolean({ description: 'check and print, save nothing' }),
55
+ force: Flags.boolean({ description: 'save even when the connection check fails' }),
60
56
  yes: Flags.boolean({ description: 'save without asking (scripts)' }),
61
57
  };
62
58
  async run() {
@@ -67,8 +63,12 @@ export default class SourceAdd extends CoreCommand {
67
63
  throw new Errors.CLIError(built.problem, { exit: 2 });
68
64
  const probe = await this.core.sources.probe({ site, candidate: built.value, listing: {} });
69
65
  this.print(probeLines(probe));
66
+ if (!usable(probe))
67
+ await this.explainOwnership(probe, site);
70
68
  if (!usable(probe) || flags['check-only'])
71
69
  return this.finishCheck(probe);
70
+ if (probe.connection?.ok === false && !flags.force)
71
+ return this.refuseFailed(probe);
72
72
  if (!(await this.confirmed(flags.yes, probe)))
73
73
  return { probe, saved: null };
74
74
  const saved = await this.core.sources.add({
@@ -84,6 +84,19 @@ export default class SourceAdd extends CoreCommand {
84
84
  for (const line of lines)
85
85
  this.log(line);
86
86
  }
87
+ async explainOwnership(probe, site) {
88
+ const owner = wholeSiteOwner(probe);
89
+ if (owner === null)
90
+ return;
91
+ const { sources } = await this.core.sources.list({ site });
92
+ this.print(ownershipHints(owner, Math.max(0, sources.findIndex((source) => source.id === owner)), site));
93
+ }
94
+ /** A source whose connection check failed is not saved unless --force. */
95
+ refuseFailed(probe) {
96
+ this.logToStderr('The connection check failed; nothing was saved. Fix it and run again, or pass --force.');
97
+ process.exitCode = 1;
98
+ return { probe, saved: null };
99
+ }
87
100
  finishCheck(probe) {
88
101
  if (!usable(probe) || probe.connection?.ok === false)
89
102
  process.exitCode = 1;