@johnhenry/sitefile 0.0.4 → 0.0.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/CHANGELOG.md +71 -0
- package/README.md +47 -10
- package/lib/src/attest.d.ts +3 -2
- package/lib/src/attest.js +3 -2
- package/lib/src/cli/index.d.ts +2 -1
- package/lib/src/cli/index.js +11 -2
- package/lib/src/cli/serve-worker.js +136 -18
- package/lib/src/cli/servers.d.ts +11 -1
- package/lib/src/cli/servers.js +89 -32
- package/lib/src/cli/watch.d.ts +2 -0
- package/lib/src/cli/watch.js +5 -4
- package/lib/src/executor.js +27 -5
- package/lib/src/explain.js +3 -2
- package/lib/src/language/ast.d.ts +15 -3
- package/lib/src/language/parser.js +30 -7
- package/lib/src/language/validate.js +11 -0
- package/lib/src/pattern.d.ts +36 -0
- package/lib/src/pattern.js +389 -0
- package/lib/src/planner.d.ts +8 -0
- package/lib/src/planner.js +4 -2
- package/lib/src/precompress.d.ts +11 -2
- package/lib/src/precompress.js +36 -5
- package/lib/src/render.d.ts +4 -1
- package/lib/src/render.js +11 -7
- package/lib/src/schema.d.ts +3 -0
- package/lib/src/schema.js +39 -6
- package/lib/src/servers.d.ts +25 -0
- package/lib/src/version.d.ts +7 -0
- package/lib/src/version.js +9 -0
- package/package.json +1 -1
package/lib/src/schema.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// title: string # a type name ...
|
|
8
8
|
// tags: { type: list, items: string }
|
|
9
9
|
// status: { enum: [draft, published] }
|
|
10
|
+
// slug: { pattern: '^[a-z0-9-]+$' } # a string matching a regular expression (src/pattern.ts)
|
|
10
11
|
//
|
|
11
12
|
// Types: string, number, boolean, date (YYYY-MM-DD or an RFC 3339 date-time, as FEED reads it) and list
|
|
12
13
|
// (`items` gives the type of its elements). `enum` lists the allowed strings, numbers or booleans (for a list,
|
|
@@ -14,6 +15,7 @@
|
|
|
14
15
|
// `boolean` the strings `true` and `false`, enum entries match their text, and an empty cell counts as missing. docs/LANGUAGE.md has the rules.
|
|
15
16
|
import { SitefileError } from './errors.js';
|
|
16
17
|
import { parseFeedDate } from './site.js';
|
|
18
|
+
import { compilePattern, PatternError, patternMatches } from './pattern.js';
|
|
17
19
|
const TYPES = ['string', 'number', 'boolean', 'date', 'list'];
|
|
18
20
|
const ITEM_TYPES = ['string', 'number', 'boolean', 'date'];
|
|
19
21
|
const NUMERIC = /^-?\d+(\.\d+)?([eE][+-]?\d+)?$/;
|
|
@@ -66,11 +68,11 @@ export function compileSchema(value, label, what, span) {
|
|
|
66
68
|
continue;
|
|
67
69
|
}
|
|
68
70
|
if (!isObject(rule))
|
|
69
|
-
fail(`${at} expected a type name or a mapping with type, items or
|
|
71
|
+
fail(`${at} expected a type name or a mapping with type, items, enum or pattern`);
|
|
70
72
|
const r = rule;
|
|
71
73
|
for (const k of Object.keys(r)) {
|
|
72
|
-
if (k !== 'type' && k !== 'items' && k !== 'enum')
|
|
73
|
-
fail(`${at} unknown key '${k}' (expected type, items or
|
|
74
|
+
if (k !== 'type' && k !== 'items' && k !== 'enum' && k !== 'pattern')
|
|
75
|
+
fail(`${at} unknown key '${k}' (expected type, items, enum or pattern)`);
|
|
74
76
|
}
|
|
75
77
|
const type = r['type'] !== undefined ? typeName(r['type'], TYPES, 'type') : undefined;
|
|
76
78
|
let items;
|
|
@@ -87,7 +89,21 @@ export function compileSchema(value, label, what, span) {
|
|
|
87
89
|
}
|
|
88
90
|
values = e;
|
|
89
91
|
}
|
|
90
|
-
|
|
92
|
+
let pattern;
|
|
93
|
+
if (r['pattern'] !== undefined) {
|
|
94
|
+
const src = r['pattern'];
|
|
95
|
+
if (typeof src !== 'string')
|
|
96
|
+
fail(`${at} pattern must be a string (a regular expression)`);
|
|
97
|
+
try {
|
|
98
|
+
pattern = compilePattern(src);
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
if (!(e instanceof PatternError))
|
|
102
|
+
throw e;
|
|
103
|
+
fail(`${at} pattern '${src}' is invalid ${e.message}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
properties.push({ key, ...(type ? { type } : {}), ...(items ? { items } : {}), ...(values ? { enum: values } : {}), ...(pattern ? { pattern } : {}) });
|
|
91
107
|
}
|
|
92
108
|
}
|
|
93
109
|
return { label, required, properties };
|
|
@@ -120,6 +136,12 @@ function hasType(v, t, csv) {
|
|
|
120
136
|
return Array.isArray(v);
|
|
121
137
|
}
|
|
122
138
|
}
|
|
139
|
+
/** Why a value fails a `pattern`, or undefined when it matches. Only strings can match. */
|
|
140
|
+
function patternMismatch(v, p) {
|
|
141
|
+
if (typeof v !== 'string')
|
|
142
|
+
return `it should be a string matching the pattern '${p.source}'`;
|
|
143
|
+
return patternMatches(p, v) ? undefined : `it should match the pattern '${p.source}'`;
|
|
144
|
+
}
|
|
123
145
|
function inEnum(v, values, csv) {
|
|
124
146
|
return values.some((e) => e === v || (csv && typeof v === 'string' && v === String(e)));
|
|
125
147
|
}
|
|
@@ -158,10 +180,21 @@ export function checkSchema(value, schema, what, csv, span) {
|
|
|
158
180
|
}
|
|
159
181
|
if (rule.enum !== undefined && !inEnum(item, rule.enum, csv))
|
|
160
182
|
fail(`has '${rule.key}' item ${j + 1} ${describe(item)}; it should be one of ${enumText(rule.enum)}`);
|
|
183
|
+
if (rule.pattern !== undefined) {
|
|
184
|
+
const m = patternMismatch(item, rule.pattern);
|
|
185
|
+
if (m)
|
|
186
|
+
fail(`has '${rule.key}' item ${j + 1} ${describe(item)}; ${m}`);
|
|
187
|
+
}
|
|
161
188
|
});
|
|
162
189
|
}
|
|
163
|
-
else
|
|
164
|
-
|
|
190
|
+
else {
|
|
191
|
+
if (rule.enum !== undefined && !inEnum(v, rule.enum, csv))
|
|
192
|
+
fail(`has '${rule.key}' ${describe(v)}; it should be one of ${enumText(rule.enum)}`);
|
|
193
|
+
if (rule.pattern !== undefined) {
|
|
194
|
+
const m = patternMismatch(v, rule.pattern);
|
|
195
|
+
if (m)
|
|
196
|
+
fail(`has '${rule.key}' ${describe(v)}; ${m}`);
|
|
197
|
+
}
|
|
165
198
|
}
|
|
166
199
|
}
|
|
167
200
|
});
|
package/lib/src/servers.d.ts
CHANGED
|
@@ -15,6 +15,21 @@ import type { AuthEntry } from './serve-auth.js';
|
|
|
15
15
|
* file alone: a server is `running` only when its pid is alive AND the port answers with
|
|
16
16
|
* this server's `x-sitefile-server` header.
|
|
17
17
|
*/
|
|
18
|
+
/** The build inputs of a `serve -d --watch` server on a build context (johnhenry/sitefile#306). */
|
|
19
|
+
export interface WatchBuild {
|
|
20
|
+
/** `-f`, absolute (absent: `<context>/Sitefile`). */
|
|
21
|
+
readonly sitefile?: string;
|
|
22
|
+
/** `--target`. */
|
|
23
|
+
readonly target?: string;
|
|
24
|
+
/** `--build-arg` flags, `NAME=value` (a bare `NAME` is resolved from the environment when the server is created). */
|
|
25
|
+
readonly buildArgs?: readonly string[];
|
|
26
|
+
/** `--build-arg-file` files, absolute (re-read on every build). */
|
|
27
|
+
readonly buildArgFiles?: readonly string[];
|
|
28
|
+
/** `--no-cache`, `--no-lockfile`, `--no-rewrite-base` (absent: false). */
|
|
29
|
+
readonly noCache?: boolean;
|
|
30
|
+
readonly noLockfile?: boolean;
|
|
31
|
+
readonly noRewriteBase?: boolean;
|
|
32
|
+
}
|
|
18
33
|
export interface ServerState {
|
|
19
34
|
readonly id: string;
|
|
20
35
|
readonly name: string;
|
|
@@ -93,6 +108,16 @@ export interface ServerState {
|
|
|
93
108
|
readonly pollMs?: number;
|
|
94
109
|
/** `--sync` with `-d --watch`: pages report where they are and follow each other (`scroll`: their scrolling too) (absent: off). */
|
|
95
110
|
readonly sync?: 'nav' | 'scroll';
|
|
111
|
+
/** `--reload` (with or without `--watch`): live-reload script and stream in this mode, so open pages reload after a restart (absent: only with `watch`, in morph mode). */
|
|
112
|
+
readonly reload?: 'full' | 'morph';
|
|
113
|
+
/** `-d --watch` on a build context (a Sitefile, or any build flag): build it in memory and rebuild on change (absent: a plain directory). */
|
|
114
|
+
readonly build?: WatchBuild;
|
|
115
|
+
/** `--no-css-inject`, `--console`, `--no-overlay`, `--navigate-to-changed`, `--keep-service-workers` with `-d --watch` (absent: false). */
|
|
116
|
+
readonly noCssInject?: boolean;
|
|
117
|
+
readonly console?: boolean;
|
|
118
|
+
readonly noOverlay?: boolean;
|
|
119
|
+
readonly navigateToChanged?: boolean;
|
|
120
|
+
readonly keepServiceWorkers?: boolean;
|
|
96
121
|
/** The requested bind address (port 0 = pick a free port). */
|
|
97
122
|
readonly bind: {
|
|
98
123
|
readonly host: string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Sitefile version: `sitefile --version`, the help text and the builder version in build
|
|
3
|
+
* attestations. package.json is the source of truth (read at load time; this file is compiled to
|
|
4
|
+
* lib/src/version.js, two levels below it). The Rust port takes it from rust/Cargo.toml, which a
|
|
5
|
+
* test in each implementation keeps equal to package.json (johnhenry/sitefile#146).
|
|
6
|
+
*/
|
|
7
|
+
export declare const SITEFILE_VERSION: string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
/**
|
|
3
|
+
* The Sitefile version: `sitefile --version`, the help text and the builder version in build
|
|
4
|
+
* attestations. package.json is the source of truth (read at load time; this file is compiled to
|
|
5
|
+
* lib/src/version.js, two levels below it). The Rust port takes it from rust/Cargo.toml, which a
|
|
6
|
+
* test in each implementation keeps equal to package.json (johnhenry/sitefile#146).
|
|
7
|
+
*/
|
|
8
|
+
export const SITEFILE_VERSION = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).version;
|
|
9
|
+
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnhenry/sitefile",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Docker-inspired static artifact builder: compose immutable file trees from local and remote sources, render templates, and export a deployable site. No container runtime, no shell, no runtime dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"static-site",
|