@rulebookguard/site 0.0.0-stage → 0.4.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Juan Carlos Jimenez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
- # Temporary Holding Version
1
+ # @rulebookguard/site
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Builds the static site of a [rulebookguard](https://github.com/JuanCJR/rulebookguard#readme) rulebook with Astro Starlight. Install it next to `rulebookguard` to use the `site:generate` and `site:run` commands:
4
+
5
+ ```sh
6
+ npm install --save-dev rulebookguard @rulebookguard/site
7
+ ```
8
+
9
+ It is kept apart so that `rulebookguard lint` does not download Astro. It requires Node.js 22.23.4 or later.
package/index.d.mts ADDED
@@ -0,0 +1,13 @@
1
+ export declare class SiteBuildError extends Error {
2
+ readonly detail: string;
3
+ constructor(detail: string);
4
+ }
5
+
6
+ /** Writes `files` as an Astro project, builds it and replaces `out` with the build. */
7
+ export declare function buildSite(files: ReadonlyMap<string, string>, out: string): Promise<void>;
8
+
9
+ /** The directory where generated projects are built, inside the node_modules that holds Astro. */
10
+ export declare function siteWorkRoot(): string;
11
+
12
+ /** The first lines of Astro's error output, without its stack trace. */
13
+ export declare function astroFailureDetail(output: string): string;
package/index.mjs ADDED
@@ -0,0 +1,73 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { randomUUID } from 'node:crypto';
3
+ import { readFileSync } from 'node:fs';
4
+ import { cp, mkdir, rm, writeFile } from 'node:fs/promises';
5
+ import { basename, dirname, join } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ import { promisify } from 'node:util';
8
+
9
+ const execFileAsync = promisify(execFile);
10
+
11
+ export class SiteBuildError extends Error {
12
+ constructor(detail) {
13
+ super(`The site build failed:\n${detail}`);
14
+ this.name = 'SiteBuildError';
15
+ this.detail = detail;
16
+ }
17
+ }
18
+
19
+ /** Writes `files` as an Astro project, builds it and replaces `out` with the build. */
20
+ export async function buildSite(files, out) {
21
+ const work = join(siteWorkRoot(), randomUUID());
22
+ try {
23
+ for (const [path, content] of files) {
24
+ await mkdir(dirname(join(work, path)), { recursive: true });
25
+ await writeFile(join(work, path), content);
26
+ }
27
+ await buildWithAstro(work);
28
+ await rm(out, { recursive: true, force: true });
29
+ await cp(join(work, 'dist'), out, { recursive: true });
30
+ } finally {
31
+ await rm(work, { recursive: true, force: true });
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Starlight injects its routes as package specifiers that Astro resolves from the project root, so the generated
37
+ * project must live inside the node_modules directory that holds this package's own dependencies.
38
+ */
39
+ export function siteWorkRoot() {
40
+ const root = dirname(fileURLToPath(import.meta.url));
41
+ let parent = dirname(root);
42
+ if (basename(parent).startsWith('@')) {
43
+ parent = dirname(parent);
44
+ }
45
+ const modules = basename(parent) === 'node_modules' ? parent : join(root, 'node_modules');
46
+ return join(modules, '.rulebookguard-site');
47
+ }
48
+
49
+ // Astro writes temporary prerender files under the process cwd, so it runs in its own process from the project.
50
+ async function buildWithAstro(work) {
51
+ const astro = join(dirname(siteWorkRoot()), 'astro');
52
+ const { bin } = JSON.parse(readFileSync(join(astro, 'package.json'), 'utf8'));
53
+ try {
54
+ await execFileAsync(process.execPath, [join(astro, bin.astro), 'build', '--silent'], {
55
+ cwd: work,
56
+ env: { ...process.env, ASTRO_TELEMETRY_DISABLED: '1' },
57
+ maxBuffer: 64 * 1024 * 1024,
58
+ });
59
+ } catch (error) {
60
+ const { stderr, stdout } = error;
61
+ throw new SiteBuildError(astroFailureDetail(`${stderr ?? ''}${stdout ?? ''}`));
62
+ }
63
+ }
64
+
65
+ /** The first lines of Astro's error output, without its stack trace. */
66
+ export function astroFailureDetail(output) {
67
+ return output
68
+ .split('\n')
69
+ .filter((line) => !/^\s*at /.test(line) && !/^\s*Stack trace:/.test(line))
70
+ .filter((line) => line.trim() !== '')
71
+ .slice(0, 12)
72
+ .join('\n');
73
+ }
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
2
  "name": "@rulebookguard/site",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.4.0",
4
+ "description": "Astro Starlight builder for the rulebookguard site commands.",
5
+ "homepage": "https://github.com/JuanCJR/rulebookguard#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/JuanCJR/rulebookguard/issues"
8
+ },
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/JuanCJR/rulebookguard.git",
13
+ "directory": "packages/site"
14
+ },
15
+ "files": [
16
+ "index.mjs",
17
+ "index.d.mts"
18
+ ],
19
+ "type": "module",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./index.d.mts",
23
+ "default": "./index.mjs"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "dependencies": {
28
+ "@astrojs/markdown-remark": "^7.3.2",
29
+ "@astrojs/starlight": "^0.42.6",
30
+ "astro": "^7.3.8"
31
+ },
32
+ "engines": {
33
+ "node": ">=22.23.4"
34
+ }
35
+ }