create-website-build-kit 0.1.6 → 0.1.7
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": "create-website-build-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Scaffold a production marketing site \u2014 Astro on Cloudflare Workers, with the gates, the migration playbook and the accessibility work already wired.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
package/template/package.json
CHANGED
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"redirects": "node scripts/redirects.mjs",
|
|
30
30
|
"handover": "node scripts/md-to-pdf.mjs docs/handover.md docs/handover.pdf",
|
|
31
31
|
"build": "astro build",
|
|
32
|
-
"build:staging": "
|
|
33
|
-
"build:production": "node scripts/
|
|
32
|
+
"build:staging": "node scripts/build.mjs staging",
|
|
33
|
+
"build:production": "node scripts/build.mjs production",
|
|
34
34
|
"preview": "wrangler dev",
|
|
35
35
|
"deploy:staging": "npm run build:staging && wrangler deploy && node scripts/check-secrets.mjs",
|
|
36
36
|
"deploy:production": "npm run build:production && wrangler deploy && node scripts/check-secrets.mjs",
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run a build for one environment.
|
|
3
|
+
*
|
|
4
|
+
* node scripts/build.mjs staging
|
|
5
|
+
* node scripts/build.mjs production
|
|
6
|
+
*
|
|
7
|
+
* `npm run build:staging` and `npm run build:production` are one-line aliases
|
|
8
|
+
* for these.
|
|
9
|
+
*
|
|
10
|
+
* ── WHY A SCRIPT AND NOT INLINE ENV IN package.json ────────────────────────
|
|
11
|
+
* ⚠ `PUBLIC_SITE_ENV=staging astro build` IS POSIX SHELL SYNTAX, AND npm ON
|
|
12
|
+
* WINDOWS RUNS SCRIPTS THROUGH cmd.exe. There it is not an assignment, it is
|
|
13
|
+
* a command name, and the build dies immediately with
|
|
14
|
+
*
|
|
15
|
+
* 'PUBLIC_SITE_ENV' is not recognized as an internal or external command
|
|
16
|
+
*
|
|
17
|
+
* So the two most important commands in the kit did not work at all on a
|
|
18
|
+
* platform the kit says it supports. Nothing caught it because every CI job
|
|
19
|
+
* ran on ubuntu.
|
|
20
|
+
*
|
|
21
|
+
* ── AND WHY IT IS SAFER EVEN WHERE THE SHELL SYNTAX WORKS ──────────────────
|
|
22
|
+
* The production line repeated `PUBLIC_SITE_ENV=production` four times, once
|
|
23
|
+
* per command. Miss one and that step runs as `development` while the others
|
|
24
|
+
* do not: `astro check` types a different environment than the one that gets
|
|
25
|
+
* built, or `check-env` validates an environment nobody deployed.
|
|
26
|
+
*
|
|
27
|
+
* A mixed-environment build is precisely what `check-env.mjs` exists to catch,
|
|
28
|
+
* and it is the sort of thing that survives review because every line looks
|
|
29
|
+
* right on its own. Setting it once removes the class.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { spawnSync } from 'node:child_process';
|
|
33
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
34
|
+
|
|
35
|
+
const RESET = '\x1b[0m';
|
|
36
|
+
const RED = '\x1b[31m';
|
|
37
|
+
const DIM = '\x1b[2m';
|
|
38
|
+
|
|
39
|
+
const env = process.argv[2];
|
|
40
|
+
|
|
41
|
+
if (env !== 'staging' && env !== 'production') {
|
|
42
|
+
console.error(
|
|
43
|
+
`\n${RED}✗ usage: node scripts/build.mjs <staging|production>${RESET}\n\n` +
|
|
44
|
+
' The environment is not optional. A build that does not declare one\n' +
|
|
45
|
+
' emits localhost canonical URLs — cleanly, and wrong.\n',
|
|
46
|
+
);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
* The site URL per environment. Read from package.json rather than restated
|
|
52
|
+
* here, so there is one place a project sets its hostnames.
|
|
53
|
+
*
|
|
54
|
+
* ⚠ Kept OUT of src/data/site.ts on purpose: astro.config.mjs needs the value
|
|
55
|
+
* before any TypeScript is loaded, and site.ts imports `import.meta.env`.
|
|
56
|
+
*/
|
|
57
|
+
const SITE_URLS = {
|
|
58
|
+
staging: 'https://new.example.com',
|
|
59
|
+
production: 'https://example.com',
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Run one step with the environment already set, and stop the build if it
|
|
64
|
+
* fails. `shell: true` on Windows because `npx`-style shims are .cmd files
|
|
65
|
+
* that execFile cannot resolve — the same reason the a11y scripts need it.
|
|
66
|
+
*/
|
|
67
|
+
function step(command, args) {
|
|
68
|
+
const run = spawnSync(command, args, {
|
|
69
|
+
stdio: 'inherit',
|
|
70
|
+
env: { ...process.env, PUBLIC_SITE_ENV: env, PUBLIC_SITE_URL: SITE_URLS[env] },
|
|
71
|
+
shell: process.platform === 'win32',
|
|
72
|
+
});
|
|
73
|
+
if (run.status !== 0) {
|
|
74
|
+
console.error(`\n${RED}✗ build failed at:${RESET} ${command} ${args.join(' ')}\n`);
|
|
75
|
+
process.exit(run.status ?? 1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* astro is a local binary; go through the package's own bin rather than a
|
|
80
|
+
global `astro`, which may not exist and would be the wrong version if it did. */
|
|
81
|
+
const astro = ['node_modules/astro/astro.js'];
|
|
82
|
+
const hasLocalAstro = existsSync('node_modules/astro/astro.js');
|
|
83
|
+
|
|
84
|
+
const run = (args) =>
|
|
85
|
+
hasLocalAstro
|
|
86
|
+
? step(process.execPath, [...astro, ...args])
|
|
87
|
+
: step('npx', ['--no-install', 'astro', ...args]);
|
|
88
|
+
|
|
89
|
+
console.log(`${DIM}building ${env} → ${SITE_URLS[env]}${RESET}\n`);
|
|
90
|
+
|
|
91
|
+
if (env === 'production') {
|
|
92
|
+
/* Refuse a production build of a template that has not been designed yet.
|
|
93
|
+
Before anything else, because it is the cheapest check and the most
|
|
94
|
+
embarrassing thing to deploy. */
|
|
95
|
+
step(process.execPath, ['scripts/tells.mjs', '--undecided-only']);
|
|
96
|
+
run(['check']);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
run(['build']);
|
|
100
|
+
|
|
101
|
+
if (env === 'staging') {
|
|
102
|
+
step(process.execPath, ['scripts/staging-headers.mjs']);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
step(process.execPath, ['scripts/check-env.mjs']);
|
|
106
|
+
|
|
107
|
+
if (env === 'production') {
|
|
108
|
+
step(process.execPath, ['scripts/check-sitemap.mjs']);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* A sanity line, so the log says which environment actually ran rather than
|
|
112
|
+
which one was asked for. They are the same now; they were not always. */
|
|
113
|
+
const pkg = existsSync('package.json') ? JSON.parse(readFileSync('package.json', 'utf8')) : {};
|
|
114
|
+
console.log(`\n${DIM}${pkg.name ?? 'site'} built as ${env}${RESET}`);
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
31
|
-
import { join, relative } from 'node:path';
|
|
31
|
+
import { join, relative, sep } from 'node:path';
|
|
32
32
|
|
|
33
33
|
const RESET = '[0m';
|
|
34
34
|
const RED = '[31m';
|
|
@@ -78,7 +78,13 @@ const ROBOTS_META = /<meta[^>]+name=["']robots["'][^>]+content=["'][^"']*\bnoind
|
|
|
78
78
|
const noindexed = walk(root)
|
|
79
79
|
.filter((f) => f.endsWith('.html'))
|
|
80
80
|
.filter((f) => ROBOTS_META.test(readFileSync(f, 'utf8')))
|
|
81
|
-
|
|
81
|
+
/* ⚠ SEPARATORS NORMALISED — `relative()` RETURNS BACKSLASHES ON WINDOWS.
|
|
82
|
+
A URL path is always `/`. Without this the map produced `/about\\` for
|
|
83
|
+
`about\\index.html`, which matched nothing: check-sitemap's contradiction
|
|
84
|
+
check silently passed a site that listed a noindexed URL in its sitemap, and
|
|
85
|
+
Search Console reports that as an error against the whole submission. */
|
|
86
|
+
.map((f) => '/' + relative(root, f).split(sep).join('/')
|
|
87
|
+
.replace(/index\.html$/, '').replace(/\.html$/, '/'))
|
|
82
88
|
.map((p) => (p.endsWith('/') ? p : `${p}/`));
|
|
83
89
|
|
|
84
90
|
const contradictions = noindexed.filter((p) => listed.has(p));
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
14
|
-
import { join, relative } from 'node:path';
|
|
14
|
+
import { join, relative, sep } from 'node:path';
|
|
15
15
|
|
|
16
16
|
/** Routes this build emitted, as absolute paths. 404 is excluded — it is not a route. */
|
|
17
17
|
export function routesFromDist() {
|
|
@@ -26,7 +26,13 @@ export function routesFromDist() {
|
|
|
26
26
|
|
|
27
27
|
return walk(root)
|
|
28
28
|
.filter((f) => f.endsWith('.html') && !f.endsWith('404.html'))
|
|
29
|
-
|
|
29
|
+
/* ⚠ SEPARATORS NORMALISED — `relative()` RETURNS BACKSLASHES ON WINDOWS.
|
|
30
|
+
A URL path is always `/`. Without this the map produced `/about\\` for
|
|
31
|
+
`about\\index.html`, which matched nothing: check-sitemap's contradiction
|
|
32
|
+
check silently passed a site that listed a noindexed URL in its sitemap, and
|
|
33
|
+
Search Console reports that as an error against the whole submission. */
|
|
34
|
+
.map((f) => '/' + relative(root, f).split(sep).join('/')
|
|
35
|
+
.replace(/index\.html$/, '').replace(/\.html$/, '/'))
|
|
30
36
|
.map((p) => (p.endsWith('/') ? p : `${p}/`))
|
|
31
37
|
.sort();
|
|
32
38
|
}
|