@transclude/core 0.8.2 → 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/LICENSE +1 -1
- package/bin/build.js +34 -0
- package/package.json +1 -1
- package/skills/transclude/references/server.md +5 -0
package/LICENSE
CHANGED
package/bin/build.js
CHANGED
|
@@ -123,6 +123,29 @@ fs.writeFileSync(entry, `// @ts-nocheck\n${fs.readFileSync(entry, 'utf8')}`);
|
|
|
123
123
|
|
|
124
124
|
const { pages } = await import(pathToFileURL(entry).href);
|
|
125
125
|
|
|
126
|
+
// ---- drafts ---------------------------------------------------------------
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* `export const draft = true` keeps a page out of the build.
|
|
130
|
+
*
|
|
131
|
+
* The dev server reads the directory, so a draft is a page there and you can
|
|
132
|
+
* open it, reload it and read it on a phone. This is the only place that knows
|
|
133
|
+
* the difference, and it takes the route out of the one list every step below
|
|
134
|
+
* reads: nothing is prerendered for it, no pattern reaches `routes.json`, and
|
|
135
|
+
* the sitemap never hears of it. In production the URL is a 404.
|
|
136
|
+
*
|
|
137
|
+
* Assigned back onto the manifest rather than carried alongside it. Three steps
|
|
138
|
+
* below read `manifest.routes`, and a fourth added later would publish drafts
|
|
139
|
+
* without anyone noticing. One list is the only version of this that stays true.
|
|
140
|
+
*
|
|
141
|
+
* The build says what it skipped, at the end, next to everything else it wrote.
|
|
142
|
+
* A page that is missing from production and silent about it is an afternoon.
|
|
143
|
+
*/
|
|
144
|
+
const isDraft = (route) => pages[route.id]?.draft === true;
|
|
145
|
+
const drafts = manifest.routes.filter(isDraft);
|
|
146
|
+
|
|
147
|
+
manifest.routes = manifest.routes.filter((route) => !isDraft(route));
|
|
148
|
+
|
|
126
149
|
/**
|
|
127
150
|
* A static route has one URL. A dynamic route has as many as its `paths` export
|
|
128
151
|
* names, and none at all if it does not export one, in which case it stays a
|
|
@@ -517,6 +540,17 @@ console.log(`\n${summary.join(', ')}`);
|
|
|
517
540
|
for (const url of prerendered) console.log(` ${url}`);
|
|
518
541
|
for (const route of dynamic) console.log(` ${route.pattern} (server-rendered)`);
|
|
519
542
|
|
|
543
|
+
// Last, and never silent. A draft is the one thing here that is absent from
|
|
544
|
+
// production on purpose, and the only way to tell a page that was skipped from
|
|
545
|
+
// a page that broke is to be told.
|
|
546
|
+
if (drafts.length) {
|
|
547
|
+
console.log(
|
|
548
|
+
`\n${drafts.length} draft${drafts.length === 1 ? '' : 's'} skipped, ` +
|
|
549
|
+
`and served by \`npm run dev\`:`,
|
|
550
|
+
);
|
|
551
|
+
for (const route of drafts) console.log(` ${route.pattern}`);
|
|
552
|
+
}
|
|
553
|
+
|
|
520
554
|
if (compressed.files) {
|
|
521
555
|
const kb = (n) => `${(n / 1024).toFixed(1)} KB`;
|
|
522
556
|
const pct = (n) => `${Math.round((1 - n / compressed.raw) * 100)}%`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transclude/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "An HTML-first server framework. A page is an .html file, the directory tree is the route table, and any fragment of a page is a URL of its own. Runs on Node, Bun, Deno and workerd, and ships no client JavaScript by default.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"html",
|
|
@@ -141,6 +141,11 @@ this to a page that has to run for each request:
|
|
|
141
141
|
export const prerender = false;
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
+
**`export const draft = true` keeps a page out of the build.** `npm run dev`
|
|
145
|
+
serves it, because the dev server reads the directory. The build writes no file,
|
|
146
|
+
puts no route in the manifest and no line in the sitemap, and prints what it
|
|
147
|
+
skipped. Deployed, the URL is a 404. Publishing is deleting the line.
|
|
148
|
+
|
|
144
149
|
`prerender` is read off the page, never off its layouts. A layout that reads a
|
|
145
150
|
cookie makes every page under it request-dependent, and nothing says so.
|
|
146
151
|
|