@goodbones/browser 0.1.0-beta.1
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 +21 -0
- package/build/dts/index.d.ts +12 -0
- package/build/dts/index.d.ts.map +1 -0
- package/build/dts/main.d.ts +3 -0
- package/build/dts/main.d.ts.map +1 -0
- package/build/dts/model/atlas.d.ts +157 -0
- package/build/dts/model/atlas.d.ts.map +1 -0
- package/build/dts/model/campaigns.d.ts +141 -0
- package/build/dts/model/campaigns.d.ts.map +1 -0
- package/build/dts/server/collect.d.ts +16 -0
- package/build/dts/server/collect.d.ts.map +1 -0
- package/build/dts/server/compose.d.ts +13 -0
- package/build/dts/server/compose.d.ts.map +1 -0
- package/build/dts/server/export.d.ts +3 -0
- package/build/dts/server/export.d.ts.map +1 -0
- package/build/dts/server/handler.d.ts +6 -0
- package/build/dts/server/handler.d.ts.map +1 -0
- package/build/dts/server/serve.d.ts +15 -0
- package/build/dts/server/serve.d.ts.map +1 -0
- package/build/dts/server/site.d.ts +2 -0
- package/build/dts/server/site.d.ts.map +1 -0
- package/build/dts/server/source.d.ts +19 -0
- package/build/dts/server/source.d.ts.map +1 -0
- package/build/dts/server/vite-plugin.d.ts +8 -0
- package/build/dts/server/vite-plugin.d.ts.map +1 -0
- package/build/dts/server/watch.d.ts +10 -0
- package/build/dts/server/watch.d.ts.map +1 -0
- package/build/esm/index.js +14 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/main.js +134 -0
- package/build/esm/main.js.map +1 -0
- package/build/esm/model/atlas.js +431 -0
- package/build/esm/model/atlas.js.map +1 -0
- package/build/esm/model/campaigns.js +181 -0
- package/build/esm/model/campaigns.js.map +1 -0
- package/build/esm/server/collect.js +83 -0
- package/build/esm/server/collect.js.map +1 -0
- package/build/esm/server/compose.js +50 -0
- package/build/esm/server/compose.js.map +1 -0
- package/build/esm/server/export.js +19 -0
- package/build/esm/server/export.js.map +1 -0
- package/build/esm/server/handler.js +67 -0
- package/build/esm/server/handler.js.map +1 -0
- package/build/esm/server/serve.js +80 -0
- package/build/esm/server/serve.js.map +1 -0
- package/build/esm/server/site.js +6 -0
- package/build/esm/server/site.js.map +1 -0
- package/build/esm/server/source.js +67 -0
- package/build/esm/server/source.js.map +1 -0
- package/build/esm/server/vite-plugin.js +21 -0
- package/build/esm/server/vite-plugin.js.map +1 -0
- package/build/esm/server/watch.js +56 -0
- package/build/esm/server/watch.js.map +1 -0
- package/build/site/_astro/Browser.yxldcnQ3.js +3 -0
- package/build/site/_astro/client.Buyw3Q1S.js +9 -0
- package/build/site/_astro/index.DQrWs1cb.css +1 -0
- package/build/site/_astro/react.DJY1zw8Z.js +1 -0
- package/build/site/favicon.svg +1 -0
- package/build/site/index.html +8 -0
- package/package.json +78 -0
- package/src/app/components/Browser.tsx +153 -0
- package/src/app/components/architecture/ArchitectureBrowser.tsx +240 -0
- package/src/app/components/architecture/Detail.tsx +655 -0
- package/src/app/components/architecture/ManifestPane.tsx +178 -0
- package/src/app/components/architecture/Tree.tsx +205 -0
- package/src/app/components/architecture/rows.ts +181 -0
- package/src/app/components/architecture/selection.ts +6 -0
- package/src/app/components/campaigns/CampaignBrowser.tsx +146 -0
- package/src/app/components/campaigns/Detail.tsx +653 -0
- package/src/app/components/campaigns/Ladder.tsx +326 -0
- package/src/app/components/campaigns/pick.ts +7 -0
- package/src/app/components/lib/data.ts +132 -0
- package/src/app/pages/index.astro +34 -0
- package/src/app/public/favicon.svg +1 -0
- package/src/app/styles/theme.css +993 -0
- package/src/index.ts +37 -0
- package/src/main.ts +155 -0
- package/src/model/atlas.ts +751 -0
- package/src/model/campaigns.ts +376 -0
- package/src/server/collect.ts +132 -0
- package/src/server/compose.ts +79 -0
- package/src/server/export.ts +24 -0
- package/src/server/handler.ts +77 -0
- package/src/server/serve.ts +100 -0
- package/src/server/site.ts +6 -0
- package/src/server/source.ts +89 -0
- package/src/server/vite-plugin.ts +32 -0
- package/src/server/watch.ts +65 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// The browsers' data, and the server pieces a host composes them with. The
|
|
2
|
+
// page itself is under `build/site`, served by the `goodbones-browser` bin.
|
|
3
|
+
export {
|
|
4
|
+
type Atlas,
|
|
5
|
+
type AtlasAllowance,
|
|
6
|
+
type AtlasEdge,
|
|
7
|
+
type AtlasExternal,
|
|
8
|
+
type AtlasFile,
|
|
9
|
+
type AtlasFolder,
|
|
10
|
+
type AtlasInput,
|
|
11
|
+
type AtlasNode,
|
|
12
|
+
type AtlasPosition,
|
|
13
|
+
type AtlasRule,
|
|
14
|
+
type AtlasViolation,
|
|
15
|
+
buildAtlas,
|
|
16
|
+
type EdgeStatus,
|
|
17
|
+
} from "./model/atlas.js";
|
|
18
|
+
export {
|
|
19
|
+
type CampaignCard,
|
|
20
|
+
type CampaignView,
|
|
21
|
+
type CampaignViewInput,
|
|
22
|
+
campaignViewOf,
|
|
23
|
+
type HitCard,
|
|
24
|
+
type ObjectiveCard,
|
|
25
|
+
type ObjectiveSectorCard,
|
|
26
|
+
type PhaseCard,
|
|
27
|
+
type SectorCard,
|
|
28
|
+
} from "./model/campaigns.js";
|
|
29
|
+
export { collect, type Collected, type CollectOptions, collectWith } from "./server/collect.js";
|
|
30
|
+
export { type LoadedManifest, loadPolicyFromFile } from "./server/compose.js";
|
|
31
|
+
export { exportSite } from "./server/export.js";
|
|
32
|
+
export { type Handler, makeHandler, PREFIX } from "./server/handler.js";
|
|
33
|
+
export { serve, type Served, type ServeOptions } from "./server/serve.js";
|
|
34
|
+
export { SITE_DIR } from "./server/site.js";
|
|
35
|
+
export { type Change, makeSource, type Source, type SourceOptions } from "./server/source.js";
|
|
36
|
+
export { type BrowserPluginOptions, goodbonesBrowser } from "./server/vite-plugin.js";
|
|
37
|
+
export { isRelevant, type WatchOptions, watchRepository } from "./server/watch.js";
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
|
|
6
|
+
import { collect } from "./server/collect.js";
|
|
7
|
+
import { exportSite } from "./server/export.js";
|
|
8
|
+
import { makeHandler } from "./server/handler.js";
|
|
9
|
+
import { serve } from "./server/serve.js";
|
|
10
|
+
import { SITE_DIR } from "./server/site.js";
|
|
11
|
+
import { makeSource } from "./server/source.js";
|
|
12
|
+
|
|
13
|
+
// goodbones-browser [serve] [<root>...] [--port N] [--host H] [--open] [--no-nudge]
|
|
14
|
+
// goodbones-browser build --out <dir> [<root>...] [--no-nudge]
|
|
15
|
+
//
|
|
16
|
+
// Run from the repository's root, as `architecture` is. `serve` (the
|
|
17
|
+
// default) opens the Architecture Browser and the Campaign Browser over the
|
|
18
|
+
// repository and redraws them as it changes; `build` writes the same page
|
|
19
|
+
// with the models as of now, for a static host.
|
|
20
|
+
|
|
21
|
+
const USAGE = [
|
|
22
|
+
"goodbones-browser [serve] [<root>...] [--port <n>] [--host <h>] [--open] [--no-nudge]",
|
|
23
|
+
"goodbones-browser build --out <dir> [<root>...] [--no-nudge]",
|
|
24
|
+
"",
|
|
25
|
+
"Roots default to `packages`, as the architecture CLI's do. ARCHITECTURE_CONFIG names",
|
|
26
|
+
"the manifest when it is not architecture.yaml at the root.",
|
|
27
|
+
].join("\n");
|
|
28
|
+
|
|
29
|
+
type Args = {
|
|
30
|
+
readonly command: "serve" | "build";
|
|
31
|
+
readonly roots: ReadonlyArray<string>;
|
|
32
|
+
readonly port: number;
|
|
33
|
+
readonly host: string;
|
|
34
|
+
readonly open: boolean;
|
|
35
|
+
readonly out: string | null;
|
|
36
|
+
readonly nudge: boolean;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const parse = (argv: ReadonlyArray<string>): Args => {
|
|
40
|
+
let command: Args["command"] = "serve";
|
|
41
|
+
const roots: Array<string> = [];
|
|
42
|
+
let port = 4321;
|
|
43
|
+
let host = "127.0.0.1";
|
|
44
|
+
let open = false;
|
|
45
|
+
let out: string | null = null;
|
|
46
|
+
let nudge = true;
|
|
47
|
+
const rest = [...argv];
|
|
48
|
+
if (rest[0] === "serve" || rest[0] === "build") command = rest.shift() as Args["command"];
|
|
49
|
+
while (rest.length > 0) {
|
|
50
|
+
const argument = rest.shift() as string;
|
|
51
|
+
switch (argument) {
|
|
52
|
+
case "--port": {
|
|
53
|
+
const value = Number(rest.shift());
|
|
54
|
+
if (!Number.isInteger(value) || value < 0) throw new Error("--port needs a number");
|
|
55
|
+
port = value;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case "--host":
|
|
59
|
+
host = rest.shift() ?? host;
|
|
60
|
+
break;
|
|
61
|
+
case "--open":
|
|
62
|
+
open = true;
|
|
63
|
+
break;
|
|
64
|
+
case "--out":
|
|
65
|
+
out = rest.shift() ?? null;
|
|
66
|
+
break;
|
|
67
|
+
case "--no-nudge":
|
|
68
|
+
nudge = false;
|
|
69
|
+
break;
|
|
70
|
+
case "--help":
|
|
71
|
+
case "-h":
|
|
72
|
+
process.stdout.write(`${USAGE}\n`);
|
|
73
|
+
process.exit(0);
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
if (argument.startsWith("--")) throw new Error(`unknown flag ${argument}\n\n${USAGE}`);
|
|
77
|
+
roots.push(argument);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (command === "build" && out === null) throw new Error(`build needs --out <dir>\n\n${USAGE}`);
|
|
81
|
+
return { command, roots: roots.length > 0 ? roots : ["packages"], port, host, open, out, nudge };
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Relative when it reads well, absolute when it would climb out of the repo.
|
|
85
|
+
const describePath = (repoRoot: string, target: string): string => {
|
|
86
|
+
const relative = path.relative(repoRoot, target);
|
|
87
|
+
if (relative === "") return ".";
|
|
88
|
+
return relative.startsWith("..") ? target : relative;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const openBrowser = (url: string): void => {
|
|
92
|
+
const [bin, args] =
|
|
93
|
+
process.platform === "darwin"
|
|
94
|
+
? ["open", [url]]
|
|
95
|
+
: process.platform === "win32"
|
|
96
|
+
? ["cmd", ["/c", "start", "", url]]
|
|
97
|
+
: ["xdg-open", [url]];
|
|
98
|
+
spawn(bin, args, { stdio: "ignore", detached: true })
|
|
99
|
+
.on("error", () => undefined)
|
|
100
|
+
.unref();
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const main = async (): Promise<void> => {
|
|
104
|
+
const args = parse(process.argv.slice(2));
|
|
105
|
+
const repoRoot = process.cwd();
|
|
106
|
+
const configFilename = process.env.ARCHITECTURE_CONFIG;
|
|
107
|
+
if (!existsSync(SITE_DIR)) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`the page is not built: ${SITE_DIR} is missing. In this repository, run \`pnpm exec nx build @goodbones/browser\`.`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (args.command === "build") {
|
|
114
|
+
const out = path.resolve(repoRoot, args.out ?? "");
|
|
115
|
+
const collected = await collect({ repoRoot, roots: args.roots, configFilename, nudge: false });
|
|
116
|
+
exportSite(SITE_DIR, out, collected);
|
|
117
|
+
process.stdout.write(
|
|
118
|
+
`wrote ${describePath(repoRoot, out)}: ${String(collected.atlas.files.length)} files, ${String(collected.campaigns.campaigns.length)} campaigns. Serve it from the root of a host.\n`,
|
|
119
|
+
);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const source = makeSource({
|
|
124
|
+
repoRoot,
|
|
125
|
+
roots: args.roots,
|
|
126
|
+
configFilename,
|
|
127
|
+
nudge: args.nudge,
|
|
128
|
+
watch: true,
|
|
129
|
+
});
|
|
130
|
+
const served = await serve({
|
|
131
|
+
siteDir: SITE_DIR,
|
|
132
|
+
handler: makeHandler(source),
|
|
133
|
+
port: args.port,
|
|
134
|
+
host: args.host,
|
|
135
|
+
});
|
|
136
|
+
process.stdout.write(
|
|
137
|
+
`goodbones-browser: ${served.url} over ${path.basename(repoRoot)} (${args.roots.join(", ")}); watching for changes.\n`,
|
|
138
|
+
);
|
|
139
|
+
if (args.open) openBrowser(served.url);
|
|
140
|
+
const stop = (): void => {
|
|
141
|
+
source.close();
|
|
142
|
+
void served.close().then(() => process.exit(0));
|
|
143
|
+
};
|
|
144
|
+
process.once("SIGINT", stop);
|
|
145
|
+
process.once("SIGTERM", stop);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
main().catch((cause: unknown) => {
|
|
149
|
+
const message =
|
|
150
|
+
typeof cause === "object" && cause !== null && "message" in cause
|
|
151
|
+
? String(cause.message)
|
|
152
|
+
: String(cause);
|
|
153
|
+
process.stderr.write(`\n${message}\n`);
|
|
154
|
+
process.exitCode = 1;
|
|
155
|
+
});
|