automovie 0.0.0 → 0.2.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/README.md +145 -18
- package/lib/AUTOMOVIE_CAPTURE_OPTIONS.d.ts +6 -0
- package/lib/AUTOMOVIE_CAPTURE_OPTIONS.js +16 -0
- package/lib/AUTOMOVIE_CAPTURE_OPTIONS.js.map +1 -0
- package/lib/AUTOMOVIE_INSPECT_OPTIONS.d.ts +6 -0
- package/lib/AUTOMOVIE_INSPECT_OPTIONS.js +14 -0
- package/lib/AUTOMOVIE_INSPECT_OPTIONS.js.map +1 -0
- package/lib/AUTOMOVIE_RENDER_OPTIONS.d.ts +6 -0
- package/lib/AUTOMOVIE_RENDER_OPTIONS.js +15 -0
- package/lib/AUTOMOVIE_RENDER_OPTIONS.js.map +1 -0
- package/lib/AUTOMOVIE_REVIEW_OPTIONS.d.ts +6 -0
- package/lib/AUTOMOVIE_REVIEW_OPTIONS.js +14 -0
- package/lib/AUTOMOVIE_REVIEW_OPTIONS.js.map +1 -0
- package/lib/AutoMovieCaptureBackend.d.ts +9 -0
- package/lib/{IAutoMoviePackageManager.js → AutoMovieCaptureBackend.js} +1 -1
- package/lib/AutoMovieCaptureBackend.js.map +1 -0
- package/lib/AutoMovieCaptureHost.d.ts +114 -0
- package/lib/AutoMovieCaptureHost.js +219 -0
- package/lib/AutoMovieCaptureHost.js.map +1 -0
- package/lib/AutoMovieCommand.d.ts +24 -13
- package/lib/IAutoMovieChromium.d.ts +75 -0
- package/lib/IAutoMovieChromium.js +3 -0
- package/lib/IAutoMovieChromium.js.map +1 -0
- package/lib/captureAutoMovie.d.ts +23 -0
- package/lib/captureAutoMovie.js +133 -0
- package/lib/captureAutoMovie.js.map +1 -0
- package/lib/deriveAutoMovieProjectName.d.ts +1 -1
- package/lib/deriveAutoMovieProjectName.js +1 -1
- package/lib/findAutoMovieFreePort.d.ts +14 -0
- package/lib/findAutoMovieFreePort.js +61 -0
- package/lib/findAutoMovieFreePort.js.map +1 -0
- package/lib/formatAutoMovieInspectUrl.d.ts +14 -0
- package/lib/formatAutoMovieInspectUrl.js +24 -0
- package/lib/formatAutoMovieInspectUrl.js.map +1 -0
- package/lib/index.d.ts +30 -2
- package/lib/index.js +30 -2
- package/lib/index.js.map +1 -1
- package/lib/inspectAutoMovie.d.ts +19 -0
- package/lib/inspectAutoMovie.js +97 -0
- package/lib/inspectAutoMovie.js.map +1 -0
- package/lib/launchAutoMovieChromium.d.ts +28 -0
- package/lib/launchAutoMovieChromium.js +42 -0
- package/lib/launchAutoMovieChromium.js.map +1 -0
- package/lib/loadAutoMovieProductionModule.d.ts +14 -0
- package/lib/loadAutoMovieProductionModule.js +61 -0
- package/lib/loadAutoMovieProductionModule.js.map +1 -0
- package/lib/planAutoMovieChromiumLaunch.d.ts +27 -0
- package/lib/planAutoMovieChromiumLaunch.js +34 -0
- package/lib/planAutoMovieChromiumLaunch.js.map +1 -0
- package/lib/planAutoMovieModulePageViteConfig.d.ts +37 -0
- package/lib/planAutoMovieModulePageViteConfig.js +27 -0
- package/lib/planAutoMovieModulePageViteConfig.js.map +1 -0
- package/lib/readAutoMovieAddArguments.d.ts +1 -1
- package/lib/readAutoMovieAddArguments.js +1 -1
- package/lib/readAutoMovieCaptureHostOptions.d.ts +36 -0
- package/lib/readAutoMovieCaptureHostOptions.js +57 -0
- package/lib/readAutoMovieCaptureHostOptions.js.map +1 -0
- package/lib/readAutoMovieCommandArguments.d.ts +1 -1
- package/lib/readAutoMovieCommandArguments.js +10 -5
- package/lib/readAutoMovieCommandArguments.js.map +1 -1
- package/lib/readAutoMovieCreateArguments.d.ts +1 -1
- package/lib/readAutoMovieCreateArguments.js +1 -1
- package/lib/readAutoMovieInspectHostOptions.d.ts +29 -0
- package/lib/readAutoMovieInspectHostOptions.js +48 -0
- package/lib/readAutoMovieInspectHostOptions.js.map +1 -0
- package/lib/readAutoMovieRenderOptions.d.ts +33 -0
- package/lib/readAutoMovieRenderOptions.js +51 -0
- package/lib/readAutoMovieRenderOptions.js.map +1 -0
- package/lib/readAutoMovieReviewOptions.d.ts +27 -0
- package/lib/readAutoMovieReviewOptions.js +54 -0
- package/lib/readAutoMovieReviewOptions.js.map +1 -0
- package/lib/readAutoMovieRevision.d.ts +12 -0
- package/lib/readAutoMovieRevision.js +32 -0
- package/lib/readAutoMovieRevision.js.map +1 -0
- package/lib/readAutoMovieVideoProbe.d.ts +23 -0
- package/lib/readAutoMovieVideoProbe.js +39 -0
- package/lib/readAutoMovieVideoProbe.js.map +1 -0
- package/lib/recordAutoMoviePlayback.d.ts +37 -0
- package/lib/recordAutoMoviePlayback.js +122 -0
- package/lib/recordAutoMoviePlayback.js.map +1 -0
- package/lib/renderAutoMovie.d.ts +21 -0
- package/lib/renderAutoMovie.js +95 -0
- package/lib/renderAutoMovie.js.map +1 -0
- package/lib/renderAutoMovieScaffoldNextSteps.d.ts +3 -5
- package/lib/renderAutoMovieScaffoldNextSteps.js +5 -14
- package/lib/renderAutoMovieScaffoldNextSteps.js.map +1 -1
- package/lib/renderAutoMovieVideo.d.ts +35 -0
- package/lib/renderAutoMovieVideo.js +110 -0
- package/lib/renderAutoMovieVideo.js.map +1 -0
- package/lib/resolveAutoMovieFfmpeg.d.ts +19 -0
- package/lib/resolveAutoMovieFfmpeg.js +32 -0
- package/lib/resolveAutoMovieFfmpeg.js.map +1 -0
- package/lib/reviewAutoMovie.d.ts +21 -0
- package/lib/reviewAutoMovie.js +71 -0
- package/lib/reviewAutoMovie.js.map +1 -0
- package/lib/run.d.ts +14 -11
- package/lib/run.js +103 -67
- package/lib/run.js.map +1 -1
- package/lib/runAutoMovieFfmpeg.d.ts +14 -0
- package/lib/runAutoMovieFfmpeg.js +40 -0
- package/lib/runAutoMovieFfmpeg.js.map +1 -0
- package/lib/serveAutoMovieDrawPage.d.ts +28 -0
- package/lib/serveAutoMovieDrawPage.js +108 -0
- package/lib/serveAutoMovieDrawPage.js.map +1 -0
- package/lib/serveAutoMovieInspectorPage.d.ts +32 -0
- package/lib/serveAutoMovieInspectorPage.js +52 -0
- package/lib/serveAutoMovieInspectorPage.js.map +1 -0
- package/lib/writeAutoMovieModulePage.d.ts +38 -0
- package/lib/writeAutoMovieModulePage.js +75 -0
- package/lib/writeAutoMovieModulePage.js.map +1 -0
- package/package.json +27 -6
- package/src/AUTOMOVIE_CAPTURE_OPTIONS.ts +12 -0
- package/src/AUTOMOVIE_INSPECT_OPTIONS.ts +10 -0
- package/src/AUTOMOVIE_RENDER_OPTIONS.ts +11 -0
- package/src/AUTOMOVIE_REVIEW_OPTIONS.ts +10 -0
- package/src/AutoMovieCaptureBackend.ts +9 -0
- package/src/AutoMovieCaptureHost.ts +245 -0
- package/src/AutoMovieCommand.ts +28 -13
- package/src/IAutoMovieChromium.ts +78 -0
- package/src/captureAutoMovie.ts +148 -0
- package/src/deriveAutoMovieProjectName.ts +1 -1
- package/src/findAutoMovieFreePort.ts +27 -0
- package/src/formatAutoMovieInspectUrl.ts +25 -0
- package/src/index.ts +30 -2
- package/src/inspectAutoMovie.ts +81 -0
- package/src/launchAutoMovieChromium.ts +61 -0
- package/src/loadAutoMovieProductionModule.ts +30 -0
- package/src/planAutoMovieChromiumLaunch.ts +45 -0
- package/src/planAutoMovieModulePageViteConfig.ts +53 -0
- package/src/readAutoMovieAddArguments.ts +1 -1
- package/src/readAutoMovieCaptureHostOptions.ts +76 -0
- package/src/readAutoMovieCommandArguments.ts +6 -4
- package/src/readAutoMovieCreateArguments.ts +1 -1
- package/src/readAutoMovieInspectHostOptions.ts +66 -0
- package/src/readAutoMovieRenderOptions.ts +67 -0
- package/src/readAutoMovieReviewOptions.ts +70 -0
- package/src/readAutoMovieRevision.ts +29 -0
- package/src/readAutoMovieVideoProbe.ts +55 -0
- package/src/recordAutoMoviePlayback.ts +168 -0
- package/src/renderAutoMovie.ts +86 -0
- package/src/renderAutoMovieScaffoldNextSteps.ts +4 -18
- package/src/renderAutoMovieVideo.ts +127 -0
- package/src/resolveAutoMovieFfmpeg.ts +33 -0
- package/src/reviewAutoMovie.ts +65 -0
- package/src/run.ts +116 -105
- package/src/runAutoMovieFfmpeg.ts +50 -0
- package/src/serveAutoMovieDrawPage.ts +105 -0
- package/src/serveAutoMovieInspectorPage.ts +82 -0
- package/src/writeAutoMovieModulePage.ts +83 -0
- package/lib/IAutoMoviePackageManager.d.ts +0 -14
- package/lib/IAutoMoviePackageManager.js.map +0 -1
- package/lib/readAutoMovieSyncArguments.d.ts +0 -13
- package/lib/readAutoMovieSyncArguments.js +0 -49
- package/lib/readAutoMovieSyncArguments.js.map +0 -1
- package/lib/selectAutoMoviePackageManager.d.ts +0 -23
- package/lib/selectAutoMoviePackageManager.js +0 -70
- package/lib/selectAutoMoviePackageManager.js.map +0 -1
- package/src/IAutoMoviePackageManager.ts +0 -15
- package/src/readAutoMovieSyncArguments.ts +0 -48
- package/src/selectAutoMoviePackageManager.ts +0 -45
package/src/AutoMovieCommand.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* One admitted CLI request, discriminated by `command`.
|
|
3
3
|
*
|
|
4
|
-
* `help` and `version` carry nothing because they are standalone requests. `create
|
|
4
|
+
* `help` and `version` carry nothing because they are standalone requests. `create` and `add` carry their targets exactly as typed; `run` resolves them against the working directory. An explicit `name` is carried as typed; `run` chooses the name when it is absent.
|
|
5
5
|
*
|
|
6
|
-
* @evidence contracts/development/design.md#principled-representation Each variant carries exactly what its command needs after admission, so `run` performs no further argument parsing.
|
|
6
|
+
* @evidence contracts/development/design.md#principled-representation Each variant carries exactly what its command needs after admission, so `run` performs no further argument parsing, except `capture`, `inspect`, `render` and `review`, whose options are read by the production's renderer's option reader once that renderer is loaded.
|
|
7
7
|
* @evidence contracts/development/design.md#minimal-and-owned-surface A closed union over the command name lets `run` switch on one field, and the workspace family is a closed pair instead of a free path.
|
|
8
|
-
* @evidence contracts/development/design.md#prohibited-design-shortcuts No variant
|
|
8
|
+
* @evidence contracts/development/design.md#prohibited-design-shortcuts No variant other than `capture`, `inspect`, `render` and `review` carries unparsed tokens, and theirs are read by the one option reader every host shares rather than a second grammar here.
|
|
9
9
|
* @evidence contracts/development/common.md#meaningful-documentation Every variant and member states its meaning and who resolves it.
|
|
10
10
|
*/
|
|
11
11
|
export type AutoMovieCommand =
|
|
@@ -27,7 +27,7 @@ export type AutoMovieCommand =
|
|
|
27
27
|
/** Install a pnpm workspace root instead of a single production. */
|
|
28
28
|
workspace: boolean;
|
|
29
29
|
|
|
30
|
-
/** Admit a non-empty target,
|
|
30
|
+
/** Admit a non-empty target, writing over same-path files and keeping the rest. */
|
|
31
31
|
force: boolean;
|
|
32
32
|
|
|
33
33
|
/** Package name as typed; absent, `run` derives or asks for one. */
|
|
@@ -43,22 +43,37 @@ export type AutoMovieCommand =
|
|
|
43
43
|
/** The production's directory under `movies/<family>`, one admitted path segment. */
|
|
44
44
|
directory: string;
|
|
45
45
|
|
|
46
|
-
/** Admit a non-empty production directory,
|
|
46
|
+
/** Admit a non-empty production directory, writing over same-path files and keeping the rest. */
|
|
47
47
|
force: boolean;
|
|
48
48
|
|
|
49
49
|
/** Package name as typed; absent, `run` derives one from the directory segment. */
|
|
50
50
|
name?: string;
|
|
51
51
|
}
|
|
52
52
|
| {
|
|
53
|
-
/**
|
|
54
|
-
command: "
|
|
53
|
+
/** Capture stills of a subject or a video file in the production at the working directory. */
|
|
54
|
+
command: "capture";
|
|
55
55
|
|
|
56
|
-
/** The
|
|
57
|
-
|
|
56
|
+
/** The tokens after `capture`, as typed; `run` reads them through the production's request grammar, which only the production's `@automovie/render` holds. */
|
|
57
|
+
args: string[];
|
|
58
|
+
}
|
|
59
|
+
| {
|
|
60
|
+
/** Serve the inspector page over a subject module of the production or package at the working directory. */
|
|
61
|
+
command: "inspect";
|
|
62
|
+
|
|
63
|
+
/** The tokens after `inspect`, as typed; `run` reads them through the production's request grammar, as for `capture`. */
|
|
64
|
+
args: string[];
|
|
65
|
+
}
|
|
66
|
+
| {
|
|
67
|
+
/** Render one subject of the production at the working directory into a video. */
|
|
68
|
+
command: "render";
|
|
58
69
|
|
|
59
|
-
/**
|
|
60
|
-
|
|
70
|
+
/** The tokens after `render`, as typed; `run` reads them with the production's option reader. */
|
|
71
|
+
args: string[];
|
|
72
|
+
}
|
|
73
|
+
| {
|
|
74
|
+
/** Record real-time playback of the production's running inspector page. */
|
|
75
|
+
command: "review";
|
|
61
76
|
|
|
62
|
-
/**
|
|
63
|
-
|
|
77
|
+
/** The tokens after `review`, as typed; `run` reads them with the production's option reader. */
|
|
78
|
+
args: string[];
|
|
64
79
|
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { IAutoMovieDrawPage } from "@automovie/render";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The part of `playwright-core`'s `chromium` the capture host calls, declared structurally so the command loads the production's own Playwright at run time and a test passes a double.
|
|
5
|
+
*
|
|
6
|
+
* @evidence contracts/development/design.md#principled-representation Playwright's own call shapes: launch with switches, then pages and a version from the browser.
|
|
7
|
+
* @evidence contracts/development/design.md#minimal-and-owned-surface Exactly what `launchAutoMovieChromium` and the capture host call; the page is the draw session's structural page.
|
|
8
|
+
* @evidence contracts/development/design.md#prohibited-design-shortcuts No Playwright type is imported, so the command compiles and installs without Playwright, which is an optional peer.
|
|
9
|
+
* @evidence contracts/development/common.md#meaningful-documentation States who satisfies it and why it is structural.
|
|
10
|
+
*/
|
|
11
|
+
export interface IAutoMovieChromium {
|
|
12
|
+
/**
|
|
13
|
+
* Start a headless browser with the given switches, from `executablePath` when given.
|
|
14
|
+
*
|
|
15
|
+
* @evidence contracts/development/common.md#meaningful-documentation States what is started and from where.
|
|
16
|
+
* @evidenceExclude contracts/development/implementation.md#principled-implementation A signature has no body; Playwright answers.
|
|
17
|
+
* @evidenceExclude contracts/development/implementation.md#clear-and-simple-structure A signature has no body; Playwright answers.
|
|
18
|
+
* @evidenceExclude contracts/development/implementation.md#prohibited-implementation-shortcuts A signature has no body; Playwright answers.
|
|
19
|
+
* @evidenceExclude contracts/development/implementation.md#efficient-algorithms A signature has no body; Playwright answers.
|
|
20
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A signature has no body; Playwright answers.
|
|
21
|
+
* @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources A signature has no body; Playwright answers.
|
|
22
|
+
*/
|
|
23
|
+
launch(options: {
|
|
24
|
+
headless: true;
|
|
25
|
+
args: string[];
|
|
26
|
+
executablePath?: string;
|
|
27
|
+
}): Promise<IAutoMovieChromium.IBrowser>;
|
|
28
|
+
}
|
|
29
|
+
export namespace IAutoMovieChromium {
|
|
30
|
+
/**
|
|
31
|
+
* A launched browser: its version, its pages, and its end.
|
|
32
|
+
*
|
|
33
|
+
* @evidence contracts/development/design.md#principled-representation Playwright's `Browser` call shapes.
|
|
34
|
+
* @evidence contracts/development/design.md#minimal-and-owned-surface The three calls the host makes.
|
|
35
|
+
* @evidence contracts/development/design.md#prohibited-design-shortcuts Structural, as its parent.
|
|
36
|
+
* @evidence contracts/development/common.md#meaningful-documentation States what it is.
|
|
37
|
+
*/
|
|
38
|
+
export interface IBrowser {
|
|
39
|
+
/**
|
|
40
|
+
* The browser's version, such as `131.0.6778.33`.
|
|
41
|
+
*
|
|
42
|
+
* @evidence contracts/development/common.md#meaningful-documentation States what is returned.
|
|
43
|
+
* @evidenceExclude contracts/development/implementation.md#principled-implementation A signature has no body; Playwright answers.
|
|
44
|
+
* @evidenceExclude contracts/development/implementation.md#clear-and-simple-structure A signature has no body; Playwright answers.
|
|
45
|
+
* @evidenceExclude contracts/development/implementation.md#prohibited-implementation-shortcuts A signature has no body; Playwright answers.
|
|
46
|
+
* @evidenceExclude contracts/development/implementation.md#efficient-algorithms A signature has no body; Playwright answers.
|
|
47
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A signature has no body; Playwright answers.
|
|
48
|
+
* @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources A signature has no body; Playwright answers.
|
|
49
|
+
*/
|
|
50
|
+
version(): string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Open a fresh page.
|
|
54
|
+
*
|
|
55
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the effect.
|
|
56
|
+
* @evidenceExclude contracts/development/implementation.md#principled-implementation A signature has no body; Playwright answers.
|
|
57
|
+
* @evidenceExclude contracts/development/implementation.md#clear-and-simple-structure A signature has no body; Playwright answers.
|
|
58
|
+
* @evidenceExclude contracts/development/implementation.md#prohibited-implementation-shortcuts A signature has no body; Playwright answers.
|
|
59
|
+
* @evidenceExclude contracts/development/implementation.md#efficient-algorithms A signature has no body; Playwright answers.
|
|
60
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A signature has no body; Playwright answers.
|
|
61
|
+
* @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources A signature has no body; Playwright answers.
|
|
62
|
+
*/
|
|
63
|
+
newPage(): Promise<IAutoMovieDrawPage>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* End the browser and every page it holds.
|
|
67
|
+
*
|
|
68
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the effect.
|
|
69
|
+
* @evidenceExclude contracts/development/implementation.md#principled-implementation A signature has no body; Playwright answers.
|
|
70
|
+
* @evidenceExclude contracts/development/implementation.md#clear-and-simple-structure A signature has no body; Playwright answers.
|
|
71
|
+
* @evidenceExclude contracts/development/implementation.md#prohibited-implementation-shortcuts A signature has no body; Playwright answers.
|
|
72
|
+
* @evidenceExclude contracts/development/implementation.md#efficient-algorithms A signature has no body; Playwright answers.
|
|
73
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A signature has no body; Playwright answers.
|
|
74
|
+
* @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources A signature has no body; Playwright answers.
|
|
75
|
+
*/
|
|
76
|
+
close(): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type * as Render from "@automovie/render";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { AutoMovieCaptureHost } from "./AutoMovieCaptureHost";
|
|
6
|
+
import { loadAutoMovieProductionModule } from "./loadAutoMovieProductionModule";
|
|
7
|
+
import { readAutoMovieCaptureHostOptions } from "./readAutoMovieCaptureHostOptions";
|
|
8
|
+
import { readAutoMovieRevision } from "./readAutoMovieRevision";
|
|
9
|
+
import { readAutoMovieVideoProbe } from "./readAutoMovieVideoProbe";
|
|
10
|
+
import { resolveAutoMovieFfmpeg } from "./resolveAutoMovieFfmpeg";
|
|
11
|
+
import { runAutoMovieFfmpeg } from "./runAutoMovieFfmpeg";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Run `automovie capture` in a production: read the options through the request grammar, capture a subject drawn by the draw page or a video file's own frames, print what was written, and resolve to the exit status.
|
|
15
|
+
*
|
|
16
|
+
* Options are read by `readAutoMovieCaptureArguments` and split by `readAutoMovieCaptureHostOptions`; the rest is the request `parseAutoMovieCapturePlanRequest` reads, so the command takes exactly the keys of a page's address. With `--module` the subject is drawn through `AutoMovieCaptureHost`, its module called with the JSON of `--props` when given; with `--file` the file is probed by FFmpeg and captured by `runAutoMovieVideoCapture`, its subject named by `subject` or the file's name. Both write into `--out`, or `media/capture/<subject>`.
|
|
17
|
+
*
|
|
18
|
+
* It prints the folder and how many cells were drawn, the backend, every sheet, every cell not drawn with its cause, and each unmatched or changed comparison entry. The status is 1 when any cell was not drawn, because an undrawn cell is unverified evidence, and 0 otherwise; a refusal throws to `run`, which prints it.
|
|
19
|
+
*
|
|
20
|
+
* @evidence contracts/development/common.md#meaningful-documentation States how options are read and split, both sources, where they write, what is printed, and the exit status with its reason.
|
|
21
|
+
* @evidence contracts/development/implementation.md#principled-implementation Every rule of a capture is the render package's; the command loads that package from the production, supplies the browser or FFmpeg, and reports.
|
|
22
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Read, then one branch per source, then one report.
|
|
23
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts An unknown option is refused by the request reader instead of ignored, and FFmpeg is resolved only for a video so a drawn capture never needs it.
|
|
24
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms One host or two FFmpeg runs plus the probe; printing is linear in the record.
|
|
25
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work One capture per command.
|
|
26
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The host is closed on every outcome.
|
|
27
|
+
*/
|
|
28
|
+
export async function captureAutoMovie(props: {
|
|
29
|
+
/** The tokens after `capture`. */
|
|
30
|
+
args: readonly string[];
|
|
31
|
+
|
|
32
|
+
/** The production's root folder, the working directory. */
|
|
33
|
+
root: string;
|
|
34
|
+
|
|
35
|
+
/** The environment, read for `CHROME_PATH` and `FFMPEG_PATH`. */
|
|
36
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
37
|
+
}): Promise<number> {
|
|
38
|
+
const { root } = props;
|
|
39
|
+
const render: typeof Render = loadAutoMovieProductionModule(
|
|
40
|
+
root,
|
|
41
|
+
"@automovie/render",
|
|
42
|
+
) as typeof Render;
|
|
43
|
+
const options: ReturnType<typeof readAutoMovieCaptureHostOptions> =
|
|
44
|
+
readAutoMovieCaptureHostOptions(
|
|
45
|
+
render.readAutoMovieCaptureArguments(props.args),
|
|
46
|
+
);
|
|
47
|
+
const request: Render.IAutoMovieCapturePlanRequest =
|
|
48
|
+
render.parseAutoMovieCapturePlanRequest(options.request);
|
|
49
|
+
|
|
50
|
+
let record: Extract<Render.IAutoMovieCaptureRecord, { state: "complete" }>;
|
|
51
|
+
let backend: string;
|
|
52
|
+
let folder: string;
|
|
53
|
+
if (options.file !== null) {
|
|
54
|
+
// A video file: probe it, then capture its own frames.
|
|
55
|
+
const ffmpeg: string = resolveAutoMovieFfmpeg({
|
|
56
|
+
env: props.env,
|
|
57
|
+
load: (id: string): unknown => loadAutoMovieProductionModule(root, id),
|
|
58
|
+
});
|
|
59
|
+
const file: string = path.resolve(root, options.file);
|
|
60
|
+
const probe: ReturnType<typeof readAutoMovieVideoProbe> =
|
|
61
|
+
readAutoMovieVideoProbe(
|
|
62
|
+
await runAutoMovieFfmpeg(
|
|
63
|
+
ffmpeg,
|
|
64
|
+
["-hide_banner", "-i", file],
|
|
65
|
+
(): boolean => true,
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
const name: string = request.subject ?? path.parse(file).name;
|
|
69
|
+
folder = path.resolve(
|
|
70
|
+
root,
|
|
71
|
+
options.out ?? path.join("media", "capture", name),
|
|
72
|
+
);
|
|
73
|
+
record = await render.runAutoMovieVideoCapture({
|
|
74
|
+
file,
|
|
75
|
+
subject: { name, ...probe },
|
|
76
|
+
request,
|
|
77
|
+
storage: fs,
|
|
78
|
+
root: folder,
|
|
79
|
+
run: async (args: readonly string[]): Promise<void> => {
|
|
80
|
+
await runAutoMovieFfmpeg(ffmpeg, args);
|
|
81
|
+
},
|
|
82
|
+
revision: readAutoMovieRevision(root),
|
|
83
|
+
});
|
|
84
|
+
backend = `ffmpeg ${ffmpeg}`;
|
|
85
|
+
} else {
|
|
86
|
+
// A drawn subject, through the draw page in headless Chromium.
|
|
87
|
+
const host: AutoMovieCaptureHost = await AutoMovieCaptureHost.open({
|
|
88
|
+
root,
|
|
89
|
+
module: options.module!,
|
|
90
|
+
backend: options.backend,
|
|
91
|
+
env: props.env,
|
|
92
|
+
});
|
|
93
|
+
try {
|
|
94
|
+
record = await host.capture({
|
|
95
|
+
request,
|
|
96
|
+
props:
|
|
97
|
+
options.props === null
|
|
98
|
+
? null
|
|
99
|
+
: JSON.parse(
|
|
100
|
+
await fs.readFile(path.resolve(root, options.props), "utf8"),
|
|
101
|
+
),
|
|
102
|
+
...(options.out === null ? {} : { out: options.out }),
|
|
103
|
+
});
|
|
104
|
+
} finally {
|
|
105
|
+
await host.close();
|
|
106
|
+
}
|
|
107
|
+
backend = host.backend;
|
|
108
|
+
folder = path.resolve(
|
|
109
|
+
root,
|
|
110
|
+
options.out ?? path.join("media", "capture", record.subject.name),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// What was written, and what was not drawn.
|
|
115
|
+
const failed: Extract<
|
|
116
|
+
Render.IAutoMovieCaptureRecord.Row,
|
|
117
|
+
{ state: "failed" }
|
|
118
|
+
>[] = record.rows.filter(
|
|
119
|
+
(
|
|
120
|
+
row: Render.IAutoMovieCaptureRecord.Row,
|
|
121
|
+
): row is Extract<
|
|
122
|
+
Render.IAutoMovieCaptureRecord.Row,
|
|
123
|
+
{ state: "failed" }
|
|
124
|
+
> => row.state === "failed",
|
|
125
|
+
);
|
|
126
|
+
const lines: string[] = [
|
|
127
|
+
`capture ${record.subject.name}: ${record.rows.length - failed.length} of ${record.rows.length} cells drawn into ${folder}`,
|
|
128
|
+
`backend ${backend}`,
|
|
129
|
+
...record.sheets.map((sheet: string): string => path.join(folder, sheet)),
|
|
130
|
+
...failed.map(
|
|
131
|
+
(
|
|
132
|
+
row: Extract<Render.IAutoMovieCaptureRecord.Row, { state: "failed" }>,
|
|
133
|
+
): string => `not drawn ${row.name}: ${row.cause}`,
|
|
134
|
+
),
|
|
135
|
+
...(record.comparison === null
|
|
136
|
+
? []
|
|
137
|
+
: record.comparison.entries.flatMap(
|
|
138
|
+
(entry: Render.IAutoMovieCaptureComparison.Entry): string[] =>
|
|
139
|
+
entry.state === "unmatched"
|
|
140
|
+
? [`unmatched ${entry.current ?? entry.earlier}: ${entry.cause}`]
|
|
141
|
+
: entry.mode === "difference" && entry.changed !== 0
|
|
142
|
+
? [`changed ${entry.current}: ${entry.changed} pixels`]
|
|
143
|
+
: [],
|
|
144
|
+
)),
|
|
145
|
+
];
|
|
146
|
+
process.stdout.write(`${lines.join("\n")}\n`);
|
|
147
|
+
return failed.length === 0 ? 0 : 1;
|
|
148
|
+
}
|
|
@@ -10,7 +10,7 @@ const NPM_NAME_LIMIT: number = 214;
|
|
|
10
10
|
*
|
|
11
11
|
* The basename is lowercased, each run of characters other than `a-z`, `0-9`, `.`, `_` and `-` becomes one `-`, the result is cut to npm's 214-character limit, and leading `-`, `.` or `_` and trailing `-` or `.` are removed. A basename with nothing left, such as a filesystem root, yields `AUTOMOVIE_DEFAULT_PROJECT_NAME`. `selectAutoMovieProjectName` passes a `create` request's absolute target, `run` passes an `add` request's directory segment, and `run` hands the result to the template renderer as the project name.
|
|
12
12
|
*
|
|
13
|
-
* This transformation does not validate npm's reserved names; `node_modules` and `favicon.ico` remain unchanged. Windows device names such as `con` also remain unchanged and are refused by `
|
|
13
|
+
* This transformation does not validate npm's reserved names; `node_modules` and `favicon.ico` remain unchanged. Windows device names such as `con` also remain unchanged and are refused by `createAutoMovieScaffold` before any file is written.
|
|
14
14
|
*
|
|
15
15
|
* @evidence contracts/development/implementation.md#principled-implementation Lowercasing and character replacement produce an unscoped-name candidate from the basename in the host's path syntax, then the 214-character cut precedes trimming so the result stays within that limit. This is normalization rather than complete npm admission: reserved names remain unchanged, while the downstream scaffold renderer separately refuses Windows device names.
|
|
16
16
|
* @evidence contracts/development/implementation.md#clear-and-simple-structure One pure function owns the directory-to-name rule, so `run` keeps only dispatch and the rule is checked without publishing a scaffold.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as net from "node:net";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A TCP port the operating system reports free on 127.0.0.1 at the moment of asking, for a page server that must not take another server's port.
|
|
5
|
+
*
|
|
6
|
+
* The port is free only at that moment; the server that takes it listens with `strictPort`, so a port taken meanwhile fails the start instead of moving elsewhere.
|
|
7
|
+
*
|
|
8
|
+
* @evidence contracts/development/common.md#meaningful-documentation States what is returned, the race it leaves and how a caller closes it.
|
|
9
|
+
* @evidence contracts/development/implementation.md#principled-implementation Listening on port 0 asks the operating system for an unused ephemeral port, which the address then reports.
|
|
10
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Listen, read the address, close.
|
|
11
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No fixed port is guessed.
|
|
12
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms One listen and one close.
|
|
13
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Each server asks once.
|
|
14
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The probing server is closed before the promise resolves.
|
|
15
|
+
*/
|
|
16
|
+
export function findAutoMovieFreePort(): Promise<number> {
|
|
17
|
+
return new Promise<number>(
|
|
18
|
+
(resolve: (port: number) => void, reject: (error: Error) => void): void => {
|
|
19
|
+
const server: net.Server = net.createServer();
|
|
20
|
+
server.once("error", reject);
|
|
21
|
+
server.listen(0, "127.0.0.1", (): void => {
|
|
22
|
+
const address: net.AddressInfo = server.address() as net.AddressInfo;
|
|
23
|
+
server.close((): void => resolve(address.port));
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The address of a served inspector page that opens on a request: the page's base address with the request's named text values as its query.
|
|
3
|
+
*
|
|
4
|
+
* `values` are the pairs `formatAutoMovieCapturePlanRequest` writes, in its order; they are joined by `URLSearchParams`, which the page reads back with the same decoder. The request that asks for nothing is the base address alone.
|
|
5
|
+
*
|
|
6
|
+
* @evidence contracts/development/common.md#meaningful-documentation States what the address holds, where the pairs come from, how they are encoded and the empty case.
|
|
7
|
+
* @evidence contracts/development/implementation.md#principled-implementation `URLSearchParams` writes `application/x-www-form-urlencoded`, which the page's `URLSearchParams` decodes to the same pairs, so the page reads the request the command was given.
|
|
8
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One encoding and one join.
|
|
9
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No key is written here; the grammar's writer chose them.
|
|
10
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Linear in the pairs' length.
|
|
11
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A pure conversion.
|
|
12
|
+
* @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Returns a fresh string and keeps nothing.
|
|
13
|
+
*/
|
|
14
|
+
export function formatAutoMovieInspectUrl(
|
|
15
|
+
base: string,
|
|
16
|
+
values: readonly (readonly [key: string, value: string])[],
|
|
17
|
+
): string {
|
|
18
|
+
const query: string = new URLSearchParams(
|
|
19
|
+
values.map(([key, value]: readonly [string, string]): [string, string] => [
|
|
20
|
+
key,
|
|
21
|
+
value,
|
|
22
|
+
]),
|
|
23
|
+
).toString();
|
|
24
|
+
return query === "" ? base : `${base}?${query}`;
|
|
25
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,8 +6,36 @@ export * from "./readAutoMovieCreateArguments";
|
|
|
6
6
|
export * from "./readAutoMovieAddArguments";
|
|
7
7
|
export * from "./readAutoMovieNameOption";
|
|
8
8
|
export * from "./selectAutoMovieProjectName";
|
|
9
|
-
export * from "./IAutoMoviePackageManager";
|
|
10
|
-
export * from "./selectAutoMoviePackageManager";
|
|
11
9
|
export * from "./promptAutoMovieProjectName";
|
|
12
10
|
export * from "./run";
|
|
13
11
|
export * from "./renderAutoMovieScaffoldNextSteps";
|
|
12
|
+
export * from "./AutoMovieCaptureBackend";
|
|
13
|
+
export * from "./AutoMovieCaptureHost";
|
|
14
|
+
export * from "./captureAutoMovie";
|
|
15
|
+
export * from "./IAutoMovieChromium";
|
|
16
|
+
export * from "./launchAutoMovieChromium";
|
|
17
|
+
export * from "./loadAutoMovieProductionModule";
|
|
18
|
+
export * from "./planAutoMovieChromiumLaunch";
|
|
19
|
+
export * from "./readAutoMovieCaptureHostOptions";
|
|
20
|
+
export * from "./readAutoMovieRevision";
|
|
21
|
+
export * from "./readAutoMovieVideoProbe";
|
|
22
|
+
export * from "./resolveAutoMovieFfmpeg";
|
|
23
|
+
export * from "./runAutoMovieFfmpeg";
|
|
24
|
+
export * from "./serveAutoMovieDrawPage";
|
|
25
|
+
export * from "./AUTOMOVIE_INSPECT_OPTIONS";
|
|
26
|
+
export * from "./findAutoMovieFreePort";
|
|
27
|
+
export * from "./formatAutoMovieInspectUrl";
|
|
28
|
+
export * from "./inspectAutoMovie";
|
|
29
|
+
export * from "./readAutoMovieInspectHostOptions";
|
|
30
|
+
export * from "./serveAutoMovieInspectorPage";
|
|
31
|
+
export * from "./writeAutoMovieModulePage";
|
|
32
|
+
export * from "./planAutoMovieModulePageViteConfig";
|
|
33
|
+
export * from "./AUTOMOVIE_CAPTURE_OPTIONS";
|
|
34
|
+
export * from "./AUTOMOVIE_RENDER_OPTIONS";
|
|
35
|
+
export * from "./AUTOMOVIE_REVIEW_OPTIONS";
|
|
36
|
+
export * from "./readAutoMovieRenderOptions";
|
|
37
|
+
export * from "./readAutoMovieReviewOptions";
|
|
38
|
+
export * from "./recordAutoMoviePlayback";
|
|
39
|
+
export * from "./renderAutoMovie";
|
|
40
|
+
export * from "./renderAutoMovieVideo";
|
|
41
|
+
export * from "./reviewAutoMovie";
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type * as Render from "@automovie/render";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { formatAutoMovieInspectUrl } from "./formatAutoMovieInspectUrl";
|
|
6
|
+
import { loadAutoMovieProductionModule } from "./loadAutoMovieProductionModule";
|
|
7
|
+
import { readAutoMovieInspectHostOptions } from "./readAutoMovieInspectHostOptions";
|
|
8
|
+
import { serveAutoMovieInspectorPage } from "./serveAutoMovieInspectorPage";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Run `automovie inspect` in a production or package: serve the inspector page over a subject module, print its address with the request as the query, and keep serving until the process is interrupted.
|
|
12
|
+
*
|
|
13
|
+
* Options are read by the production's `readAutoMovieCaptureArguments` and split by `readAutoMovieInspectHostOptions`; the rest is read by `parseAutoMovieCapturePlanRequest`, so a request the capture command would refuse is refused here before anything is served, as is a `--props` file that is not JSON, and an accepted one is written back by `formatAutoMovieCapturePlanRequest` as the address's query. `@automovie/render`, `vite`, and through the page `@automovie/viewer`, `react` and `react-dom`, come from the production. On SIGINT or SIGTERM the server stops, the page is deleted, and the status is 0; a refusal throws to `run`, which prints it.
|
|
14
|
+
*
|
|
15
|
+
* @evidence contracts/development/common.md#meaningful-documentation States how options are read and checked, what is served and printed, which packages come from the production, how the command ends and its status.
|
|
16
|
+
* @evidence contracts/development/implementation.md#principled-implementation Every rule of the request is the render package's and every rule of the page the viewer's; the command loads them from the production, serves, and reports, as `automovie capture` does.
|
|
17
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Read, serve, print, wait, close.
|
|
18
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts A request is read before the server starts, so a mistyped key never opens a page that silently ignores it.
|
|
19
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms One server for the command's life.
|
|
20
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work One page per command.
|
|
21
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The server and its page are closed when the process is interrupted; the signal listeners are removed with them.
|
|
22
|
+
*/
|
|
23
|
+
export async function inspectAutoMovie(props: {
|
|
24
|
+
/** The tokens after `inspect`. */
|
|
25
|
+
args: readonly string[];
|
|
26
|
+
|
|
27
|
+
/** The production's or package's root folder, the working directory. */
|
|
28
|
+
root: string;
|
|
29
|
+
}): Promise<number> {
|
|
30
|
+
const { root } = props;
|
|
31
|
+
const render: typeof Render = loadAutoMovieProductionModule(
|
|
32
|
+
root,
|
|
33
|
+
"@automovie/render",
|
|
34
|
+
) as typeof Render;
|
|
35
|
+
const options: ReturnType<typeof readAutoMovieInspectHostOptions> =
|
|
36
|
+
readAutoMovieInspectHostOptions(
|
|
37
|
+
render.readAutoMovieCaptureArguments(props.args),
|
|
38
|
+
);
|
|
39
|
+
const request: Render.IAutoMovieCapturePlanRequest =
|
|
40
|
+
render.parseAutoMovieCapturePlanRequest(options.request);
|
|
41
|
+
|
|
42
|
+
// The module's props, read before anything is served.
|
|
43
|
+
let data: unknown = null;
|
|
44
|
+
if (options.props !== null) {
|
|
45
|
+
const file: string = path.resolve(root, options.props);
|
|
46
|
+
try {
|
|
47
|
+
data = JSON.parse(fs.readFileSync(file, "utf8")) as unknown;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw new Error(`Inspect --props ${file} is not a readable JSON file`, {
|
|
50
|
+
cause: error,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Vite's CommonJS entry warns once per load; the command loads it on purpose.
|
|
56
|
+
process.env.VITE_CJS_IGNORE_WARNING = "true";
|
|
57
|
+
const page: Awaited<ReturnType<typeof serveAutoMovieInspectorPage>> =
|
|
58
|
+
await serveAutoMovieInspectorPage({
|
|
59
|
+
root,
|
|
60
|
+
module: options.module,
|
|
61
|
+
vite: loadAutoMovieProductionModule(root, "vite"),
|
|
62
|
+
port: options.port,
|
|
63
|
+
props: data,
|
|
64
|
+
});
|
|
65
|
+
process.stdout.write(
|
|
66
|
+
`inspect ${options.module}: ${formatAutoMovieInspectUrl(page.url, render.formatAutoMovieCapturePlanRequest(request))}\nPress Ctrl+C to stop.\n`,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
// Serve until interrupted.
|
|
70
|
+
await new Promise<undefined>((resolve: (value: undefined) => void): void => {
|
|
71
|
+
const stop: () => void = (): void => {
|
|
72
|
+
process.off("SIGINT", stop);
|
|
73
|
+
process.off("SIGTERM", stop);
|
|
74
|
+
resolve(undefined);
|
|
75
|
+
};
|
|
76
|
+
process.on("SIGINT", stop);
|
|
77
|
+
process.on("SIGTERM", stop);
|
|
78
|
+
});
|
|
79
|
+
await page.close();
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { AutoMovieCaptureBackend } from "./AutoMovieCaptureBackend";
|
|
2
|
+
import type { IAutoMovieChromium } from "./IAutoMovieChromium";
|
|
3
|
+
import { planAutoMovieChromiumLaunch } from "./planAutoMovieChromiumLaunch";
|
|
4
|
+
|
|
5
|
+
/** The command that installs the Chromium build the production's `playwright-core` pins for headless use; `playwright-core`'s own command, so the revision is the one the production launches. */
|
|
6
|
+
const INSTALL: string = "npx playwright-core install chromium-headless-shell";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Launch headless Chromium for a capture backend, and describe the launch the way a record names it: the backend, then the Chromium version.
|
|
10
|
+
*
|
|
11
|
+
* A launch that fails because the browser executable is missing is rethrown as an error naming `npx playwright-core install chromium-headless-shell` and `CHROME_PATH`; any other failure is rethrown with the backend named.
|
|
12
|
+
*
|
|
13
|
+
* @evidence contracts/development/common.md#meaningful-documentation States what is launched, the description's form and both failures.
|
|
14
|
+
* @evidence contracts/development/implementation.md#principled-implementation Switches come from `planAutoMovieChromiumLaunch`; Playwright reports a missing browser as an executable that does not exist, which is the message matched, so only that case is turned into the install instruction.
|
|
15
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Plan, launch, describe.
|
|
16
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No other browser or backend is tried after a failure.
|
|
17
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms One launch.
|
|
18
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Each capture host launches its own browser.
|
|
19
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The returned browser is the caller's to close; a failed launch leaves none.
|
|
20
|
+
*/
|
|
21
|
+
export async function launchAutoMovieChromium(props: {
|
|
22
|
+
/** Playwright's `chromium`, loaded from the production. */
|
|
23
|
+
chromium: IAutoMovieChromium;
|
|
24
|
+
|
|
25
|
+
/** How the browser draws. */
|
|
26
|
+
backend: AutoMovieCaptureBackend;
|
|
27
|
+
|
|
28
|
+
/** The environment, read for `CHROME_PATH`. */
|
|
29
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
/** The launched browser. */
|
|
32
|
+
browser: IAutoMovieChromium.IBrowser;
|
|
33
|
+
|
|
34
|
+
/** The backend and Chromium version, such as `swiftshader; Chromium 131.0.6778.33`. */
|
|
35
|
+
backend: string;
|
|
36
|
+
}> {
|
|
37
|
+
const plan: ReturnType<typeof planAutoMovieChromiumLaunch> =
|
|
38
|
+
planAutoMovieChromiumLaunch(props.backend, props.env);
|
|
39
|
+
let browser: IAutoMovieChromium.IBrowser;
|
|
40
|
+
try {
|
|
41
|
+
browser = await props.chromium.launch({
|
|
42
|
+
headless: true,
|
|
43
|
+
args: plan.args,
|
|
44
|
+
...(plan.executablePath === undefined
|
|
45
|
+
? {}
|
|
46
|
+
: { executablePath: plan.executablePath }),
|
|
47
|
+
});
|
|
48
|
+
} catch (error) {
|
|
49
|
+
const message: string =
|
|
50
|
+
error instanceof Error ? error.message : String(error);
|
|
51
|
+
if (/executable doesn't exist|executable does not exist/iu.test(message))
|
|
52
|
+
throw new Error(
|
|
53
|
+
`No Chromium is installed for capture; run ${INSTALL} in the production, or set CHROME_PATH to a Chromium executable`,
|
|
54
|
+
{ cause: error },
|
|
55
|
+
);
|
|
56
|
+
throw new Error(`Chromium did not start for the ${plan.name} backend`, {
|
|
57
|
+
cause: error,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return { browser, backend: `${plan.name}; Chromium ${browser.version()}` };
|
|
61
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Load a package as the production at `root` resolves it, for the capture host's optional peers: `@automovie/render`, `vite`, `playwright-core` and `ffmpeg-static`.
|
|
6
|
+
*
|
|
7
|
+
* The command itself depends on none of them, so `npx automovie create` installs nothing a capture needs; a production that captures installs them, and this resolves the copies it installed. It throws naming the package and the production when it is not installed there.
|
|
8
|
+
*
|
|
9
|
+
* @evidence contracts/development/common.md#meaningful-documentation States which packages it serves, why they come from the production, and the refusal.
|
|
10
|
+
* @evidence contracts/development/implementation.md#principled-implementation `createRequire` anchored at the production's `package.json` applies Node's resolution from that folder, the same copy the production's own scripts import.
|
|
11
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One anchored require.
|
|
12
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No copy beside the command is tried, so a capture never draws with a renderer the production did not install.
|
|
13
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms One resolution; Node caches the module.
|
|
14
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Node's module cache serves a second load of the same package.
|
|
15
|
+
* @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources The module stays in Node's cache for the process, as any import does.
|
|
16
|
+
*/
|
|
17
|
+
export function loadAutoMovieProductionModule(
|
|
18
|
+
root: string,
|
|
19
|
+
id: string,
|
|
20
|
+
): unknown {
|
|
21
|
+
const load: NodeJS.Require = createRequire(path.join(root, "package.json"));
|
|
22
|
+
try {
|
|
23
|
+
return load(id);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`${id} is not installed in ${root}; capture loads it from the production, so add it to the production's dependencies`,
|
|
27
|
+
{ cause: error },
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { AutoMovieCaptureBackend } from "./AutoMovieCaptureBackend";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The Chromium switches and executable for a capture backend.
|
|
5
|
+
*
|
|
6
|
+
* | Backend | Switches | Named |
|
|
7
|
+
* | --- | --- | --- |
|
|
8
|
+
* | `software` | `--use-gl=angle --use-angle=swiftshader` | `swiftshader` |
|
|
9
|
+
* | `gpu` | `--use-gl=angle --use-angle=default --ignore-gpu-blocklist` | `gpu` |
|
|
10
|
+
*
|
|
11
|
+
* The executable is `CHROME_PATH` when the environment sets it to a non-blank path, else the Chromium build Playwright pins, which `executablePath` leaves absent.
|
|
12
|
+
*
|
|
13
|
+
* @evidence contracts/development/common.md#meaningful-documentation Tabulates each backend's switches and name and states where the executable comes from.
|
|
14
|
+
* @evidence contracts/development/implementation.md#principled-implementation Chromium's SwiftShader documentation selects the software backend through ANGLE with exactly these two switches, and Playwright already adds `--enable-unsafe-swiftshader`; `--use-angle=default` lets ANGLE pick the platform's GPU backend, such as Direct3D 11 on Windows, and the blocklist switch keeps a headless browser from refusing it.
|
|
15
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One table lookup and one environment read.
|
|
16
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No backend is chosen from the machine; the caller states it, and the record names what the browser reported.
|
|
17
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Constant.
|
|
18
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A pure mapping.
|
|
19
|
+
* @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Returns fresh arrays and keeps nothing.
|
|
20
|
+
*/
|
|
21
|
+
export function planAutoMovieChromiumLaunch(
|
|
22
|
+
backend: AutoMovieCaptureBackend,
|
|
23
|
+
env: Readonly<Record<string, string | undefined>>,
|
|
24
|
+
): {
|
|
25
|
+
/** Switches passed to Chromium. */
|
|
26
|
+
args: string[];
|
|
27
|
+
|
|
28
|
+
/** Executable to launch, or absent for Playwright's own build. */
|
|
29
|
+
executablePath?: string;
|
|
30
|
+
|
|
31
|
+
/** The backend's name as the record states it. */
|
|
32
|
+
name: string;
|
|
33
|
+
} {
|
|
34
|
+
const chrome: string | undefined = env.CHROME_PATH?.trim();
|
|
35
|
+
return {
|
|
36
|
+
args:
|
|
37
|
+
backend === "software"
|
|
38
|
+
? ["--use-gl=angle", "--use-angle=swiftshader"]
|
|
39
|
+
: ["--use-gl=angle", "--use-angle=default", "--ignore-gpu-blocklist"],
|
|
40
|
+
...(chrome === undefined || chrome === ""
|
|
41
|
+
? {}
|
|
42
|
+
: { executablePath: chrome }),
|
|
43
|
+
name: backend === "software" ? "swiftshader" : "gpu",
|
|
44
|
+
};
|
|
45
|
+
}
|