@scenar/cli 0.1.20 → 0.2.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/example-bundle/assets/index-BLQ14SEo.js +147 -0
- package/example-bundle/assets/logo-f-5LjVqJ.png +0 -0
- package/example-bundle/assets/style-Dnzx_jUO.css +1 -0
- package/example-bundle/index.html +13 -0
- package/example-bundle/pack-manifest.json +36 -0
- package/example-bundle/scenario.json +9 -0
- package/package.json +17 -5
- package/src/__tests__/pack-generate-embed-entry.test.ts +59 -6
- package/src/__tests__/publish-command.test.ts +46 -0
- package/src/__tests__/publish-flow.test.ts +220 -0
- package/src/__tests__/read-viewport.test.ts +45 -0
- package/src/__tests__/run-publish.test.ts +92 -0
- package/src/__tests__/serve-command.test.ts +44 -0
- package/src/__tests__/serve-request-path.test.ts +67 -0
- package/src/__tests__/serve-static-server.test.ts +88 -0
- package/src/__tests__/try-command.test.ts +21 -0
- package/src/api.d.ts +31 -0
- package/src/api.d.ts.map +1 -0
- package/src/api.js +28 -0
- package/src/api.js.map +1 -0
- package/src/api.ts +55 -0
- package/src/bundle/read-viewport.d.ts +23 -0
- package/src/bundle/read-viewport.d.ts.map +1 -0
- package/src/bundle/read-viewport.js +25 -0
- package/src/bundle/read-viewport.js.map +1 -0
- package/src/bundle/read-viewport.ts +36 -0
- package/src/commands/deploy.d.ts.map +1 -1
- package/src/commands/deploy.js +8 -24
- package/src/commands/deploy.js.map +1 -1
- package/src/commands/deploy.ts +10 -28
- package/src/commands/narrate.d.ts.map +1 -1
- package/src/commands/narrate.js +39 -170
- package/src/commands/narrate.js.map +1 -1
- package/src/commands/narrate.ts +48 -289
- package/src/commands/pack.d.ts.map +1 -1
- package/src/commands/pack.js +12 -112
- package/src/commands/pack.js.map +1 -1
- package/src/commands/pack.ts +12 -128
- package/src/commands/publish.d.ts +3 -0
- package/src/commands/publish.d.ts.map +1 -0
- package/src/commands/publish.js +64 -0
- package/src/commands/publish.js.map +1 -0
- package/src/commands/publish.ts +86 -0
- package/src/commands/render.d.ts.map +1 -1
- package/src/commands/render.js +12 -194
- package/src/commands/render.js.map +1 -1
- package/src/commands/render.ts +19 -286
- package/src/commands/serve.d.ts +3 -0
- package/src/commands/serve.d.ts.map +1 -0
- package/src/commands/serve.js +91 -0
- package/src/commands/serve.js.map +1 -0
- package/src/commands/serve.ts +112 -0
- package/src/commands/try.d.ts +3 -0
- package/src/commands/try.d.ts.map +1 -0
- package/src/commands/try.js +99 -0
- package/src/commands/try.js.map +1 -0
- package/src/commands/try.ts +122 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +6 -0
- package/src/index.js.map +1 -1
- package/src/index.ts +6 -0
- package/src/narrate/run-narrate.d.ts +43 -0
- package/src/narrate/run-narrate.d.ts.map +1 -0
- package/src/narrate/run-narrate.js +174 -0
- package/src/narrate/run-narrate.js.map +1 -0
- package/src/narrate/run-narrate.ts +298 -0
- package/src/pack/generate-embed-entry.d.ts +11 -0
- package/src/pack/generate-embed-entry.d.ts.map +1 -1
- package/src/pack/generate-embed-entry.js +81 -10
- package/src/pack/generate-embed-entry.js.map +1 -1
- package/src/pack/generate-embed-entry.ts +81 -10
- package/src/pack/run-pack.d.ts +34 -0
- package/src/pack/run-pack.d.ts.map +1 -0
- package/src/pack/run-pack.js +117 -0
- package/src/pack/run-pack.js.map +1 -0
- package/src/pack/run-pack.ts +163 -0
- package/src/publish/github.d.ts +11 -0
- package/src/publish/github.d.ts.map +1 -0
- package/src/publish/github.js +197 -0
- package/src/publish/github.js.map +1 -0
- package/src/publish/github.ts +216 -0
- package/src/publish/publish-flow.d.ts +110 -0
- package/src/publish/publish-flow.d.ts.map +1 -0
- package/src/publish/publish-flow.js +117 -0
- package/src/publish/publish-flow.js.map +1 -0
- package/src/publish/publish-flow.ts +199 -0
- package/src/publish/run-publish.d.ts +41 -0
- package/src/publish/run-publish.d.ts.map +1 -0
- package/src/publish/run-publish.js +77 -0
- package/src/publish/run-publish.js.map +1 -0
- package/src/publish/run-publish.ts +131 -0
- package/src/render/run-render.d.ts +31 -0
- package/src/render/run-render.d.ts.map +1 -0
- package/src/render/run-render.js +196 -0
- package/src/render/run-render.js.map +1 -0
- package/src/render/run-render.ts +287 -0
- package/src/serve/request-path.d.ts +23 -0
- package/src/serve/request-path.d.ts.map +1 -0
- package/src/serve/request-path.js +52 -0
- package/src/serve/request-path.js.map +1 -0
- package/src/serve/request-path.ts +55 -0
- package/src/serve/run-serve.d.ts +31 -0
- package/src/serve/run-serve.d.ts.map +1 -0
- package/src/serve/run-serve.js +35 -0
- package/src/serve/run-serve.js.map +1 -0
- package/src/serve/run-serve.ts +68 -0
- package/src/serve/static-server.d.ts +38 -0
- package/src/serve/static-server.d.ts.map +1 -0
- package/src/serve/static-server.js +91 -0
- package/src/serve/static-server.js.map +1 -0
- package/src/serve/static-server.ts +118 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
2
|
+
import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { runPublish } from "../publish/run-publish.js";
|
|
6
|
+
import type { PublishFlowDeps } from "../publish/publish-flow.js";
|
|
7
|
+
|
|
8
|
+
/** Fake gh/git deps: record calls, never touch the network. */
|
|
9
|
+
function fakeDeps(): Omit<PublishFlowDeps, "log"> {
|
|
10
|
+
return {
|
|
11
|
+
ensureToolsAvailable: vi.fn(async () => {}),
|
|
12
|
+
resolveOwner: vi.fn(async (org) => org ?? "octocat"),
|
|
13
|
+
repoExists: vi.fn(async () => false),
|
|
14
|
+
createRepo: vi.fn(async () => {}),
|
|
15
|
+
pushBundleToPages: vi.fn(async () => {}),
|
|
16
|
+
enablePages: vi.fn(async () => {}),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("runPublish", () => {
|
|
21
|
+
let dir: string;
|
|
22
|
+
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
dir = await mkdtemp(join(tmpdir(), "scenar-publish-bundle-"));
|
|
25
|
+
await writeFile(join(dir, "index.html"), "<!doctype html><title>t</title>", "utf-8");
|
|
26
|
+
await writeFile(
|
|
27
|
+
join(dir, "scenario.json"),
|
|
28
|
+
JSON.stringify({ schemaVersion: "1", id: "welcome-tour", viewport: { width: 896, height: 480 } }),
|
|
29
|
+
"utf-8",
|
|
30
|
+
);
|
|
31
|
+
await writeFile(
|
|
32
|
+
join(dir, "pack-manifest.json"),
|
|
33
|
+
JSON.stringify({ schemaVersion: 1, scenarioId: "welcome-tour", files: [{ path: "index.html", sha256: "a".repeat(64), sizeBytes: 30, contentType: "text/html" }] }),
|
|
34
|
+
"utf-8",
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
afterEach(async () => {
|
|
39
|
+
await rm(dir, { recursive: true, force: true });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("defaults to the shared repo + scenario-slug subpath and returns the URL + snippet", async () => {
|
|
43
|
+
const deps = fakeDeps();
|
|
44
|
+
const { result, snippet, recordedViewport } = await runPublish({ bundleDir: dir, deps });
|
|
45
|
+
|
|
46
|
+
expect(result.repo).toBe("scenar-embeds");
|
|
47
|
+
expect(result.path).toBe("welcome-tour");
|
|
48
|
+
expect(result.pagesUrl).toBe("https://octocat.github.io/scenar-embeds/welcome-tour/");
|
|
49
|
+
expect(deps.createRepo).toHaveBeenCalledWith(
|
|
50
|
+
"octocat",
|
|
51
|
+
"scenar-embeds",
|
|
52
|
+
expect.objectContaining({ private: false }),
|
|
53
|
+
);
|
|
54
|
+
expect(deps.pushBundleToPages).toHaveBeenCalledWith(
|
|
55
|
+
expect.objectContaining({ path: "welcome-tour" }),
|
|
56
|
+
);
|
|
57
|
+
expect(recordedViewport).toBe(true);
|
|
58
|
+
expect(snippet).toContain("https://octocat.github.io/scenar-embeds/welcome-tour/");
|
|
59
|
+
expect(snippet).toContain("aspect-ratio:896/480");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("honors an explicit repo + org, defaulting the path to the slug", async () => {
|
|
63
|
+
const deps = fakeDeps();
|
|
64
|
+
const { result } = await runPublish({ bundleDir: dir, repo: "tours", org: "stigmer", deps });
|
|
65
|
+
expect(result.pagesUrl).toBe("https://stigmer.github.io/tours/welcome-tour/");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("publishes at the repo root when --path is /", async () => {
|
|
69
|
+
const deps = fakeDeps();
|
|
70
|
+
const { result } = await runPublish({ bundleDir: dir, repo: "scenar-welcome-tour", org: "stigmer", path: "/", deps });
|
|
71
|
+
expect(result.path).toBe("");
|
|
72
|
+
expect(result.pagesUrl).toBe("https://stigmer.github.io/scenar-welcome-tour/");
|
|
73
|
+
expect(deps.pushBundleToPages).toHaveBeenCalledWith(expect.objectContaining({ path: "" }));
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("rejects an invalid explicit path before any GitHub call", async () => {
|
|
77
|
+
const deps = fakeDeps();
|
|
78
|
+
await expect(runPublish({ bundleDir: dir, path: "../escape", deps })).rejects.toThrow(/\.\./);
|
|
79
|
+
expect(deps.ensureToolsAvailable).not.toHaveBeenCalled();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("rejects an invalid explicit repo name before any GitHub call", async () => {
|
|
83
|
+
const deps = fakeDeps();
|
|
84
|
+
await expect(runPublish({ bundleDir: dir, repo: "bad name", deps })).rejects.toThrow(/invalid repo name/);
|
|
85
|
+
expect(deps.ensureToolsAvailable).not.toHaveBeenCalled();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("fails clearly when the bundle has no index.html", async () => {
|
|
89
|
+
await rm(join(dir, "index.html"));
|
|
90
|
+
await expect(runPublish({ bundleDir: dir, deps: fakeDeps() })).rejects.toThrow(/no index\.html/);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { createProgram } from "../index.js";
|
|
3
|
+
|
|
4
|
+
describe("scenar serve", () => {
|
|
5
|
+
let stderrOutput: string;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
stderrOutput = "";
|
|
9
|
+
vi.spyOn(process.stderr, "write").mockImplementation((chunk) => {
|
|
10
|
+
stderrOutput += String(chunk);
|
|
11
|
+
return true;
|
|
12
|
+
});
|
|
13
|
+
process.exitCode = undefined;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("registers the serve command", () => {
|
|
17
|
+
const program = createProgram();
|
|
18
|
+
const cmd = program.commands.find((c) => c.name() === "serve");
|
|
19
|
+
expect(cmd).toBeDefined();
|
|
20
|
+
expect(cmd!.description()).toContain("embed URL");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("accepts a bundle directory argument and exposes its options", () => {
|
|
24
|
+
const program = createProgram();
|
|
25
|
+
const cmd = program.commands.find((c) => c.name() === "serve");
|
|
26
|
+
expect(cmd!.registeredArguments[0]!.name()).toBe("bundleDir");
|
|
27
|
+
const opts = cmd!.options.map((o) => o.long);
|
|
28
|
+
expect(opts).toContain("--port");
|
|
29
|
+
expect(opts).toContain("--host");
|
|
30
|
+
expect(opts).toContain("--open");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("fails clearly when the bundle directory does not exist", async () => {
|
|
34
|
+
const program = createProgram();
|
|
35
|
+
program.exitOverride();
|
|
36
|
+
try {
|
|
37
|
+
await program.parseAsync(["node", "scenar", "serve", "/tmp/__no_bundle__"]);
|
|
38
|
+
} catch {
|
|
39
|
+
// exitOverride throws on a non-zero exit; the assertion is on exitCode.
|
|
40
|
+
}
|
|
41
|
+
expect(process.exitCode).toBe(1);
|
|
42
|
+
expect(stderrOutput).toContain("Error");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { resolveStaticPath, contentTypeFor } from "../serve/request-path.js";
|
|
3
|
+
|
|
4
|
+
describe("resolveStaticPath", () => {
|
|
5
|
+
it("maps the root and trailing-slash paths to index.html", () => {
|
|
6
|
+
expect(resolveStaticPath("/")).toBe("index.html");
|
|
7
|
+
expect(resolveStaticPath("/sub/")).toBe("sub/index.html");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("returns clean relative paths for file requests", () => {
|
|
11
|
+
expect(resolveStaticPath("/assets/index-abc.js")).toBe("assets/index-abc.js");
|
|
12
|
+
expect(resolveStaticPath("/scenario.json")).toBe("scenario.json");
|
|
13
|
+
expect(resolveStaticPath("/narration/step-0.mp3")).toBe("narration/step-0.mp3");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("strips a query string and fragment", () => {
|
|
17
|
+
expect(resolveStaticPath("/assets/app.js?v=2")).toBe("assets/app.js");
|
|
18
|
+
expect(resolveStaticPath("/index.html#top")).toBe("index.html");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("percent-decodes path segments", () => {
|
|
22
|
+
expect(resolveStaticPath("/assets/logo%20art.png")).toBe("assets/logo art.png");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("rejects parent-directory traversal in every form", () => {
|
|
26
|
+
expect(resolveStaticPath("/../secret")).toBeNull();
|
|
27
|
+
expect(resolveStaticPath("/assets/../../etc/passwd")).toBeNull();
|
|
28
|
+
expect(resolveStaticPath("/%2e%2e/secret")).toBeNull();
|
|
29
|
+
expect(resolveStaticPath("/foo/%2e%2e/%2e%2e/bar")).toBeNull();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("rejects current-dir and empty (double-slash) segments", () => {
|
|
33
|
+
expect(resolveStaticPath("/./foo")).toBeNull();
|
|
34
|
+
expect(resolveStaticPath("/foo//bar")).toBeNull();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("rejects backslash and NUL injection", () => {
|
|
38
|
+
expect(resolveStaticPath("/..\\windows")).toBeNull();
|
|
39
|
+
expect(resolveStaticPath("/foo\u0000.js")).toBeNull();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("rejects malformed percent-encoding", () => {
|
|
43
|
+
expect(resolveStaticPath("/%zz")).toBeNull();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("rejects non-absolute paths", () => {
|
|
47
|
+
expect(resolveStaticPath("relative")).toBeNull();
|
|
48
|
+
expect(resolveStaticPath("")).toBeNull();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("contentTypeFor", () => {
|
|
53
|
+
it("resolves canonical bundle content types by extension", () => {
|
|
54
|
+
expect(contentTypeFor("index.html")).toBe("text/html");
|
|
55
|
+
expect(contentTypeFor("assets/app.js")).toBe("text/javascript");
|
|
56
|
+
expect(contentTypeFor("assets/style.css")).toBe("text/css");
|
|
57
|
+
expect(contentTypeFor("scenario.json")).toBe("application/json");
|
|
58
|
+
expect(contentTypeFor("narration/step-0.mp3")).toBe("audio/mpeg");
|
|
59
|
+
expect(contentTypeFor("assets/logo.png")).toBe("image/png");
|
|
60
|
+
expect(contentTypeFor("fonts/inter.woff2")).toBe("font/woff2");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("falls back to application/octet-stream for unknown extensions", () => {
|
|
64
|
+
expect(contentTypeFor("data.bin")).toBe("application/octet-stream");
|
|
65
|
+
expect(contentTypeFor("noext")).toBe("application/octet-stream");
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
|
2
|
+
import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { request } from "node:http";
|
|
6
|
+
import { startBundleServer, type BundleServerHandle } from "../serve/static-server.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Issue a GET with a verbatim request path. Unlike fetch/URL, node:http does not
|
|
10
|
+
* normalise the path, so an encoded "%2e%2e" traversal reaches the server intact
|
|
11
|
+
* — exactly what an attacker would send. Returns the response status code.
|
|
12
|
+
*/
|
|
13
|
+
function rawGetStatus(baseUrl: string, rawPath: string): Promise<number> {
|
|
14
|
+
const base = new URL(baseUrl);
|
|
15
|
+
return new Promise<number>((resolvePromise, reject) => {
|
|
16
|
+
const req = request(
|
|
17
|
+
{ hostname: base.hostname, port: base.port, path: rawPath, method: "GET" },
|
|
18
|
+
(res) => {
|
|
19
|
+
res.resume();
|
|
20
|
+
resolvePromise(res.statusCode ?? 0);
|
|
21
|
+
},
|
|
22
|
+
);
|
|
23
|
+
req.on("error", reject);
|
|
24
|
+
req.end();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe("startBundleServer", () => {
|
|
29
|
+
let dir: string;
|
|
30
|
+
let server: BundleServerHandle;
|
|
31
|
+
|
|
32
|
+
beforeAll(async () => {
|
|
33
|
+
dir = await mkdtemp(join(tmpdir(), "scenar-serve-"));
|
|
34
|
+
await writeFile(join(dir, "index.html"), "<!doctype html><title>tour</title>", "utf-8");
|
|
35
|
+
await mkdir(join(dir, "assets"), { recursive: true });
|
|
36
|
+
await writeFile(join(dir, "assets", "app.js"), "console.log(1)", "utf-8");
|
|
37
|
+
// Port 0 → the OS assigns a free port (no fixed-port collisions in CI).
|
|
38
|
+
server = await startBundleServer({ rootDir: dir, port: 0 });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
afterAll(async () => {
|
|
42
|
+
await server.close();
|
|
43
|
+
await rm(dir, { recursive: true, force: true });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("serves index.html at the root with the right content type", async () => {
|
|
47
|
+
const res = await fetch(server.url);
|
|
48
|
+
expect(res.status).toBe(200);
|
|
49
|
+
expect(res.headers.get("content-type")).toBe("text/html");
|
|
50
|
+
expect(await res.text()).toContain("<title>tour</title>");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("serves nested assets with the right content type", async () => {
|
|
54
|
+
const res = await fetch(new URL("assets/app.js", server.url));
|
|
55
|
+
expect(res.status).toBe(200);
|
|
56
|
+
expect(res.headers.get("content-type")).toBe("text/javascript");
|
|
57
|
+
expect(await res.text()).toBe("console.log(1)");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("sets Cache-Control: no-cache so a preview never serves stale assets", async () => {
|
|
61
|
+
const res = await fetch(server.url);
|
|
62
|
+
expect(res.headers.get("cache-control")).toBe("no-cache");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("returns 404 for a missing file", async () => {
|
|
66
|
+
const res = await fetch(new URL("does-not-exist.js", server.url));
|
|
67
|
+
expect(res.status).toBe(404);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("answers HEAD with headers but no body", async () => {
|
|
71
|
+
const res = await fetch(server.url, { method: "HEAD" });
|
|
72
|
+
expect(res.status).toBe(200);
|
|
73
|
+
expect(res.headers.get("content-type")).toBe("text/html");
|
|
74
|
+
expect(await res.text()).toBe("");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("rejects non-GET/HEAD methods with 405", async () => {
|
|
78
|
+
const res = await fetch(server.url, { method: "POST" });
|
|
79
|
+
expect(res.status).toBe(405);
|
|
80
|
+
expect(res.headers.get("allow")).toBe("GET, HEAD");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("rejects a raw encoded traversal attempt with 400 (never reaches disk)", async () => {
|
|
84
|
+
// Sent verbatim via node:http so the "%2e%2e" survives to the server.
|
|
85
|
+
expect(await rawGetStatus(server.url, "/%2e%2e/%2e%2e/secret")).toBe(400);
|
|
86
|
+
expect(await rawGetStatus(server.url, "/assets/%2e%2e/%2e%2e/etc/passwd")).toBe(400);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { createProgram } from "../index.js";
|
|
3
|
+
|
|
4
|
+
describe("scenar try", () => {
|
|
5
|
+
it("registers the try command", () => {
|
|
6
|
+
const program = createProgram();
|
|
7
|
+
const cmd = program.commands.find((c) => c.name() === "try");
|
|
8
|
+
expect(cmd).toBeDefined();
|
|
9
|
+
expect(cmd!.description()).toContain("no app required");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("takes no positional arguments and exposes its options", () => {
|
|
13
|
+
const program = createProgram();
|
|
14
|
+
const cmd = program.commands.find((c) => c.name() === "try");
|
|
15
|
+
expect(cmd!.registeredArguments).toHaveLength(0);
|
|
16
|
+
const opts = cmd!.options.map((o) => o.long);
|
|
17
|
+
expect(opts).toContain("--port");
|
|
18
|
+
expect(opts).toContain("--host");
|
|
19
|
+
expect(opts).toContain("--open");
|
|
20
|
+
});
|
|
21
|
+
});
|
package/src/api.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The programmatic API of the Scenar CLI — the same orchestration the commands
|
|
3
|
+
* run, exposed as plain functions so other tools (notably @scenar/mcp-server)
|
|
4
|
+
* can drive Scenar without shelling out. Each `run*` performs one operation and
|
|
5
|
+
* returns a structured result; none touch process.exit or the process streams
|
|
6
|
+
* (they accept an optional `onLog` for progress).
|
|
7
|
+
*/
|
|
8
|
+
export { runPack } from "./pack/run-pack.js";
|
|
9
|
+
export type { RunPackOptions, PackResult } from "./pack/run-pack.js";
|
|
10
|
+
export type { PackManifest } from "./pack/pack-manifest.js";
|
|
11
|
+
export { runNarrate } from "./narrate/run-narrate.js";
|
|
12
|
+
export type { RunNarrateOptions, NarrateResult, NarratedScenario } from "./narrate/run-narrate.js";
|
|
13
|
+
export { runRender } from "./render/run-render.js";
|
|
14
|
+
export type { RunRenderOptions, RenderResult } from "./render/run-render.js";
|
|
15
|
+
export { runServe } from "./serve/run-serve.js";
|
|
16
|
+
export type { RunServeOptions, ServeResult } from "./serve/run-serve.js";
|
|
17
|
+
export { startBundleServer, createBundleServer } from "./serve/static-server.js";
|
|
18
|
+
export type { BundleServerHandle, StartBundleServerOptions } from "./serve/static-server.js";
|
|
19
|
+
export { runPublish } from "./publish/run-publish.js";
|
|
20
|
+
export type { RunPublishOptions, PublishRunResult } from "./publish/run-publish.js";
|
|
21
|
+
export { runPublishFlow, validateRepoName, validatePublishPath, normalizePath, pagesUrl, repoUrl, } from "./publish/publish-flow.js";
|
|
22
|
+
export type { PublishFlowDeps, PublishOptions, PublishResult, } from "./publish/publish-flow.js";
|
|
23
|
+
export { createGithubPublisher } from "./publish/github.js";
|
|
24
|
+
export { validateScenario } from "./validate/scenario-validator.js";
|
|
25
|
+
export { loadScenarioYaml } from "./util/load-yaml.js";
|
|
26
|
+
export { readBundleViewport } from "./bundle/read-viewport.js";
|
|
27
|
+
export type { BundleViewport } from "./bundle/read-viewport.js";
|
|
28
|
+
export { buildEmbedSnippet } from "./deploy/embed-snippet.js";
|
|
29
|
+
export { DEFAULT_VIEWPORT, parseViewport } from "./pack/viewport.js";
|
|
30
|
+
export type { Viewport } from "./pack/viewport.js";
|
|
31
|
+
//# sourceMappingURL=api.d.ts.map
|
package/src/api.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAGnG,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG7E,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACjF,YAAY,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAG7F,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACpF,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,QAAQ,EACR,OAAO,GACR,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,eAAe,EACf,cAAc,EACd,aAAa,GACd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,YAAY,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACrE,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC"}
|
package/src/api.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The programmatic API of the Scenar CLI — the same orchestration the commands
|
|
3
|
+
* run, exposed as plain functions so other tools (notably @scenar/mcp-server)
|
|
4
|
+
* can drive Scenar without shelling out. Each `run*` performs one operation and
|
|
5
|
+
* returns a structured result; none touch process.exit or the process streams
|
|
6
|
+
* (they accept an optional `onLog` for progress).
|
|
7
|
+
*/
|
|
8
|
+
// Pack
|
|
9
|
+
export { runPack } from "./pack/run-pack.js";
|
|
10
|
+
// Narrate
|
|
11
|
+
export { runNarrate } from "./narrate/run-narrate.js";
|
|
12
|
+
// Render
|
|
13
|
+
export { runRender } from "./render/run-render.js";
|
|
14
|
+
// Serve
|
|
15
|
+
export { runServe } from "./serve/run-serve.js";
|
|
16
|
+
export { startBundleServer, createBundleServer } from "./serve/static-server.js";
|
|
17
|
+
// Publish (GitHub Pages)
|
|
18
|
+
export { runPublish } from "./publish/run-publish.js";
|
|
19
|
+
export { runPublishFlow, validateRepoName, validatePublishPath, normalizePath, pagesUrl, repoUrl, } from "./publish/publish-flow.js";
|
|
20
|
+
export { createGithubPublisher } from "./publish/github.js";
|
|
21
|
+
// Validate
|
|
22
|
+
export { validateScenario } from "./validate/scenario-validator.js";
|
|
23
|
+
export { loadScenarioYaml } from "./util/load-yaml.js";
|
|
24
|
+
// Bundle helpers (viewport + embed snippet)
|
|
25
|
+
export { readBundleViewport } from "./bundle/read-viewport.js";
|
|
26
|
+
export { buildEmbedSnippet } from "./deploy/embed-snippet.js";
|
|
27
|
+
export { DEFAULT_VIEWPORT, parseViewport } from "./pack/viewport.js";
|
|
28
|
+
//# sourceMappingURL=api.js.map
|
package/src/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO;AACP,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAI7C,UAAU;AACV,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGtD,SAAS;AACT,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGnD,QAAQ;AACR,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAGjF,yBAAyB;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,QAAQ,EACR,OAAO,GACR,MAAM,2BAA2B,CAAC;AAMnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,WAAW;AACX,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,4CAA4C;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The programmatic API of the Scenar CLI — the same orchestration the commands
|
|
3
|
+
* run, exposed as plain functions so other tools (notably @scenar/mcp-server)
|
|
4
|
+
* can drive Scenar without shelling out. Each `run*` performs one operation and
|
|
5
|
+
* returns a structured result; none touch process.exit or the process streams
|
|
6
|
+
* (they accept an optional `onLog` for progress).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Pack
|
|
10
|
+
export { runPack } from "./pack/run-pack.js";
|
|
11
|
+
export type { RunPackOptions, PackResult } from "./pack/run-pack.js";
|
|
12
|
+
export type { PackManifest } from "./pack/pack-manifest.js";
|
|
13
|
+
|
|
14
|
+
// Narrate
|
|
15
|
+
export { runNarrate } from "./narrate/run-narrate.js";
|
|
16
|
+
export type { RunNarrateOptions, NarrateResult, NarratedScenario } from "./narrate/run-narrate.js";
|
|
17
|
+
|
|
18
|
+
// Render
|
|
19
|
+
export { runRender } from "./render/run-render.js";
|
|
20
|
+
export type { RunRenderOptions, RenderResult } from "./render/run-render.js";
|
|
21
|
+
|
|
22
|
+
// Serve
|
|
23
|
+
export { runServe } from "./serve/run-serve.js";
|
|
24
|
+
export type { RunServeOptions, ServeResult } from "./serve/run-serve.js";
|
|
25
|
+
export { startBundleServer, createBundleServer } from "./serve/static-server.js";
|
|
26
|
+
export type { BundleServerHandle, StartBundleServerOptions } from "./serve/static-server.js";
|
|
27
|
+
|
|
28
|
+
// Publish (GitHub Pages)
|
|
29
|
+
export { runPublish } from "./publish/run-publish.js";
|
|
30
|
+
export type { RunPublishOptions, PublishRunResult } from "./publish/run-publish.js";
|
|
31
|
+
export {
|
|
32
|
+
runPublishFlow,
|
|
33
|
+
validateRepoName,
|
|
34
|
+
validatePublishPath,
|
|
35
|
+
normalizePath,
|
|
36
|
+
pagesUrl,
|
|
37
|
+
repoUrl,
|
|
38
|
+
} from "./publish/publish-flow.js";
|
|
39
|
+
export type {
|
|
40
|
+
PublishFlowDeps,
|
|
41
|
+
PublishOptions,
|
|
42
|
+
PublishResult,
|
|
43
|
+
} from "./publish/publish-flow.js";
|
|
44
|
+
export { createGithubPublisher } from "./publish/github.js";
|
|
45
|
+
|
|
46
|
+
// Validate
|
|
47
|
+
export { validateScenario } from "./validate/scenario-validator.js";
|
|
48
|
+
export { loadScenarioYaml } from "./util/load-yaml.js";
|
|
49
|
+
|
|
50
|
+
// Bundle helpers (viewport + embed snippet)
|
|
51
|
+
export { readBundleViewport } from "./bundle/read-viewport.js";
|
|
52
|
+
export type { BundleViewport } from "./bundle/read-viewport.js";
|
|
53
|
+
export { buildEmbedSnippet } from "./deploy/embed-snippet.js";
|
|
54
|
+
export { DEFAULT_VIEWPORT, parseViewport } from "./pack/viewport.js";
|
|
55
|
+
export type { Viewport } from "./pack/viewport.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Viewport } from "../pack/viewport.js";
|
|
2
|
+
/** The outcome of reading a bundle's recorded viewport. */
|
|
3
|
+
export interface BundleViewport {
|
|
4
|
+
/** The viewport to use — the recorded one, or {@link DEFAULT_VIEWPORT}. */
|
|
5
|
+
readonly viewport: Viewport;
|
|
6
|
+
/**
|
|
7
|
+
* Whether the viewport came from the bundle's scenario.json. False when the
|
|
8
|
+
* file is missing/unreadable/invalid (older bundles, or hand-assembled dirs),
|
|
9
|
+
* in which case {@link DEFAULT_VIEWPORT} is returned. Callers decide whether
|
|
10
|
+
* to surface a "re-pack to embed at the exact aspect ratio" note.
|
|
11
|
+
*/
|
|
12
|
+
readonly recorded: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Read the canonical viewport recorded in a bundle's scenario.json (DD-004),
|
|
16
|
+
* falling back to {@link DEFAULT_VIEWPORT} when it is absent or malformed.
|
|
17
|
+
*
|
|
18
|
+
* Shared by `deploy` and `serve` so the two derive the embed snippet's aspect
|
|
19
|
+
* ratio from one place and cannot drift. Pure-ish (one file read, no logging) —
|
|
20
|
+
* the caller owns any user-facing note about a missing viewport.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readBundleViewport(bundleDir: string): Promise<BundleViewport>;
|
|
23
|
+
//# sourceMappingURL=read-viewport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-viewport.d.ts","sourceRoot":"","sources":["../../../src/bundle/read-viewport.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmC,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAErF,2DAA2D;AAC3D,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CASnF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { SCENARIO_JSON_FILE } from "../pack/pack-manifest.js";
|
|
4
|
+
import { DEFAULT_VIEWPORT, parseViewport } from "../pack/viewport.js";
|
|
5
|
+
/**
|
|
6
|
+
* Read the canonical viewport recorded in a bundle's scenario.json (DD-004),
|
|
7
|
+
* falling back to {@link DEFAULT_VIEWPORT} when it is absent or malformed.
|
|
8
|
+
*
|
|
9
|
+
* Shared by `deploy` and `serve` so the two derive the embed snippet's aspect
|
|
10
|
+
* ratio from one place and cannot drift. Pure-ish (one file read, no logging) —
|
|
11
|
+
* the caller owns any user-facing note about a missing viewport.
|
|
12
|
+
*/
|
|
13
|
+
export async function readBundleViewport(bundleDir) {
|
|
14
|
+
try {
|
|
15
|
+
const raw = await readFile(join(bundleDir, SCENARIO_JSON_FILE), "utf-8");
|
|
16
|
+
const viewport = parseViewport(JSON.parse(raw).viewport);
|
|
17
|
+
if (viewport)
|
|
18
|
+
return { viewport, recorded: true };
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Missing/unreadable/invalid scenario.json — fall through to the default.
|
|
22
|
+
}
|
|
23
|
+
return { viewport: DEFAULT_VIEWPORT, recorded: false };
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=read-viewport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-viewport.js","sourceRoot":"","sources":["../../../src/bundle/read-viewport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAiB,MAAM,qBAAqB,CAAC;AAerF;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,SAAiB;IACxD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,kBAAkB,CAAC,EAAE,OAAO,CAAC,CAAC;QACzE,MAAM,QAAQ,GAAG,aAAa,CAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAA4B,CAAC,QAAQ,CAAC,CAAC;QACrF,IAAI,QAAQ;YAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,0EAA0E;IAC5E,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { SCENARIO_JSON_FILE } from "../pack/pack-manifest.js";
|
|
4
|
+
import { DEFAULT_VIEWPORT, parseViewport, type Viewport } from "../pack/viewport.js";
|
|
5
|
+
|
|
6
|
+
/** The outcome of reading a bundle's recorded viewport. */
|
|
7
|
+
export interface BundleViewport {
|
|
8
|
+
/** The viewport to use — the recorded one, or {@link DEFAULT_VIEWPORT}. */
|
|
9
|
+
readonly viewport: Viewport;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the viewport came from the bundle's scenario.json. False when the
|
|
12
|
+
* file is missing/unreadable/invalid (older bundles, or hand-assembled dirs),
|
|
13
|
+
* in which case {@link DEFAULT_VIEWPORT} is returned. Callers decide whether
|
|
14
|
+
* to surface a "re-pack to embed at the exact aspect ratio" note.
|
|
15
|
+
*/
|
|
16
|
+
readonly recorded: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Read the canonical viewport recorded in a bundle's scenario.json (DD-004),
|
|
21
|
+
* falling back to {@link DEFAULT_VIEWPORT} when it is absent or malformed.
|
|
22
|
+
*
|
|
23
|
+
* Shared by `deploy` and `serve` so the two derive the embed snippet's aspect
|
|
24
|
+
* ratio from one place and cannot drift. Pure-ish (one file read, no logging) —
|
|
25
|
+
* the caller owns any user-facing note about a missing viewport.
|
|
26
|
+
*/
|
|
27
|
+
export async function readBundleViewport(bundleDir: string): Promise<BundleViewport> {
|
|
28
|
+
try {
|
|
29
|
+
const raw = await readFile(join(bundleDir, SCENARIO_JSON_FILE), "utf-8");
|
|
30
|
+
const viewport = parseViewport((JSON.parse(raw) as { viewport?: unknown }).viewport);
|
|
31
|
+
if (viewport) return { viewport, recorded: true };
|
|
32
|
+
} catch {
|
|
33
|
+
// Missing/unreadable/invalid scenario.json — fall through to the default.
|
|
34
|
+
}
|
|
35
|
+
return { viewport: DEFAULT_VIEWPORT, recorded: false };
|
|
36
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/commands/deploy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/commands/deploy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqF5D"}
|
package/src/commands/deploy.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolve, join } from "node:path";
|
|
2
2
|
import { readFile, stat } from "node:fs/promises";
|
|
3
|
-
import { PACK_MANIFEST_FILE
|
|
4
|
-
import {
|
|
3
|
+
import { PACK_MANIFEST_FILE } from "../pack/pack-manifest.js";
|
|
4
|
+
import { readBundleViewport } from "../bundle/read-viewport.js";
|
|
5
5
|
import { createBackendClients } from "../deploy/client.js";
|
|
6
6
|
import { putFile } from "../deploy/upload.js";
|
|
7
7
|
import { buildEmbedSnippet } from "../deploy/embed-snippet.js";
|
|
@@ -62,7 +62,12 @@ export function registerDeployCommand(program) {
|
|
|
62
62
|
// piping). Responsive iframe at the bundle's canonical aspect ratio
|
|
63
63
|
// (DD-002/DD-004); falls back to the default viewport for bundles packed
|
|
64
64
|
// before the viewport was recorded.
|
|
65
|
-
const viewport = await
|
|
65
|
+
const { viewport, recorded } = await readBundleViewport(resolvedDir);
|
|
66
|
+
if (!recorded) {
|
|
67
|
+
process.stderr.write(` Note: no recorded viewport for "${name}"; ` +
|
|
68
|
+
`snippet uses the default ${viewport.width}x${viewport.height}. ` +
|
|
69
|
+
"Re-pack with the current CLI to embed at the exact aspect ratio.\n");
|
|
70
|
+
}
|
|
66
71
|
process.stderr.write("\n Embed snippet (paste into any page):\n\n");
|
|
67
72
|
process.stderr.write(`${indent(buildEmbedSnippet({ embedUrl, viewport, title: name }))}\n`);
|
|
68
73
|
}
|
|
@@ -123,27 +128,6 @@ function makeDeps(clients, bundleDir) {
|
|
|
123
128
|
},
|
|
124
129
|
};
|
|
125
130
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Read the canonical viewport recorded in the bundle's scenario.json (DD-004).
|
|
128
|
-
* Falls back to {@link DEFAULT_VIEWPORT} for bundles packed before the viewport
|
|
129
|
-
* was recorded, or if the file is missing/malformed — a snippet with sensible
|
|
130
|
-
* proportions always beats no snippet. `scenarioLabel` is only for the warning.
|
|
131
|
-
*/
|
|
132
|
-
async function readScenarioViewport(bundleDir, scenarioLabel) {
|
|
133
|
-
try {
|
|
134
|
-
const raw = await readFile(join(bundleDir, SCENARIO_JSON_FILE), "utf-8");
|
|
135
|
-
const viewport = parseViewport(JSON.parse(raw).viewport);
|
|
136
|
-
if (viewport)
|
|
137
|
-
return viewport;
|
|
138
|
-
}
|
|
139
|
-
catch {
|
|
140
|
-
// Missing/unreadable/invalid scenario.json — fall through to the default.
|
|
141
|
-
}
|
|
142
|
-
process.stderr.write(` Note: no recorded viewport for "${scenarioLabel}"; ` +
|
|
143
|
-
`snippet uses the default ${DEFAULT_VIEWPORT.width}x${DEFAULT_VIEWPORT.height}. ` +
|
|
144
|
-
"Re-pack with the current CLI to embed at the exact aspect ratio.\n");
|
|
145
|
-
return DEFAULT_VIEWPORT;
|
|
146
|
-
}
|
|
147
131
|
/** Indent every line by two spaces (for nesting a block under a heading). */
|
|
148
132
|
function indent(block) {
|
|
149
133
|
return block.replace(/^/gm, " ");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,YAAY,EAAuB,MAAM,0BAA0B,CAAC;AAE5F,uGAAuG;AACvG,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAEhD,8FAA8F;AAC9F,MAAM,YAA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