@mondarth/create-docs 0.1.0 → 0.2.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/dist/check.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { execFile } from 'node:child_process';
2
- import { KEY_SECRET } from './templates.js';
2
+ import { keySecretOf } from './templates.js';
3
3
  /** The GitHub CLI on this machine. */
4
4
  export const gh = args => new Promise(resolve => {
5
5
  execFile('gh', args, { encoding: 'utf8' }, (error, stdout, stderr) => {
@@ -12,7 +12,7 @@ export function setupStep(manifest, branch) {
12
12
  ? `In the repository's Settings > Pages, set Source to GitHub Actions. Then, in Settings > Environments >` +
13
13
  ` github-pages > Deployment branches and tags, make sure ${branch} may deploy.`
14
14
  : `Add the upload key for ${manifest.product}/${manifest.set} on docs.mondarth.com as the repository secret` +
15
- ` ${KEY_SECRET}: \`gh secret set ${KEY_SECRET}\`, and paste the key.`;
15
+ ` ${keySecretOf(manifest)}: \`gh secret set ${keySecretOf(manifest)}\`, and paste the key.`;
16
16
  }
17
17
  /** Whether the branch is one a deployment branch policy's name, a branch name or a pattern of `*`s, allows. */
18
18
  function allows(pattern, branch) {
@@ -75,16 +75,16 @@ async function checkPages(run, repo, branch) {
75
75
  }
76
76
  return findings;
77
77
  }
78
- async function checkKey(run, repo) {
78
+ async function checkKey(run, repo, secret) {
79
79
  const secrets = await run(['secret', 'list', '--repo', repo, '--json', 'name', '--jq', '.[].name']);
80
80
  if (!secrets.ok) {
81
81
  return [
82
82
  { ok: false, message: `Cannot list the repository's secrets: ${secrets.stderr || 'gh secret list failed'}` },
83
83
  ];
84
84
  }
85
- return secrets.stdout.split('\n').includes(KEY_SECRET)
86
- ? [{ ok: true, message: `The upload key is set (${KEY_SECRET})` }]
87
- : [{ ok: false, message: `The upload key is not set: ${KEY_SECRET} is not among the repository's secrets` }];
85
+ return secrets.stdout.split('\n').includes(secret)
86
+ ? [{ ok: true, message: `The upload key is set (${secret})` }]
87
+ : [{ ok: false, message: `The upload key is not set: ${secret} is not among the repository's secrets` }];
88
88
  }
89
89
  /** Checks the set's repository is set up to publish it, as its audience requires. */
90
90
  export async function check(manifest, branch, run = gh) {
@@ -101,5 +101,7 @@ export async function check(manifest, branch, run = gh) {
101
101
  if (!repo.ok || repo.stdout === '') {
102
102
  return [{ ok: false, message: 'This is not a GitHub repository the GitHub CLI knows: push it to GitHub first' }];
103
103
  }
104
- return manifest.audience === 'internal' ? checkPages(run, repo.stdout, branch) : checkKey(run, repo.stdout);
104
+ return manifest.audience === 'internal'
105
+ ? checkPages(run, repo.stdout, branch)
106
+ : checkKey(run, repo.stdout, keySecretOf(manifest));
105
107
  }
package/dist/cli.js CHANGED
@@ -10,7 +10,7 @@ import { CreateDocsError } from './errors.js';
10
10
  import { AUDIENCES, SLUG, problemsOf, readManifest, requireManifest, } from './manifest.js';
11
11
  import { SITE, publish } from './publish.js';
12
12
  import { readLock, scaffold } from './scaffold.js';
13
- import { KEY_SECRET } from './templates.js';
13
+ import { KEY_VARIABLE } from './templates.js';
14
14
  import { documentedPackage, tagPrefixOf } from './version.js';
15
15
  const HELP = `Adds a documentation set, built with Mondarth's Sphinx theme, to the repository, or brings it up to date.
16
16
  Run it from the repository's root.
@@ -19,7 +19,7 @@ Run it from the repository's root.
19
19
  create-docs check [--dir] check the repository is set up to publish the set
20
20
  create-docs version [--dir] print the version of the package the set documents
21
21
  create-docs publish --dir <dir> --version <version>
22
- upload a public set's build to docs.mondarth.com (key: ${KEY_SECRET})
22
+ upload a public set's build to docs.mondarth.com (key: ${KEY_VARIABLE})
23
23
 
24
24
  Options:
25
25
  --dir <path> the set's folder (docs)
@@ -226,7 +226,7 @@ export async function main(argv, io) {
226
226
  manifest,
227
227
  html: join(folder, '_build', 'html'),
228
228
  version: values.version,
229
- key: io.env[KEY_SECRET],
229
+ key: io.env[KEY_VARIABLE],
230
230
  site: io.env.MONDARTH_DOCS_URL ?? SITE,
231
231
  ...(io.send === undefined ? {} : { send: io.send }),
232
232
  });
package/dist/publish.js CHANGED
@@ -2,7 +2,7 @@ import { execFile } from 'node:child_process';
2
2
  import { access } from 'node:fs/promises';
3
3
  import { join } from 'node:path';
4
4
  import { CreateDocsError } from './errors.js';
5
- import { KEY_SECRET } from './templates.js';
5
+ import { KEY_VARIABLE, keySecretOf } from './templates.js';
6
6
  import { checkedVersion } from './version.js';
7
7
  /**
8
8
  * Uploads a public set's built HTML to docs.mondarth.com, as one of its versions. The upload, as the site takes it:
@@ -42,7 +42,7 @@ async function refusal(response, manifest) {
42
42
  }
43
43
  switch (response.status) {
44
44
  case 401:
45
- return `docs.mondarth.com refused the key${said}. Is ${KEY_SECRET} the key for ${set}?`;
45
+ return `docs.mondarth.com refused the key${said}. Is ${keySecretOf(manifest)} the key for ${set}?`;
46
46
  case 403:
47
47
  return `The key may not publish ${set}${said}: it is another set's`;
48
48
  case 413:
@@ -61,7 +61,7 @@ export async function publish(options) {
61
61
  }
62
62
  if (key === undefined || key === '') {
63
63
  throw new CreateDocsError(`No upload key: add ${manifest.product}/${manifest.set}'s key for docs.mondarth.com as the repository secret` +
64
- ` ${KEY_SECRET}, and pass it to this step as the environment variable ${KEY_SECRET}`);
64
+ ` ${keySecretOf(manifest)}, and pass it to this step as the environment variable ${KEY_VARIABLE}`);
65
65
  }
66
66
  try {
67
67
  await access(join(html, 'index.html'));
package/dist/templates.js CHANGED
@@ -17,8 +17,15 @@ export const ACTIONS = {
17
17
  uploadPages: 'actions/upload-pages-artifact@v5',
18
18
  deployPages: 'actions/deploy-pages@v5',
19
19
  };
20
- /** The secret a public set's upload key is kept in. */
21
- export const KEY_SECRET = 'MONDARTH_DOCS_KEY';
20
+ /** The environment variable `create-docs publish` reads a set's upload key from. */
21
+ export const KEY_VARIABLE = 'MONDARTH_DOCS_KEY';
22
+ /**
23
+ * The repository secret a public set's upload key is kept in: its own, named for it, as a key uploads its own set alone
24
+ * and a repository may hold several sets, such as `MONDARTH_DOCS_KEY_EMMA_EXTENSION` for emma/extension.
25
+ */
26
+ export function keySecretOf(manifest) {
27
+ return `${KEY_VARIABLE}_${manifest.product}_${manifest.set}`.toUpperCase().replaceAll('-', '_');
28
+ }
22
29
  /** The generated workflow's file, from the repository's root. */
23
30
  export function workflowPath(manifest) {
24
31
  return `.github/workflows/docs-${manifest.product}-${manifest.set}.yml`;
@@ -156,7 +163,7 @@ on:
156
163
  type: string
157
164
  default: ''
158
165
  secrets:
159
- ${KEY_SECRET}:
166
+ ${keySecretOf(manifest)}:
160
167
  required: true
161
168
  workflow_dispatch:
162
169
  inputs:
@@ -190,7 +197,7 @@ ${setupSteps()}
190
197
  done
191
198
  env:
192
199
  VERSIONS: \${{ inputs.versions }}
193
- ${KEY_SECRET}: \${{ secrets.${KEY_SECRET} }}
200
+ ${KEY_VARIABLE}: \${{ secrets.${keySecretOf(manifest)} }}
194
201
  `;
195
202
  }
196
203
  /** The workflow of an internal set: built on pull requests, published to GitHub Pages from its branch. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mondarth/create-docs",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Adds a documentation set, built with Mondarth's Sphinx theme, to a repository: `pnpm create @mondarth/docs`.",
5
5
  "license": "MIT",
6
6
  "type": "module",