@mark1russell7/site-pages 0.8.5 → 0.8.6
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/README.md
CHANGED
|
@@ -157,7 +157,7 @@ By default, the check only reports each text, and the view does not fail. The lo
|
|
|
157
157
|
{ "sitePages": { "bareErrors": "fail" } }
|
|
158
158
|
```
|
|
159
159
|
|
|
160
|
-
The option `--bare-errors fail` or `--bare-errors report` overrides the field. Turn the failure on when the report of the site gives no text.
|
|
160
|
+
The option `--bare-errors fail` or `--bare-errors report` overrides the field. In `reusable-pages.yml`, the key `site-check-bare-errors` of `.github/site.json` gives the option. A repository with one package uses the key: the field changes the `package.json` of its npm release. Turn the failure on when the report of the site gives no text.
|
|
161
161
|
|
|
162
162
|
The folder of `--shots` gets a screenshot of each view, `report.json` and `summary.md`. The exit code is 0 when each view and each budget passes. It is 1 when a view or a budget fails, and 2 for an incorrect command line.
|
|
163
163
|
|
|
@@ -59,6 +59,8 @@ export interface SiteConfig {
|
|
|
59
59
|
readonly "site-check-widths": string;
|
|
60
60
|
/** A probe script of the site check. */
|
|
61
61
|
readonly "site-check-probe": string;
|
|
62
|
+
/** What a text with the shape of an error outside an error view does: `fail` or `report`. Empty reads `sitePages.bareErrors` of package.json. */
|
|
63
|
+
readonly "site-check-bare-errors": string;
|
|
62
64
|
/** The Playwright version of the site check. */
|
|
63
65
|
readonly "site-check-playwright": string;
|
|
64
66
|
/** The Playwright browsers of the build, with spaces between them. The action `setup-playwright` installs them before the build. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site-config.d.ts","names":[],"sources":["../../src/config/site-config.ts"],"mappings":";;;;;;;;;;;;;;qBAea;;YAGD;;iBAGK;;WAEN;;WAEA;;WAEA,KAAK,SAAS;;WAEd;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;YAIC,sBAAsB;;iBAGjB,kBAAkB;WACxB,MAAM;WACN,SAAS;;;qBAIP,8BAA8B,KAAK,gBAAgB,kBAAkB,WAAW;;
|
|
1
|
+
{"version":3,"file":"site-config.d.ts","names":[],"sources":["../../src/config/site-config.ts"],"mappings":";;;;;;;;;;;;;;qBAea;;YAGD;;iBAGK;;WAEN;;WAEA;;WAEA,KAAK,SAAS;;WAEd;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;YAIC,sBAAsB;;iBAGjB,kBAAkB;WACxB,MAAM;WACN,SAAS;;;qBAIP,8BAA8B,KAAK,gBAAgB,kBAAkB,WAAW;;iBAkC5E;;WAEN;;WAEA;;WAEA,QAAQ,SAAS;;WAEjB;;;YAIC;WAA8B,QAAQ;WAAqB;;WAAyC;;;wBAKhG,eAAe,eAAe;;;;;wBA4B9B,YAAY,QAAQ,SAAS,2BAA2B;;;;;wBAaxD,kBAAkB,OAAO,kBAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site-config.js","names":[],"sources":["../../src/config/site-config.ts"],"sourcesContent":["/**\n * The site config of a repository: the one home of the inputs of its site build (CI.md, \"The site config\").\n *\n * The file `.github/site.json` of the repository holds them. `reusable-pages.yml` (build and deploy) and\n * `reusable-pages-check.yml` (the check of a pull request) read it with `main.ts` of this folder. Thus the two\n * workflows build the same site, and each value has one home. The rules of `@mark1russell7/conventions` read it too.\n *\n * A repository with no file gives the old inputs of `reusable-pages.yml`, and the resolver takes them. Thus an old\n * caller keeps its site. A repository that has the file and also gives a site input gets an error.\n *\n * In each string value, `{owner}` is the owner of the repository and `{repo}` is its name. This file imports nothing,\n * so the workflow starts it from the template commit with no install.\n */\n\n/** The path of the site config in a repository. */\nexport const SITE_CONFIG_PATH = \".github/site.json\";\n\n/** The type of a key: a string, a boolean or a map of environment variables. */\nexport type SiteConfigKind = \"string\" | \"boolean\" | \"env\";\n\n/** The site config: a value for each key. CI.md tells each key. */\nexport interface SiteConfig {\n /** The command that builds the site. It is the one necessary key, with `out`. */\n readonly build: string;\n /** The folder of the built site. */\n readonly out: string;\n /** The environment variables of the build. `{owner}` and `{repo}` change in each value. */\n readonly env: Readonly<Record<string, string>>;\n /** `true` gives the build the token of the job as `GITHUB_TOKEN`. */\n readonly \"github-token\": boolean;\n /** The Node.js version of the build. */\n readonly \"node-version\": string;\n /** A file with the Node.js version, for example `.nvmrc`. It replaces `node-version`. */\n readonly \"node-version-file\": string;\n /** `true` adds the Releases page and the Status page. */\n readonly \"site-pages\": boolean;\n /** The npm version of site-pages for its pages. Empty uses the template commit. */\n readonly \"site-pages-version\": string;\n /** The roadmap file of the Status page, for example `docs/ROADMAP.md`. */\n readonly roadmap: string;\n /** The base path of the site, for example `/{repo}/`. */\n readonly base: string;\n /** The npm packages of the Releases page, with commas between them. */\n readonly packages: string;\n /** The folder of the changesets of the Status page. */\n readonly changesets: string;\n /** The group of the pages of the site. */\n readonly group: string;\n /** A style file of the site for the pages of site-pages. */\n readonly css: string;\n /** The name of the site in the bar and in the titles. */\n readonly \"site-name\": string;\n /** `true` writes only the data files of the pages, with no HTML. */\n readonly \"data-only\": boolean;\n /** A file of data stamps, for the freshness gate. */\n readonly \"data-stamps\": string;\n /** `true` checks the pages in a browser at each width. */\n readonly \"site-check\": boolean;\n /** The pages of the site check, with commas between them. */\n readonly \"site-check-pages\": string;\n /** The widths of the site check, with commas between them. */\n readonly \"site-check-widths\": string;\n /** A probe script of the site check. */\n readonly \"site-check-probe\": string;\n /** The Playwright version of the site check. */\n readonly \"site-check-playwright\": string;\n /** The Playwright browsers of the build, with spaces between them. The action `setup-playwright` installs them before the build. */\n readonly \"playwright-browsers\": string;\n /** The command that runs the Playwright CLI of the repository, for the install of `playwright-browsers`. */\n readonly \"playwright-command\": string;\n /** `true` gives each page the bar of the site. */\n readonly \"site-bar\": boolean;\n /** The pages of the bar, with commas between them. */\n readonly \"site-bar-pages\": string;\n /** The npm name of the package of the site, for the npm link of the bar. */\n readonly \"site-bar-npm\": string;\n /** `true` gives each code block the scroll cue. */\n readonly \"scroll-cue\": boolean;\n /** A key of IndexNow. After each deploy that is not scheduled, the URLs go to the engines. */\n readonly \"indexnow-key\": string;\n}\n\n/** A key of the site config. */\nexport type SiteConfigKey = keyof SiteConfig;\n\n/** The type and the default of one key. The defaults are those of the inputs of `reusable-pages.yml`. */\nexport interface SiteConfigKeySpec<T> {\n readonly kind: SiteConfigKind;\n readonly default: T;\n}\n\n/** The keys of the site config, with their types and their defaults. */\nexport const SITE_CONFIG_KEYS: { readonly [K in SiteConfigKey]: SiteConfigKeySpec<SiteConfig[K]> } = {\n build: { kind: \"string\", default: \"\" },\n out: { kind: \"string\", default: \"\" },\n env: { kind: \"env\", default: {} },\n \"github-token\": { kind: \"boolean\", default: false },\n \"node-version\": { kind: \"string\", default: \"26\" },\n \"node-version-file\": { kind: \"string\", default: \"\" },\n \"site-pages\": { kind: \"boolean\", default: true },\n \"site-pages-version\": { kind: \"string\", default: \"\" },\n roadmap: { kind: \"string\", default: \"\" },\n base: { kind: \"string\", default: \"\" },\n packages: { kind: \"string\", default: \"\" },\n changesets: { kind: \"string\", default: \"\" },\n group: { kind: \"string\", default: \"\" },\n css: { kind: \"string\", default: \"\" },\n \"site-name\": { kind: \"string\", default: \"\" },\n \"data-only\": { kind: \"boolean\", default: false },\n \"data-stamps\": { kind: \"string\", default: \"\" },\n \"site-check\": { kind: \"boolean\", default: false },\n \"site-check-pages\": { kind: \"string\", default: \"\" },\n \"site-check-widths\": { kind: \"string\", default: \"\" },\n \"site-check-probe\": { kind: \"string\", default: \"\" },\n \"site-check-playwright\": { kind: \"string\", default: \"1.64.1\" },\n \"playwright-browsers\": { kind: \"string\", default: \"\" },\n \"playwright-command\": { kind: \"string\", default: \"npx --no-install playwright\" },\n \"site-bar\": { kind: \"boolean\", default: false },\n \"site-bar-pages\": { kind: \"string\", default: \"\" },\n \"site-bar-npm\": { kind: \"string\", default: \"\" },\n \"scroll-cue\": { kind: \"boolean\", default: true },\n \"indexnow-key\": { kind: \"string\", default: \"\" },\n};\n\n/** The input of {@link resolveSiteConfig}. */\nexport interface SiteConfigInput {\n /** The text of .github/site.json, or undefined when the repository has no such file. */\n readonly file: string | undefined;\n /** The path of the file, for the messages. */\n readonly path: string;\n /** The inputs of the workflow (toJSON(inputs)), or undefined when the workflow has no old inputs. */\n readonly inputs: Readonly<Record<string, unknown>> | undefined;\n /** The repository, \"owner/name\". */\n readonly repository: string;\n}\n\n/** The site config and its source, or an error. */\nexport type SiteConfigResult = { readonly config: SiteConfig; readonly source: \"file\" | \"inputs\" } | { readonly error: string };\n\nconst NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/** This function puts the owner and the name of the repository in for {owner} and {repo}. */\nexport function fillRepository(value: string, repository: string): string {\n const [owner = \"\", repo = \"\"] = repository.split(\"/\");\n return value.replaceAll(\"{owner}\", owner).replaceAll(\"{repo}\", repo);\n}\n\n/** This function checks one value against the type of its key, and gives the value or an error. */\nfunction check(key: SiteConfigKey, value: unknown, where: string, repository: string): { value: SiteConfig[SiteConfigKey] } | { error: string } {\n const kind: SiteConfigKind = SITE_CONFIG_KEYS[key].kind;\n if (kind === \"boolean\") {\n return typeof value === \"boolean\" ? { value } : { error: `${where}: \"${key}\" must be true or false.` };\n }\n if (kind === \"string\") {\n return typeof value === \"string\" ? { value: fillRepository(value, repository) } : { error: `${where}: \"${key}\" must be a string.` };\n }\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return { error: `${where}: \"env\" must be an object of strings.` };\n const env: Record<string, string> = {};\n for (const [name, text] of Object.entries(value)) {\n if (!NAME.test(name)) return { error: `${where}: \"${name}\" of \"env\" is not a name of an environment variable.` };\n if (typeof text !== \"string\") return { error: `${where}: the value of \"${name}\" of \"env\" must be a string.` };\n env[name] = fillRepository(text, repository);\n }\n return { value: env };\n}\n\n/**\n * This function gives the keys of the site config that the inputs of a workflow give with a value other than the default.\n * The input `env` of `reusable-pages.yml` is a JSON string, and `\"{}\"` or an empty string is its default.\n */\nexport function inputsGiven(inputs: Readonly<Record<string, unknown>>): SiteConfigKey[] {\n return (Object.keys(SITE_CONFIG_KEYS) as SiteConfigKey[]).filter((key) => {\n const value = inputs[key];\n if (value === undefined) return false;\n if (key === \"env\") return !(value === \"\" || (typeof value === \"string\" && value.replace(/\\s/g, \"\") === \"{}\"));\n return value !== SITE_CONFIG_KEYS[key].default;\n });\n}\n\n/**\n * This function gives the site config of a repository from its file, or from the old inputs when it has no file. The\n * workflow uses only the file. Thus a repository with the file gets an error for a site input that is not its default.\n */\nexport function resolveSiteConfig(input: SiteConfigInput): SiteConfigResult {\n const config = Object.fromEntries(Object.entries(SITE_CONFIG_KEYS).map(([key, spec]) => [key, spec.default])) as Record<SiteConfigKey, unknown>;\n let source: \"file\" | \"inputs\";\n if (input.file !== undefined) {\n const given = input.inputs === undefined ? [] : inputsGiven(input.inputs);\n if (given.length > 0) {\n return { error: `The repository has ${input.path} and the workflow also gives the inputs ${given.join(\", \")}. Give the site values only in ${input.path}.` };\n }\n let data: unknown;\n try {\n data = JSON.parse(input.file);\n } catch (error) {\n return { error: `${input.path} is not JSON: ${(error as Error).message}` };\n }\n if (data === null || typeof data !== \"object\" || Array.isArray(data)) return { error: `${input.path} must be a JSON object.` };\n for (const [key, value] of Object.entries(data)) {\n if (key === \"$schema\" || key === \"$comment\") continue;\n if (!Object.hasOwn(SITE_CONFIG_KEYS, key)) return { error: `${input.path}: \"${key}\" is not a key of the site config. CI.md tells the keys.` };\n const checked = check(key as SiteConfigKey, value, input.path, input.repository);\n if (\"error\" in checked) return checked;\n config[key as SiteConfigKey] = checked.value;\n }\n source = \"file\";\n } else if (input.inputs !== undefined) {\n for (const key of Object.keys(SITE_CONFIG_KEYS) as SiteConfigKey[]) {\n let value = input.inputs[key];\n if (value === undefined) continue;\n // The input env of reusable-pages.yml is a JSON string, and an empty string means no variables.\n if (key === \"env\") {\n if (value === \"\") continue;\n try {\n value = JSON.parse(String(value));\n } catch (error) {\n return { error: `The input env is not JSON: ${(error as Error).message}` };\n }\n }\n const checked = check(key, value, \"the inputs\", input.repository);\n if (\"error\" in checked) return checked;\n config[key] = checked.value;\n }\n source = \"inputs\";\n } else {\n return { error: `The repository has no ${input.path}. The check of the site needs the file (CI.md, \"The site config\").` };\n }\n for (const key of [\"build\", \"out\"] as const) {\n if (config[key] === \"\") {\n const home = source === \"file\" ? input.path : \"the inputs of the workflow\";\n return { error: `${home} gives no \"${key}\". The site config needs \"build\" and \"out\".` };\n }\n }\n return { config: config as SiteConfig, source };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,mBAAmB;;AA6EhC,MAAa,mBAAwF;CACnG,OAAO;EAAE,MAAM;EAAU,SAAS;CAAG;CACrC,KAAK;EAAE,MAAM;EAAU,SAAS;CAAG;CACnC,KAAK;EAAE,MAAM;EAAO,SAAS,CAAC;CAAE;CAChC,gBAAgB;EAAE,MAAM;EAAW,SAAS;CAAM;CAClD,gBAAgB;EAAE,MAAM;EAAU,SAAS;CAAK;CAChD,qBAAqB;EAAE,MAAM;EAAU,SAAS;CAAG;CACnD,cAAc;EAAE,MAAM;EAAW,SAAS;CAAK;CAC/C,sBAAsB;EAAE,MAAM;EAAU,SAAS;CAAG;CACpD,SAAS;EAAE,MAAM;EAAU,SAAS;CAAG;CACvC,MAAM;EAAE,MAAM;EAAU,SAAS;CAAG;CACpC,UAAU;EAAE,MAAM;EAAU,SAAS;CAAG;CACxC,YAAY;EAAE,MAAM;EAAU,SAAS;CAAG;CAC1C,OAAO;EAAE,MAAM;EAAU,SAAS;CAAG;CACrC,KAAK;EAAE,MAAM;EAAU,SAAS;CAAG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"file":"site-config.js","names":[],"sources":["../../src/config/site-config.ts"],"sourcesContent":["/**\n * The site config of a repository: the one home of the inputs of its site build (CI.md, \"The site config\").\n *\n * The file `.github/site.json` of the repository holds them. `reusable-pages.yml` (build and deploy) and\n * `reusable-pages-check.yml` (the check of a pull request) read it with `main.ts` of this folder. Thus the two\n * workflows build the same site, and each value has one home. The rules of `@mark1russell7/conventions` read it too.\n *\n * A repository with no file gives the old inputs of `reusable-pages.yml`, and the resolver takes them. Thus an old\n * caller keeps its site. A repository that has the file and also gives a site input gets an error.\n *\n * In each string value, `{owner}` is the owner of the repository and `{repo}` is its name. This file imports nothing,\n * so the workflow starts it from the template commit with no install.\n */\n\n/** The path of the site config in a repository. */\nexport const SITE_CONFIG_PATH = \".github/site.json\";\n\n/** The type of a key: a string, a boolean or a map of environment variables. */\nexport type SiteConfigKind = \"string\" | \"boolean\" | \"env\";\n\n/** The site config: a value for each key. CI.md tells each key. */\nexport interface SiteConfig {\n /** The command that builds the site. It is the one necessary key, with `out`. */\n readonly build: string;\n /** The folder of the built site. */\n readonly out: string;\n /** The environment variables of the build. `{owner}` and `{repo}` change in each value. */\n readonly env: Readonly<Record<string, string>>;\n /** `true` gives the build the token of the job as `GITHUB_TOKEN`. */\n readonly \"github-token\": boolean;\n /** The Node.js version of the build. */\n readonly \"node-version\": string;\n /** A file with the Node.js version, for example `.nvmrc`. It replaces `node-version`. */\n readonly \"node-version-file\": string;\n /** `true` adds the Releases page and the Status page. */\n readonly \"site-pages\": boolean;\n /** The npm version of site-pages for its pages. Empty uses the template commit. */\n readonly \"site-pages-version\": string;\n /** The roadmap file of the Status page, for example `docs/ROADMAP.md`. */\n readonly roadmap: string;\n /** The base path of the site, for example `/{repo}/`. */\n readonly base: string;\n /** The npm packages of the Releases page, with commas between them. */\n readonly packages: string;\n /** The folder of the changesets of the Status page. */\n readonly changesets: string;\n /** The group of the pages of the site. */\n readonly group: string;\n /** A style file of the site for the pages of site-pages. */\n readonly css: string;\n /** The name of the site in the bar and in the titles. */\n readonly \"site-name\": string;\n /** `true` writes only the data files of the pages, with no HTML. */\n readonly \"data-only\": boolean;\n /** A file of data stamps, for the freshness gate. */\n readonly \"data-stamps\": string;\n /** `true` checks the pages in a browser at each width. */\n readonly \"site-check\": boolean;\n /** The pages of the site check, with commas between them. */\n readonly \"site-check-pages\": string;\n /** The widths of the site check, with commas between them. */\n readonly \"site-check-widths\": string;\n /** A probe script of the site check. */\n readonly \"site-check-probe\": string;\n /** What a text with the shape of an error outside an error view does: `fail` or `report`. Empty reads `sitePages.bareErrors` of package.json. */\n readonly \"site-check-bare-errors\": string;\n /** The Playwright version of the site check. */\n readonly \"site-check-playwright\": string;\n /** The Playwright browsers of the build, with spaces between them. The action `setup-playwright` installs them before the build. */\n readonly \"playwright-browsers\": string;\n /** The command that runs the Playwright CLI of the repository, for the install of `playwright-browsers`. */\n readonly \"playwright-command\": string;\n /** `true` gives each page the bar of the site. */\n readonly \"site-bar\": boolean;\n /** The pages of the bar, with commas between them. */\n readonly \"site-bar-pages\": string;\n /** The npm name of the package of the site, for the npm link of the bar. */\n readonly \"site-bar-npm\": string;\n /** `true` gives each code block the scroll cue. */\n readonly \"scroll-cue\": boolean;\n /** A key of IndexNow. After each deploy that is not scheduled, the URLs go to the engines. */\n readonly \"indexnow-key\": string;\n}\n\n/** A key of the site config. */\nexport type SiteConfigKey = keyof SiteConfig;\n\n/** The type and the default of one key. The defaults are those of the inputs of `reusable-pages.yml`. */\nexport interface SiteConfigKeySpec<T> {\n readonly kind: SiteConfigKind;\n readonly default: T;\n}\n\n/** The keys of the site config, with their types and their defaults. */\nexport const SITE_CONFIG_KEYS: { readonly [K in SiteConfigKey]: SiteConfigKeySpec<SiteConfig[K]> } = {\n build: { kind: \"string\", default: \"\" },\n out: { kind: \"string\", default: \"\" },\n env: { kind: \"env\", default: {} },\n \"github-token\": { kind: \"boolean\", default: false },\n \"node-version\": { kind: \"string\", default: \"26\" },\n \"node-version-file\": { kind: \"string\", default: \"\" },\n \"site-pages\": { kind: \"boolean\", default: true },\n \"site-pages-version\": { kind: \"string\", default: \"\" },\n roadmap: { kind: \"string\", default: \"\" },\n base: { kind: \"string\", default: \"\" },\n packages: { kind: \"string\", default: \"\" },\n changesets: { kind: \"string\", default: \"\" },\n group: { kind: \"string\", default: \"\" },\n css: { kind: \"string\", default: \"\" },\n \"site-name\": { kind: \"string\", default: \"\" },\n \"data-only\": { kind: \"boolean\", default: false },\n \"data-stamps\": { kind: \"string\", default: \"\" },\n \"site-check\": { kind: \"boolean\", default: false },\n \"site-check-pages\": { kind: \"string\", default: \"\" },\n \"site-check-widths\": { kind: \"string\", default: \"\" },\n \"site-check-probe\": { kind: \"string\", default: \"\" },\n \"site-check-bare-errors\": { kind: \"string\", default: \"\" },\n \"site-check-playwright\": { kind: \"string\", default: \"1.64.1\" },\n \"playwright-browsers\": { kind: \"string\", default: \"\" },\n \"playwright-command\": { kind: \"string\", default: \"npx --no-install playwright\" },\n \"site-bar\": { kind: \"boolean\", default: false },\n \"site-bar-pages\": { kind: \"string\", default: \"\" },\n \"site-bar-npm\": { kind: \"string\", default: \"\" },\n \"scroll-cue\": { kind: \"boolean\", default: true },\n \"indexnow-key\": { kind: \"string\", default: \"\" },\n};\n\n/** The input of {@link resolveSiteConfig}. */\nexport interface SiteConfigInput {\n /** The text of .github/site.json, or undefined when the repository has no such file. */\n readonly file: string | undefined;\n /** The path of the file, for the messages. */\n readonly path: string;\n /** The inputs of the workflow (toJSON(inputs)), or undefined when the workflow has no old inputs. */\n readonly inputs: Readonly<Record<string, unknown>> | undefined;\n /** The repository, \"owner/name\". */\n readonly repository: string;\n}\n\n/** The site config and its source, or an error. */\nexport type SiteConfigResult = { readonly config: SiteConfig; readonly source: \"file\" | \"inputs\" } | { readonly error: string };\n\nconst NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/** This function puts the owner and the name of the repository in for {owner} and {repo}. */\nexport function fillRepository(value: string, repository: string): string {\n const [owner = \"\", repo = \"\"] = repository.split(\"/\");\n return value.replaceAll(\"{owner}\", owner).replaceAll(\"{repo}\", repo);\n}\n\n/** This function checks one value against the type of its key, and gives the value or an error. */\nfunction check(key: SiteConfigKey, value: unknown, where: string, repository: string): { value: SiteConfig[SiteConfigKey] } | { error: string } {\n const kind: SiteConfigKind = SITE_CONFIG_KEYS[key].kind;\n if (kind === \"boolean\") {\n return typeof value === \"boolean\" ? { value } : { error: `${where}: \"${key}\" must be true or false.` };\n }\n if (kind === \"string\") {\n return typeof value === \"string\" ? { value: fillRepository(value, repository) } : { error: `${where}: \"${key}\" must be a string.` };\n }\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return { error: `${where}: \"env\" must be an object of strings.` };\n const env: Record<string, string> = {};\n for (const [name, text] of Object.entries(value)) {\n if (!NAME.test(name)) return { error: `${where}: \"${name}\" of \"env\" is not a name of an environment variable.` };\n if (typeof text !== \"string\") return { error: `${where}: the value of \"${name}\" of \"env\" must be a string.` };\n env[name] = fillRepository(text, repository);\n }\n return { value: env };\n}\n\n/**\n * This function gives the keys of the site config that the inputs of a workflow give with a value other than the default.\n * The input `env` of `reusable-pages.yml` is a JSON string, and `\"{}\"` or an empty string is its default.\n */\nexport function inputsGiven(inputs: Readonly<Record<string, unknown>>): SiteConfigKey[] {\n return (Object.keys(SITE_CONFIG_KEYS) as SiteConfigKey[]).filter((key) => {\n const value = inputs[key];\n if (value === undefined) return false;\n if (key === \"env\") return !(value === \"\" || (typeof value === \"string\" && value.replace(/\\s/g, \"\") === \"{}\"));\n return value !== SITE_CONFIG_KEYS[key].default;\n });\n}\n\n/**\n * This function gives the site config of a repository from its file, or from the old inputs when it has no file. The\n * workflow uses only the file. Thus a repository with the file gets an error for a site input that is not its default.\n */\nexport function resolveSiteConfig(input: SiteConfigInput): SiteConfigResult {\n const config = Object.fromEntries(Object.entries(SITE_CONFIG_KEYS).map(([key, spec]) => [key, spec.default])) as Record<SiteConfigKey, unknown>;\n let source: \"file\" | \"inputs\";\n if (input.file !== undefined) {\n const given = input.inputs === undefined ? [] : inputsGiven(input.inputs);\n if (given.length > 0) {\n return { error: `The repository has ${input.path} and the workflow also gives the inputs ${given.join(\", \")}. Give the site values only in ${input.path}.` };\n }\n let data: unknown;\n try {\n data = JSON.parse(input.file);\n } catch (error) {\n return { error: `${input.path} is not JSON: ${(error as Error).message}` };\n }\n if (data === null || typeof data !== \"object\" || Array.isArray(data)) return { error: `${input.path} must be a JSON object.` };\n for (const [key, value] of Object.entries(data)) {\n if (key === \"$schema\" || key === \"$comment\") continue;\n if (!Object.hasOwn(SITE_CONFIG_KEYS, key)) return { error: `${input.path}: \"${key}\" is not a key of the site config. CI.md tells the keys.` };\n const checked = check(key as SiteConfigKey, value, input.path, input.repository);\n if (\"error\" in checked) return checked;\n config[key as SiteConfigKey] = checked.value;\n }\n source = \"file\";\n } else if (input.inputs !== undefined) {\n for (const key of Object.keys(SITE_CONFIG_KEYS) as SiteConfigKey[]) {\n let value = input.inputs[key];\n if (value === undefined) continue;\n // The input env of reusable-pages.yml is a JSON string, and an empty string means no variables.\n if (key === \"env\") {\n if (value === \"\") continue;\n try {\n value = JSON.parse(String(value));\n } catch (error) {\n return { error: `The input env is not JSON: ${(error as Error).message}` };\n }\n }\n const checked = check(key, value, \"the inputs\", input.repository);\n if (\"error\" in checked) return checked;\n config[key] = checked.value;\n }\n source = \"inputs\";\n } else {\n return { error: `The repository has no ${input.path}. The check of the site needs the file (CI.md, \"The site config\").` };\n }\n for (const key of [\"build\", \"out\"] as const) {\n if (config[key] === \"\") {\n const home = source === \"file\" ? input.path : \"the inputs of the workflow\";\n return { error: `${home} gives no \"${key}\". The site config needs \"build\" and \"out\".` };\n }\n }\n return { config: config as SiteConfig, source };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,mBAAmB;;AA+EhC,MAAa,mBAAwF;CACnG,OAAO;EAAE,MAAM;EAAU,SAAS;CAAG;CACrC,KAAK;EAAE,MAAM;EAAU,SAAS;CAAG;CACnC,KAAK;EAAE,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AO;IACjB,IAAI,UAAU,IAAI;IAClB,IAAI;KACF,QAAQ,KAAK,MAAM,OAAO,KAAK,CAAC;IAClC,SAAS,OAAO;KACd,OAAO,EAAE,OAAO,8BAA+B,MAAgB,UAAU;IAC3E;GACF;GACA,MAAM,UAAU,MAAM,KAAK,OAAO,cAAc,MAAM,UAAU;GAChE,IAAI,WAAW,SAAS,OAAO;GAC/B,OAAO,OAAO,QAAQ;EACxB;EACA,SAAS;CACX,OACE,OAAO,EAAE,OAAO,yBAAyB,MAAM,KAAK,oEAAoE;CAE1H,KAAK,MAAM,OAAO,CAAC,SAAS,KAAK,GAC/B,IAAI,OAAO,SAAS,IAElB,OAAO,EAAE,OAAO,GADH,WAAW,SAAS,MAAM,OAAO,6BACtB,aAAa,IAAI,6CAA6C;CAG1F,OAAO;EAAU;EAAsB;CAAO;AAChD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/site-pages",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.6",
|
|
5
5
|
"description": "A release timeline page and a live status page for the site of a GitHub repository: JSON data and standalone HTML, made at deploy time.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"github-pages",
|