automovie 0.1.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 +25 -13
- 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 +26 -5
- 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
|
@@ -0,0 +1,127 @@
|
|
|
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 type { AutoMovieCaptureHost } from "./AutoMovieCaptureHost";
|
|
6
|
+
import { readAutoMovieRevision } from "./readAutoMovieRevision";
|
|
7
|
+
import { runAutoMovieFfmpeg } from "./runAutoMovieFfmpeg";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The delivery encoding of a drawn subject: H.264 in yuv420p at CRF 18, without tone mapping, as the production's render used; the frame format is the subject's own clock and raster.
|
|
11
|
+
*/
|
|
12
|
+
const SPEC: Parameters<typeof Render.renderAutoMovieDrawnVideo>[0]["spec"] = {
|
|
13
|
+
target: "production",
|
|
14
|
+
toneMapping: "none",
|
|
15
|
+
codec: "h264",
|
|
16
|
+
pixelFormat: "yuv420p",
|
|
17
|
+
crf: 18,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Render one subject of a host's draw page into `<out>/film.mp4`, with `render-report.json` beside it.
|
|
22
|
+
*
|
|
23
|
+
* The subject is opened through the host's draw session, every frame of its clock is drawn by `renderAutoMovieDrawnVideo` into a scratch folder under `<root>/.cache/render/`, and FFmpeg encodes them into a partial file that is renamed to `film.mp4` only once it is complete, so a failed render leaves no file that looks finished. The report names the subject, the source revision, the backend, the encoder's arguments and every frame's second and pixel hash. The scratch folder is deleted and the session closed on every outcome.
|
|
24
|
+
*
|
|
25
|
+
* @evidence contracts/development/common.md#meaningful-documentation States what is written where, how a failure leaves the output, what the report holds, and what is released.
|
|
26
|
+
* @evidence contracts/development/implementation.md#principled-implementation Drawing and encoding are the render package's; this host supplies the session, files and FFmpeg, so a delivered frame is drawn by the same function as a capture's still.
|
|
27
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Open, draw and encode, rename, report, release.
|
|
28
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The output is replaced only by a complete encode; no frame is reused from an earlier render.
|
|
29
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms One draw and one PNG file per frame, then one FFmpeg run.
|
|
30
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Each render draws afresh.
|
|
31
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The frame files live in the scratch folder until the encode ends, then are deleted with it; the session's page is closed on every outcome.
|
|
32
|
+
*/
|
|
33
|
+
export async function renderAutoMovieVideo(props: {
|
|
34
|
+
/** The opened draw host. */
|
|
35
|
+
host: AutoMovieCaptureHost;
|
|
36
|
+
|
|
37
|
+
/** The production's root folder. */
|
|
38
|
+
root: string;
|
|
39
|
+
|
|
40
|
+
/** The subject's name, or null for the page's only subject. */
|
|
41
|
+
subject: string | null;
|
|
42
|
+
|
|
43
|
+
/** Data the subject module reads, as JSON, or null. */
|
|
44
|
+
props: unknown;
|
|
45
|
+
|
|
46
|
+
/** Output folder, relative to the root or absolute; absent, `media/automovie/<subject>/videos`. */
|
|
47
|
+
out?: string;
|
|
48
|
+
|
|
49
|
+
/** FFmpeg executable. */
|
|
50
|
+
ffmpeg: string;
|
|
51
|
+
}): Promise<{
|
|
52
|
+
/** The video written. */
|
|
53
|
+
video: string;
|
|
54
|
+
|
|
55
|
+
/** The report written beside it. */
|
|
56
|
+
report: string;
|
|
57
|
+
|
|
58
|
+
/** Frames drawn. */
|
|
59
|
+
frames: number;
|
|
60
|
+
}> {
|
|
61
|
+
const session: Render.AutoMovieDrawSession = await props.host.session({
|
|
62
|
+
subject: props.subject,
|
|
63
|
+
props: props.props,
|
|
64
|
+
});
|
|
65
|
+
const name: string = session.subject.name;
|
|
66
|
+
const out: string = path.resolve(
|
|
67
|
+
props.root,
|
|
68
|
+
props.out ?? path.join("media", "automovie", name, "videos"),
|
|
69
|
+
);
|
|
70
|
+
const scratch: string = path.join(
|
|
71
|
+
props.root,
|
|
72
|
+
".cache",
|
|
73
|
+
"render",
|
|
74
|
+
`${name}-${process.pid}-${Date.now()}`,
|
|
75
|
+
);
|
|
76
|
+
const partial: string = path.join(out, `.film-${process.pid}.mp4`);
|
|
77
|
+
try {
|
|
78
|
+
await fs.mkdir(scratch, { recursive: true });
|
|
79
|
+
await fs.mkdir(out, { recursive: true });
|
|
80
|
+
const result: Awaited<ReturnType<typeof Render.renderAutoMovieDrawnVideo>> =
|
|
81
|
+
await props.host.render.renderAutoMovieDrawnVideo({
|
|
82
|
+
session,
|
|
83
|
+
spec: SPEC,
|
|
84
|
+
frameDir: scratch.split(path.sep).join("/"),
|
|
85
|
+
outputPath: partial,
|
|
86
|
+
audio: null,
|
|
87
|
+
write: (file: string, data: Uint8Array): Promise<void> =>
|
|
88
|
+
fs.writeFile(file, data),
|
|
89
|
+
encode: async (args: readonly string[]): Promise<void> => {
|
|
90
|
+
await runAutoMovieFfmpeg(props.ffmpeg, args);
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
const video: string = path.join(out, "film.mp4");
|
|
94
|
+
await fs.rename(partial, video);
|
|
95
|
+
const report: string = path.join(out, "render-report.json");
|
|
96
|
+
await fs.writeFile(
|
|
97
|
+
report,
|
|
98
|
+
JSON.stringify(
|
|
99
|
+
{
|
|
100
|
+
subject: name,
|
|
101
|
+
revision: readAutoMovieRevision(props.root),
|
|
102
|
+
backend: session.backend,
|
|
103
|
+
video: "film.mp4",
|
|
104
|
+
args: result.args,
|
|
105
|
+
frames: result.frames.map(
|
|
106
|
+
(frame: {
|
|
107
|
+
index: number;
|
|
108
|
+
seconds: number;
|
|
109
|
+
hash: string;
|
|
110
|
+
}): { index: number; seconds: number; hash: string } => ({
|
|
111
|
+
index: frame.index,
|
|
112
|
+
seconds: frame.seconds,
|
|
113
|
+
hash: frame.hash,
|
|
114
|
+
}),
|
|
115
|
+
),
|
|
116
|
+
},
|
|
117
|
+
null,
|
|
118
|
+
2,
|
|
119
|
+
),
|
|
120
|
+
);
|
|
121
|
+
return { video, report, frames: result.frames.length };
|
|
122
|
+
} finally {
|
|
123
|
+
await fs.rm(partial, { force: true });
|
|
124
|
+
await fs.rm(scratch, { recursive: true, force: true });
|
|
125
|
+
await session.close();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find the FFmpeg executable a capture of a video file runs: `FFMPEG_PATH` when the environment sets it to a non-blank path, else the binary of the production's `ffmpeg-static`.
|
|
3
|
+
*
|
|
4
|
+
* It throws naming both `FFMPEG_PATH` and `ffmpeg-static` when neither gives a path, so a capture that plans a video says how to supply one before it touches its folder.
|
|
5
|
+
*
|
|
6
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the order of the two sources and the refusal.
|
|
7
|
+
* @evidence contracts/development/implementation.md#principled-implementation `ffmpeg-static` exports the path of the binary it downloaded, or null on a platform it has none for; the environment variable wins so a machine's own build can be used.
|
|
8
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Read the variable, else load the package, else refuse.
|
|
9
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No `ffmpeg` on the search path is guessed, because a capture records the binary it ran.
|
|
10
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms One module load at most.
|
|
11
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Resolved once per capture.
|
|
12
|
+
* @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Returns a path and keeps nothing.
|
|
13
|
+
*/
|
|
14
|
+
export function resolveAutoMovieFfmpeg(props: {
|
|
15
|
+
/** The environment, read for `FFMPEG_PATH`. */
|
|
16
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
17
|
+
|
|
18
|
+
/** Loads a package from the production, throwing when it is not installed. */
|
|
19
|
+
load: (id: string) => unknown;
|
|
20
|
+
}): string {
|
|
21
|
+
const given: string | undefined = props.env.FFMPEG_PATH?.trim();
|
|
22
|
+
if (given !== undefined && given !== "") return given;
|
|
23
|
+
let binary: unknown = null;
|
|
24
|
+
try {
|
|
25
|
+
binary = props.load("ffmpeg-static");
|
|
26
|
+
} catch {
|
|
27
|
+
binary = null;
|
|
28
|
+
}
|
|
29
|
+
if (typeof binary === "string" && binary !== "") return binary;
|
|
30
|
+
throw new Error(
|
|
31
|
+
"A video capture needs FFmpeg: set FFMPEG_PATH to an ffmpeg executable, or install ffmpeg-static in the production",
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { loadAutoMovieProductionModule } from "./loadAutoMovieProductionModule";
|
|
6
|
+
import { readAutoMovieReviewOptions } from "./readAutoMovieReviewOptions";
|
|
7
|
+
import { recordAutoMoviePlayback } from "./recordAutoMoviePlayback";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Run `automovie review` in a production: record real-time playback of its running inspector page for a person to watch, and resolve to the exit status.
|
|
11
|
+
*
|
|
12
|
+
* Options are read by `readAutoMovieCaptureArguments` and admitted by `readAutoMovieReviewOptions`. The recording is `recordAutoMoviePlayback` with the production's `playwright-core`; it and `playback.json`, holding the time readings and the page's script errors, go into `--out` or `media/automovie/review`. It prints the video and the number of errors, and resolves to 1 when the page reported a script error, since a playback that errors is not one to watch, and 0 otherwise.
|
|
13
|
+
*
|
|
14
|
+
* @evidence contracts/development/common.md#meaningful-documentation States how options are read, what records, what is written where, what is printed and the status with its reason.
|
|
15
|
+
* @evidence contracts/development/implementation.md#principled-implementation The recording's rules are `recordAutoMoviePlayback`'s; the command supplies the production's Playwright and writes the result.
|
|
16
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Read, record, write, report.
|
|
17
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts An unknown option is refused; a page error is reported in the status, not hidden.
|
|
18
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms One recording.
|
|
19
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work One review per command.
|
|
20
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The browser is the recording's and closed by it.
|
|
21
|
+
*/
|
|
22
|
+
export async function reviewAutoMovie(props: {
|
|
23
|
+
/** The tokens after `review`. */
|
|
24
|
+
args: readonly string[];
|
|
25
|
+
|
|
26
|
+
/** The production's root folder, the working directory. */
|
|
27
|
+
root: string;
|
|
28
|
+
|
|
29
|
+
/** The environment, read for `CHROME_PATH`. */
|
|
30
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
31
|
+
}): Promise<number> {
|
|
32
|
+
const { root } = props;
|
|
33
|
+
const render: typeof Render = loadAutoMovieProductionModule(
|
|
34
|
+
root,
|
|
35
|
+
"@automovie/render",
|
|
36
|
+
) as typeof Render;
|
|
37
|
+
const options: ReturnType<typeof readAutoMovieReviewOptions> =
|
|
38
|
+
readAutoMovieReviewOptions(
|
|
39
|
+
render.readAutoMovieCaptureArguments(props.args),
|
|
40
|
+
);
|
|
41
|
+
const out: string = path.resolve(
|
|
42
|
+
root,
|
|
43
|
+
options.out ?? path.join("media", "automovie", "review"),
|
|
44
|
+
);
|
|
45
|
+
const recorded: Awaited<ReturnType<typeof recordAutoMoviePlayback>> =
|
|
46
|
+
await recordAutoMoviePlayback({
|
|
47
|
+
chromium: (
|
|
48
|
+
loadAutoMovieProductionModule(root, "playwright-core") as {
|
|
49
|
+
chromium: unknown;
|
|
50
|
+
}
|
|
51
|
+
).chromium,
|
|
52
|
+
url: options.url,
|
|
53
|
+
seconds: options.seconds,
|
|
54
|
+
out,
|
|
55
|
+
env: props.env,
|
|
56
|
+
});
|
|
57
|
+
await fs.writeFile(
|
|
58
|
+
path.join(out, "playback.json"),
|
|
59
|
+
JSON.stringify(recorded, null, 2),
|
|
60
|
+
);
|
|
61
|
+
process.stdout.write(
|
|
62
|
+
`review: ${recorded.video}\n${recorded.errors.length} page errors\n`,
|
|
63
|
+
);
|
|
64
|
+
return recorded.errors.length === 0 ? 0 : 1;
|
|
65
|
+
}
|
package/src/run.ts
CHANGED
|
@@ -1,48 +1,73 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
ScaffoldPublicationError,
|
|
5
|
-
publishFiles,
|
|
6
|
-
renderScaffold,
|
|
7
|
-
renderWorkspaceProductionScaffold,
|
|
8
|
-
renderWorkspaceScaffold,
|
|
9
|
-
syncScaffold,
|
|
2
|
+
type IAutoMovieScaffoldProps,
|
|
3
|
+
createAutoMovieScaffold,
|
|
10
4
|
} from "@automovie/template";
|
|
11
5
|
import * as fs from "node:fs";
|
|
12
6
|
import * as path from "node:path";
|
|
13
7
|
|
|
14
8
|
import type { AutoMovieCommand } from "./AutoMovieCommand";
|
|
15
|
-
import
|
|
9
|
+
import { captureAutoMovie } from "./captureAutoMovie";
|
|
16
10
|
import { deriveAutoMovieProjectName } from "./deriveAutoMovieProjectName";
|
|
11
|
+
import { inspectAutoMovie } from "./inspectAutoMovie";
|
|
17
12
|
import { promptAutoMovieProjectName } from "./promptAutoMovieProjectName";
|
|
18
13
|
import { readAutoMovieCommandArguments } from "./readAutoMovieCommandArguments";
|
|
14
|
+
import { renderAutoMovie } from "./renderAutoMovie";
|
|
19
15
|
import { renderAutoMovieScaffoldNextSteps } from "./renderAutoMovieScaffoldNextSteps";
|
|
20
|
-
import {
|
|
16
|
+
import { reviewAutoMovie } from "./reviewAutoMovie";
|
|
21
17
|
import { selectAutoMovieProjectName } from "./selectAutoMovieProjectName";
|
|
22
18
|
|
|
23
|
-
const USAGE: string = `automovie: scaffold an automovie project
|
|
19
|
+
const USAGE: string = `automovie: scaffold an automovie project, and capture, render and review it
|
|
24
20
|
|
|
25
21
|
Usage:
|
|
26
22
|
npx automovie create <directory> [--workspace] [--name <name>] [--force]
|
|
27
23
|
pnpm automovie add <shorts|series>/<name> [--name <name>] [--force]
|
|
28
|
-
|
|
24
|
+
automovie capture --module <file> [--props <json>] [--backend software|gpu] [--out <dir>] [<request>]
|
|
25
|
+
automovie capture --file <video> [--out <dir>] [<request>]
|
|
26
|
+
automovie inspect --module <file> [--props <json>] [--port <n>] [<request>]
|
|
27
|
+
automovie render --module <file> [--subject <name>] [--props <json>] [--out <dir>] [--backend software|gpu]
|
|
28
|
+
automovie review --url <inspector address> --seconds <s> [--out <dir>]
|
|
29
29
|
|
|
30
30
|
Commands:
|
|
31
31
|
create A single production, or with --workspace a pnpm workspace
|
|
32
32
|
root for movies/shorts, movies/series and packages.
|
|
33
33
|
add From a workspace root, a production at movies/<family>/<name>:
|
|
34
34
|
shorts run brief -> screenplay, series the long route.
|
|
35
|
-
|
|
36
|
-
or a
|
|
35
|
+
capture In a production, draw the subjects a module offers in headless
|
|
36
|
+
Chromium, or take a video file's own frames, into stills,
|
|
37
|
+
contact sheets and record.json. Needs @automovie/render, vite
|
|
38
|
+
and playwright-core in the production, and FFmpeg for --file.
|
|
39
|
+
inspect In a production or package, serve the inspector page over the
|
|
40
|
+
subjects a module offers and print its address, whose query
|
|
41
|
+
is the request. Needs @automovie/render, @automovie/viewer,
|
|
42
|
+
react, react-dom and vite there; Ctrl+C stops it.
|
|
43
|
+
render In a production, draw every frame of one subject through the
|
|
44
|
+
draw page in headless Chromium and encode film.mp4 with
|
|
45
|
+
render-report.json. Needs what capture needs, and FFmpeg.
|
|
46
|
+
review Record real-time playback of the running inspector page as a
|
|
47
|
+
video with playback.json. Needs playwright-core and
|
|
48
|
+
Playwright's ffmpeg (npx playwright-core install ffmpeg).
|
|
37
49
|
|
|
38
50
|
Options:
|
|
39
51
|
--workspace Create a pnpm workspace root instead of a single production.
|
|
40
52
|
--name Package name; create asks for one when the target is the
|
|
41
53
|
current directory, and add defaults to the directory name.
|
|
42
54
|
--force Install into a non-empty directory, replacing same-path files.
|
|
43
|
-
--
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
--module capture, inspect, render: the module whose subjects(props)
|
|
56
|
+
the page draws.
|
|
57
|
+
--port inspect: the port to serve on; default a free port.
|
|
58
|
+
--props capture, inspect, render: a JSON file the module's subjects(props) is
|
|
59
|
+
called with; default null.
|
|
60
|
+
--file capture: an encoded video file instead of a subject.
|
|
61
|
+
--backend capture, render: software (SwiftShader, the default) or gpu.
|
|
62
|
+
--out capture: the folder; default media/capture/<subject>.
|
|
63
|
+
render: default media/automovie/<subject>/videos.
|
|
64
|
+
review: default media/automovie/review.
|
|
65
|
+
--url review: the running inspector page's address.
|
|
66
|
+
--seconds review: wall-clock seconds of playback recorded.
|
|
67
|
+
<request> capture, inspect: --subject, --at, --from, --to, --rate, --events,
|
|
68
|
+
--views, --passes, --marks, --label, --round, --compare and
|
|
69
|
+
every other key of the capture request grammar; render takes
|
|
70
|
+
--subject alone, the subject rendered, default the only one.
|
|
46
71
|
-h, --help Show this help as a standalone request.
|
|
47
72
|
-v, --version Print the version as a standalone request.
|
|
48
73
|
`;
|
|
@@ -51,24 +76,27 @@ Options:
|
|
|
51
76
|
* The `automovie` CLI entry. `argv` is the full process vector; its first two positions (executable and script) are skipped.
|
|
52
77
|
*
|
|
53
78
|
* - `help` and `version` write to stdout; the version is read from this package's `package.json`.
|
|
54
|
-
* - `create`
|
|
55
|
-
* - `add` requires `pnpm-workspace.yaml` in the working directory, which it takes as the workspace root without searching elsewhere, and
|
|
56
|
-
* - `
|
|
79
|
+
* - `create` writes a single production, or with `--workspace` a workspace root, into the directory resolved against the working directory. The name is the typed `--name`, else derived from the target's basename; for the working directory itself the terminal is asked, offering `automovie-examples`, which is used without asking when no terminal is attached.
|
|
80
|
+
* - `add` requires `pnpm-workspace.yaml` in the working directory, which it takes as the workspace root without searching elsewhere, and writes a workspace production into `movies/<family>/<directory>`, named by `--name`, else by the npm-safe name derived from the directory segment as `create` derives one.
|
|
81
|
+
* - `capture` runs `captureAutoMovie` in the working directory as the production, resolving to its status: 1 when a cell was not drawn.
|
|
82
|
+
* - `inspect` runs `inspectAutoMovie` in the working directory, serving the inspector page until the process is interrupted.
|
|
83
|
+
* - `render` runs `renderAutoMovie` in the working directory as the production, resolving to 0 once the video is written.
|
|
84
|
+
* - `review` runs `reviewAutoMovie`, resolving to 1 when the recorded page reported a script error.
|
|
57
85
|
*
|
|
58
|
-
* `create` and `add` refuse a non-empty target without `--force
|
|
86
|
+
* `create` and `add` take their files from `createAutoMovieScaffold` and refuse a non-empty target without `--force`, which writes over same-path files and keeps every other file. On success they list the written files relative to the target, then the next steps. A failed write stops there and leaves the files already written.
|
|
59
87
|
*
|
|
60
88
|
* Resolves to the process exit code, 0 after queuing the requested stdout text or 1 after queuing a caught error's message and distinct `cause` objects' messages without stacks. A repeated cause ends the chain. Reading or stringifying an unusual thrown value, or writing stderr, can itself throw. The executable assigns the result to `process.exitCode` so queued output can drain.
|
|
61
89
|
*
|
|
62
90
|
* @param argv The full process vector.
|
|
63
91
|
* @returns The exit code.
|
|
64
92
|
*
|
|
65
|
-
* @evidence contracts/development/implementation.md#principled-implementation Parsing finishes before
|
|
66
|
-
* @evidence contracts/development/implementation.md#clear-and-simple-structure This dispatcher delegates admission, name choice, the prompt and closing text to CLI owners and
|
|
67
|
-
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts `add` checks only the working directory for `pnpm-workspace.yaml` and never searches ancestors
|
|
68
|
-
* @evidence contracts/development/common.md#meaningful-documentation The comment gives argv ownership, every command's effect, name and target choice, retained file
|
|
69
|
-
* @evidence contracts/development/implementation.md#efficient-algorithms For n files,
|
|
70
|
-
* @
|
|
71
|
-
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources
|
|
93
|
+
* @evidence contracts/development/implementation.md#principled-implementation Parsing finishes before the scaffold is created, the whole file map exists before the first write, and path.resolve binds every target to the current working directory. describeError follows distinct cause values with a set to terminate cycles, but assumes their message access and string conversion do not throw.
|
|
94
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure This dispatcher delegates admission, name choice, the prompt and closing text to CLI owners and the file map to the template package, keeping only the write. Only bin.ts invokes it at module load, so importing run does not execute a request.
|
|
95
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts `add` checks only the working directory for `pnpm-workspace.yaml` and never searches ancestors. The catch reports failures without stacks and never retries a write or rolls back files.
|
|
96
|
+
* @evidence contracts/development/common.md#meaningful-documentation The comment gives argv ownership, every command's effect, name and target choice, retained file effects, and the returned status.
|
|
97
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms For n files, creation reads the scaffold once and each file is written once with its directory ensured; listing scans the written paths once. Failure formatting additionally walks the distinct cause chain.
|
|
98
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Every command takes fresh filesystem observations and reads the installed scaffold anew.
|
|
99
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The file map and listing text scale with scaffold size; the cause set scales with chain length without a fixed cap. The prompt closes its terminal interface before returning. This dispatcher owns no descriptor; queued stdout and stderr bytes belong to the process streams.
|
|
72
100
|
*/
|
|
73
101
|
export async function run(argv: readonly string[]): Promise<number> {
|
|
74
102
|
try {
|
|
@@ -83,80 +111,59 @@ export async function run(argv: readonly string[]): Promise<number> {
|
|
|
83
111
|
process.stdout.write(`${packageVersion()}\n`);
|
|
84
112
|
return 0;
|
|
85
113
|
}
|
|
86
|
-
if (command.command === "
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
114
|
+
if (command.command === "capture")
|
|
115
|
+
return await captureAutoMovie({
|
|
116
|
+
args: command.args,
|
|
117
|
+
root: process.cwd(),
|
|
118
|
+
env: process.env,
|
|
119
|
+
});
|
|
120
|
+
if (command.command === "inspect")
|
|
121
|
+
return await inspectAutoMovie({
|
|
122
|
+
args: command.args,
|
|
123
|
+
root: process.cwd(),
|
|
124
|
+
});
|
|
125
|
+
if (command.command === "render")
|
|
126
|
+
return await renderAutoMovie({
|
|
127
|
+
args: command.args,
|
|
128
|
+
root: process.cwd(),
|
|
129
|
+
env: process.env,
|
|
130
|
+
});
|
|
131
|
+
if (command.command === "review")
|
|
132
|
+
return await reviewAutoMovie({
|
|
133
|
+
args: command.args,
|
|
134
|
+
root: process.cwd(),
|
|
135
|
+
env: process.env,
|
|
92
136
|
});
|
|
93
|
-
process.stdout.write(
|
|
94
|
-
`Scaffold sync ${result.status}: ${targetDir}\n` +
|
|
95
|
-
[
|
|
96
|
-
...Object.keys(result.plan.files).map(
|
|
97
|
-
(file: string): string => ` update ${file}`,
|
|
98
|
-
),
|
|
99
|
-
...result.plan.conflicts.map(
|
|
100
|
-
(file: string): string => ` conflict ${file}`,
|
|
101
|
-
),
|
|
102
|
-
...result.plan.retired.map(
|
|
103
|
-
(file: string): string =>
|
|
104
|
-
` retained retired instruction ${file}`,
|
|
105
|
-
),
|
|
106
|
-
].join("\n") +
|
|
107
|
-
"\n",
|
|
108
|
-
);
|
|
109
|
-
if (result.receipt !== undefined && result.receipt.status !== "completed")
|
|
110
|
-
throw new ScaffoldPublicationError(result.receipt);
|
|
111
|
-
return result.status === "conflicted" ||
|
|
112
|
-
(command.check && Object.keys(result.plan.files).length > 0)
|
|
113
|
-
? 1
|
|
114
|
-
: 0;
|
|
115
|
-
}
|
|
116
137
|
if (command.command === "add") {
|
|
117
138
|
const root: string = process.cwd();
|
|
118
139
|
if (!fs.existsSync(path.join(root, "pnpm-workspace.yaml")))
|
|
119
140
|
throw new Error(
|
|
120
141
|
`add runs at an AutoMovie workspace root, and ${root} has no pnpm-workspace.yaml; create one with automovie create <directory> --workspace.`,
|
|
121
142
|
);
|
|
122
|
-
|
|
123
|
-
root,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
command.directory,
|
|
127
|
-
);
|
|
128
|
-
publish(
|
|
129
|
-
targetDir,
|
|
130
|
-
renderWorkspaceProductionScaffold({
|
|
143
|
+
write(
|
|
144
|
+
path.join(root, "movies", command.family, command.directory),
|
|
145
|
+
{
|
|
146
|
+
kind: "workspace-production",
|
|
131
147
|
name: command.name ?? deriveAutoMovieProjectName(command.directory),
|
|
132
|
-
}
|
|
148
|
+
},
|
|
133
149
|
command.force,
|
|
134
|
-
"workspace-production",
|
|
135
150
|
);
|
|
136
151
|
return 0;
|
|
137
152
|
}
|
|
138
153
|
|
|
139
154
|
// Create: a typed or derived name, else the terminal's answer for the working directory itself.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
: renderScaffold({ name }),
|
|
155
|
+
write(
|
|
156
|
+
path.resolve(process.cwd(), command.directory),
|
|
157
|
+
{
|
|
158
|
+
kind: command.workspace ? "workspace" : "production",
|
|
159
|
+
name:
|
|
160
|
+
selectAutoMovieProjectName({
|
|
161
|
+
directory: command.directory,
|
|
162
|
+
cwd: process.cwd(),
|
|
163
|
+
...(command.name === undefined ? {} : { name: command.name }),
|
|
164
|
+
}) ?? (await promptAutoMovieProjectName()),
|
|
165
|
+
},
|
|
152
166
|
command.force,
|
|
153
|
-
command.workspace ? "workspace" : "production",
|
|
154
|
-
selectAutoMoviePackageManager({
|
|
155
|
-
directory: targetDir,
|
|
156
|
-
...(process.env.npm_config_user_agent === undefined
|
|
157
|
-
? {}
|
|
158
|
-
: { userAgent: process.env.npm_config_user_agent }),
|
|
159
|
-
}),
|
|
160
167
|
);
|
|
161
168
|
return 0;
|
|
162
169
|
} catch (error) {
|
|
@@ -166,29 +173,33 @@ export async function run(argv: readonly string[]): Promise<number> {
|
|
|
166
173
|
}
|
|
167
174
|
|
|
168
175
|
/**
|
|
169
|
-
*
|
|
176
|
+
* Write one created installation into `directory`, then list the written files and the next steps. A non-empty directory is refused unless `force` is set, which writes over same-path files and keeps every other file.
|
|
170
177
|
*/
|
|
171
|
-
function
|
|
172
|
-
|
|
173
|
-
|
|
178
|
+
function write(
|
|
179
|
+
directory: string,
|
|
180
|
+
props: IAutoMovieScaffoldProps,
|
|
174
181
|
force: boolean,
|
|
175
|
-
kind: "production" | "workspace" | "workspace-production",
|
|
176
|
-
packageManager?: IAutoMoviePackageManager,
|
|
177
182
|
): void {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
const files: Record<string, string> = createAutoMovieScaffold(props);
|
|
184
|
+
if (
|
|
185
|
+
force === false &&
|
|
186
|
+
fs.existsSync(directory) &&
|
|
187
|
+
fs.readdirSync(directory).length !== 0
|
|
188
|
+
)
|
|
189
|
+
throw new Error(
|
|
190
|
+
`${directory} is not empty; pass --force to write into it, replacing same-path files.`,
|
|
191
|
+
);
|
|
192
|
+
for (const [relative, content] of Object.entries(files)) {
|
|
193
|
+
const file: string = path.join(directory, relative);
|
|
194
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
195
|
+
fs.writeFileSync(file, content, "utf8");
|
|
196
|
+
}
|
|
183
197
|
process.stdout.write(
|
|
184
|
-
`Scaffolded ${
|
|
185
|
-
|
|
186
|
-
.map(
|
|
187
|
-
({ entry }: IScaffoldCompletedPublication): string =>
|
|
188
|
-
` ${entry.relative}`,
|
|
189
|
-
)
|
|
198
|
+
`Scaffolded ${Object.keys(files).length} files into ${directory}\n\n` +
|
|
199
|
+
Object.keys(files)
|
|
200
|
+
.map((relative: string): string => ` ${relative}`)
|
|
190
201
|
.join("\n") +
|
|
191
|
-
renderAutoMovieScaffoldNextSteps(
|
|
202
|
+
renderAutoMovieScaffoldNextSteps(directory, props.kind),
|
|
192
203
|
);
|
|
193
204
|
}
|
|
194
205
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
/** Lines of FFmpeg's error output kept for a failure message. */
|
|
4
|
+
const TAIL: number = 12;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Run FFmpeg once with the given arguments, resolving with its error output when it exits as `accept` allows and rejecting otherwise.
|
|
8
|
+
*
|
|
9
|
+
* FFmpeg writes its log, including a probe of every input, to its error output, so that text is what callers read. By default only exit status 0 is accepted; a probe that names no output exits 1 by design and accepts it. A rejection names the binary, the exit status and the last lines of the log.
|
|
10
|
+
*
|
|
11
|
+
* @evidence contracts/development/common.md#meaningful-documentation States what is resolved, the acceptance rule and its default, and what a rejection names.
|
|
12
|
+
* @evidence contracts/development/implementation.md#principled-implementation `child_process.spawn` without a shell passes each argument as it is, so a path with spaces or quotes needs no escaping.
|
|
13
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Spawn, collect the error output, settle on exit.
|
|
14
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts A failed run is never retried, and a failure to start rejects with its cause.
|
|
15
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Linear in the log FFmpeg writes.
|
|
16
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Each run is its own process.
|
|
17
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The child process ends before the promise settles; its log is held until then.
|
|
18
|
+
*/
|
|
19
|
+
export function runAutoMovieFfmpeg(
|
|
20
|
+
binary: string,
|
|
21
|
+
args: readonly string[],
|
|
22
|
+
accept: (code: number | null) => boolean = (code: number | null): boolean =>
|
|
23
|
+
code === 0,
|
|
24
|
+
): Promise<string> {
|
|
25
|
+
return new Promise<string>(
|
|
26
|
+
(resolve: (log: string) => void, reject: (error: Error) => void): void => {
|
|
27
|
+
const child: ReturnType<typeof spawn> = spawn(binary, [...args], {
|
|
28
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
29
|
+
windowsHide: true,
|
|
30
|
+
});
|
|
31
|
+
let log: string = "";
|
|
32
|
+
child.stderr!.setEncoding("utf8");
|
|
33
|
+
child.stderr!.on("data", (chunk: string): void => {
|
|
34
|
+
log += chunk;
|
|
35
|
+
});
|
|
36
|
+
child.on("error", (error: Error): void =>
|
|
37
|
+
reject(new Error(`FFmpeg ${binary} did not start`, { cause: error })),
|
|
38
|
+
);
|
|
39
|
+
child.on("close", (code: number | null): void => {
|
|
40
|
+
if (accept(code)) resolve(log);
|
|
41
|
+
else
|
|
42
|
+
reject(
|
|
43
|
+
new Error(
|
|
44
|
+
`FFmpeg ${binary} exited with ${code}:\n${log.trimEnd().split(/\r?\n/u).slice(-TAIL).join("\n")}`,
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
}
|