@rathnasgala/cli 1.1.17 → 1.1.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rathnasgala/cli",
3
- "version": "1.1.17",
3
+ "version": "1.1.18",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -1,6 +1,7 @@
1
1
  import path from 'node:path';
2
2
 
3
3
  import { galaApi } from '../api/gala.js';
4
+ import { HttpError } from '../api/http.js';
4
5
  import { accountForCommand } from '../auth/checkout-profile.js';
5
6
  import { authenticatedProfile } from '../auth/profiles.js';
6
7
  import { UsageError } from '../cli/args.js';
@@ -24,7 +25,8 @@ export async function domain({ terminal, options, cwd = process.cwd() }) {
24
25
  if (action !== 'set' && value != null) throw new UsageError(`domain ${action} takes no hostname`);
25
26
 
26
27
  const account = await accountForCommand(options, root, { terminal });
27
- const credential = (await authenticatedProfile({ name: account, terminal })).gala;
28
+ const profile = await authenticatedProfile({ name: account, terminal });
29
+ const credential = profile.gala;
28
30
  const api = galaApi({ baseUrl: credential.apiBaseUrl, token: credential.accessToken });
29
31
 
30
32
  if (action === 'status') {
@@ -41,13 +43,14 @@ export async function domain({ terminal, options, cwd = process.cwd() }) {
41
43
  if (action === 'set') {
42
44
  const checked = customDomain(value);
43
45
  if (checked.error) throw new UsageError(checked.error);
46
+ const site = await ownedSite(api, publication.siteId);
47
+ const owner = site.repository.split('/')[0];
44
48
  const change = await api.prepareTopologyChange(publication.siteId, {
45
49
  canonicalBaseUrl: `https://${checked.host}`,
46
50
  pathPrefix: '/',
47
51
  });
48
52
  terminal.done(`Reserved ${checked.host}`);
49
- terminal.note(`Verify it in the repository owner’s GitHub account, then run: ${cliCommand('domain check')}`);
50
- terminal.openUrl('https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/verifying-your-custom-domain-for-github-pages');
53
+ showVerificationSteps(terminal, checked.host, owner, profile.metadata.githubLogin);
51
54
  return change;
52
55
  }
53
56
 
@@ -81,7 +84,17 @@ export async function domain({ terminal, options, cwd = process.cwd() }) {
81
84
 
82
85
  if (action === 'check') {
83
86
  if (pending.cname && pending.state === 'PREPARED') {
84
- const configured = await api.configureTopologyChange(publication.siteId, pending.changeId);
87
+ let configured;
88
+ try {
89
+ configured = await api.configureTopologyChange(publication.siteId, pending.changeId);
90
+ } catch (failure) {
91
+ if (!(failure instanceof HttpError)
92
+ || failure.code !== 'GITHUB_PAGES_DOMAIN_VERIFICATION_REQUIRED') throw failure;
93
+ const site = await ownedSite(api, publication.siteId);
94
+ const owner = site.repository.split('/')[0];
95
+ showVerificationSteps(terminal, pending.cname, owner, profile.metadata.githubLogin);
96
+ throw new Error(`GitHub has not verified ${pending.cname} for @${owner} yet. Complete the steps above, then retry.`);
97
+ }
85
98
  terminal.done(`GitHub verified ${configured.cname}`);
86
99
  terminal.note(dnsInstruction(configured.cname, await providerHost(api, publication.siteId)));
87
100
  terminal.note(`After DNS propagates, run: ${cliCommand('domain check')}`);
@@ -100,6 +113,16 @@ export async function domain({ terminal, options, cwd = process.cwd() }) {
100
113
  throw new UsageError(`Unsupported domain action: ${action}`);
101
114
  }
102
115
 
116
+ function showVerificationSteps(terminal, host, owner, login) {
117
+ terminal.note(`GitHub owner @${owner} must verify ${host} once under Settings → Pages → Verified domains.`);
118
+ terminal.openUrl(owner.toLowerCase() === login.toLowerCase()
119
+ ? 'https://github.com/settings/pages'
120
+ : `https://github.com/organizations/${encodeURIComponent(owner)}/settings/pages`);
121
+ terminal.note(`Choose “Add a domain”, enter ${host}, and add GitHub’s TXT record at your DNS provider.`);
122
+ terminal.note(`The TXT record name will be _github-pages-challenge-${owner}.${host}; GitHub supplies its value.`);
123
+ terminal.note(`When GitHub shows “Verified”, run: ${cliCommand('domain check')}`);
124
+ }
125
+
103
126
  async function ownedSite(api, siteId) {
104
127
  const sites = await api.listPublications();
105
128
  const site = Array.isArray(sites) ? sites.find((candidate) => candidate.siteId === siteId) : null;