obsidian-plugin-dev-kit 0.0.0-stage → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +223 -2
- package/bin/opdk.js +34 -0
- package/dist/build/args.d.ts +10 -0
- package/dist/build/args.js +45 -0
- package/dist/build/bundle-check.d.ts +17 -0
- package/dist/build/bundle-check.js +42 -0
- package/dist/build/bundle-file.d.ts +4 -0
- package/dist/build/bundle-file.js +29 -0
- package/dist/build/commands.d.ts +5 -0
- package/dist/build/commands.js +109 -0
- package/dist/build/config.d.ts +3 -0
- package/dist/build/config.js +103 -0
- package/dist/build/css-imports.d.ts +23 -0
- package/dist/build/css-imports.js +50 -0
- package/dist/build/css-step.d.ts +10 -0
- package/dist/build/css-step.js +27 -0
- package/dist/build/css.d.ts +24 -0
- package/dist/build/css.js +47 -0
- package/dist/build/options.d.ts +55 -0
- package/dist/build/options.js +70 -0
- package/dist/build/release.d.ts +5 -0
- package/dist/build/release.js +34 -0
- package/dist/build/report.d.ts +7 -0
- package/dist/build/report.js +16 -0
- package/dist/build/vault.d.ts +26 -0
- package/dist/build/vault.js +290 -0
- package/dist/build-info.json +1 -0
- package/dist/cli/argv.d.ts +14 -0
- package/dist/cli/argv.js +18 -0
- package/dist/cli/commands.d.ts +3 -0
- package/dist/cli/commands.js +7 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +23 -0
- package/dist/cli/process-reporter.d.ts +5 -0
- package/dist/cli/process-reporter.js +15 -0
- package/dist/cli/registry.d.ts +4 -0
- package/dist/cli/registry.js +15 -0
- package/dist/cli/reporter.d.ts +53 -0
- package/dist/cli/reporter.js +100 -0
- package/dist/cli/run.d.ts +9 -0
- package/dist/cli/run.js +61 -0
- package/dist/cli/types.d.ts +27 -0
- package/dist/cli/types.js +1 -0
- package/dist/cli/version.d.ts +13 -0
- package/dist/cli/version.js +61 -0
- package/dist/config/define-config.d.ts +3 -0
- package/dist/config/define-config.js +4 -0
- package/dist/config/load-config.d.ts +6 -0
- package/dist/config/load-config.js +70 -0
- package/dist/config/manifest.d.ts +3 -0
- package/dist/config/manifest.js +72 -0
- package/dist/config/types.d.ts +146 -0
- package/dist/config/types.js +23 -0
- package/dist/demo/args.d.ts +4 -0
- package/dist/demo/args.js +13 -0
- package/dist/demo/checks.d.ts +56 -0
- package/dist/demo/checks.js +124 -0
- package/dist/demo/commands.d.ts +3 -0
- package/dist/demo/commands.js +65 -0
- package/dist/demo/config.d.ts +57 -0
- package/dist/demo/config.js +337 -0
- package/dist/demo/ffmpeg-run.d.ts +18 -0
- package/dist/demo/ffmpeg-run.js +59 -0
- package/dist/demo/ffmpeg.d.ts +63 -0
- package/dist/demo/ffmpeg.js +111 -0
- package/dist/demo/films.d.ts +46 -0
- package/dist/demo/films.js +134 -0
- package/dist/demo/phone-layout.d.ts +38 -0
- package/dist/demo/phone-layout.js +98 -0
- package/dist/demo/phone-render.d.ts +28 -0
- package/dist/demo/phone-render.js +124 -0
- package/dist/demo/published.d.ts +16 -0
- package/dist/demo/published.js +72 -0
- package/dist/demo/run.d.ts +31 -0
- package/dist/demo/run.js +397 -0
- package/dist/demo/stills.d.ts +21 -0
- package/dist/demo/stills.js +62 -0
- package/dist/e2e/artifacts.d.ts +27 -0
- package/dist/e2e/artifacts.js +90 -0
- package/dist/e2e/cleanup.d.ts +54 -0
- package/dist/e2e/cleanup.js +109 -0
- package/dist/e2e/config.d.ts +9 -0
- package/dist/e2e/config.js +42 -0
- package/dist/e2e/create-test.d.ts +37 -0
- package/dist/e2e/create-test.js +109 -0
- package/dist/e2e/demo/clip.d.ts +21 -0
- package/dist/e2e/demo/clip.js +44 -0
- package/dist/e2e/demo/create-demo.d.ts +42 -0
- package/dist/e2e/demo/create-demo.js +439 -0
- package/dist/e2e/demo/manifest.d.ts +76 -0
- package/dist/e2e/demo/manifest.js +168 -0
- package/dist/e2e/demo/names.d.ts +18 -0
- package/dist/e2e/demo/names.js +44 -0
- package/dist/e2e/demo/options.d.ts +22 -0
- package/dist/e2e/demo/options.js +59 -0
- package/dist/e2e/demo/ownership.d.ts +27 -0
- package/dist/e2e/demo/ownership.js +65 -0
- package/dist/e2e/demo/page-scripts.d.ts +82 -0
- package/dist/e2e/demo/page-scripts.js +250 -0
- package/dist/e2e/demo/png.d.ts +8 -0
- package/dist/e2e/demo/png.js +23 -0
- package/dist/e2e/demo/presets.d.ts +43 -0
- package/dist/e2e/demo/presets.js +20 -0
- package/dist/e2e/demo/privacy.d.ts +18 -0
- package/dist/e2e/demo/privacy.js +30 -0
- package/dist/e2e/demo/still-options.d.ts +22 -0
- package/dist/e2e/demo/still-options.js +68 -0
- package/dist/e2e/demo/types.d.ts +184 -0
- package/dist/e2e/demo/types.js +1 -0
- package/dist/e2e/electron-binary.d.ts +15 -0
- package/dist/e2e/electron-binary.js +30 -0
- package/dist/e2e/fixtures.d.ts +62 -0
- package/dist/e2e/fixtures.js +68 -0
- package/dist/e2e/gate.d.ts +4 -0
- package/dist/e2e/gate.js +8 -0
- package/dist/e2e/global-setup.d.ts +11 -0
- package/dist/e2e/global-setup.js +17 -0
- package/dist/e2e/helpers/commands.d.ts +14 -0
- package/dist/e2e/helpers/commands.js +56 -0
- package/dist/e2e/helpers/create-helpers.d.ts +24 -0
- package/dist/e2e/helpers/create-helpers.js +582 -0
- package/dist/e2e/helpers/device-metrics.d.ts +21 -0
- package/dist/e2e/helpers/device-metrics.js +25 -0
- package/dist/e2e/helpers/ime.d.ts +13 -0
- package/dist/e2e/helpers/ime.js +19 -0
- package/dist/e2e/helpers/layout-page-scripts.d.ts +103 -0
- package/dist/e2e/helpers/layout-page-scripts.js +224 -0
- package/dist/e2e/helpers/layout.d.ts +83 -0
- package/dist/e2e/helpers/layout.js +148 -0
- package/dist/e2e/helpers/mobile.d.ts +31 -0
- package/dist/e2e/helpers/mobile.js +26 -0
- package/dist/e2e/helpers/page-scripts.d.ts +194 -0
- package/dist/e2e/helpers/page-scripts.js +467 -0
- package/dist/e2e/helpers/settings.d.ts +8 -0
- package/dist/e2e/helpers/settings.js +16 -0
- package/dist/e2e/helpers/settle.d.ts +28 -0
- package/dist/e2e/helpers/settle.js +33 -0
- package/dist/e2e/helpers/types.d.ts +193 -0
- package/dist/e2e/helpers/types.js +1 -0
- package/dist/e2e/helpers/view-mode.d.ts +23 -0
- package/dist/e2e/helpers/view-mode.js +35 -0
- package/dist/e2e/index.d.ts +14 -0
- package/dist/e2e/index.js +4 -0
- package/dist/e2e/internals.d.ts +155 -0
- package/dist/e2e/internals.js +8 -0
- package/dist/e2e/obsidian-path.d.ts +17 -0
- package/dist/e2e/obsidian-path.js +31 -0
- package/dist/e2e/options.d.ts +123 -0
- package/dist/e2e/options.js +244 -0
- package/dist/e2e/page-scripts.d.ts +45 -0
- package/dist/e2e/page-scripts.js +53 -0
- package/dist/e2e/peers.d.ts +9 -0
- package/dist/e2e/peers.js +19 -0
- package/dist/e2e/plugins.d.ts +32 -0
- package/dist/e2e/plugins.js +119 -0
- package/dist/e2e/process-tree.d.ts +33 -0
- package/dist/e2e/process-tree.js +133 -0
- package/dist/e2e/readiness.d.ts +23 -0
- package/dist/e2e/readiness.js +63 -0
- package/dist/e2e/seed.d.ts +34 -0
- package/dist/e2e/seed.js +122 -0
- package/dist/e2e/session.d.ts +71 -0
- package/dist/e2e/session.js +266 -0
- package/dist/e2e/vault.d.ts +52 -0
- package/dist/e2e/vault.js +146 -0
- package/dist/e2e/version.d.ts +25 -0
- package/dist/e2e/version.js +40 -0
- package/dist/eslint/index.d.ts +2 -0
- package/dist/eslint/index.js +1 -0
- package/dist/eslint/obsidian-plugin.d.ts +49 -0
- package/dist/eslint/obsidian-plugin.js +115 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/kit/args.d.ts +7 -0
- package/dist/kit/args.js +21 -0
- package/dist/kit/commands.d.ts +3 -0
- package/dist/kit/commands.js +52 -0
- package/dist/kit/files.d.ts +3 -0
- package/dist/kit/files.js +24 -0
- package/dist/kit/pins.d.ts +89 -0
- package/dist/kit/pins.js +178 -0
- package/dist/kit/remote.d.ts +13 -0
- package/dist/kit/remote.js +33 -0
- package/dist/kit/runners.d.ts +11 -0
- package/dist/kit/runners.js +53 -0
- package/dist/kit/terminal-text.d.ts +6 -0
- package/dist/kit/terminal-text.js +20 -0
- package/dist/kit/upgrade.d.ts +26 -0
- package/dist/kit/upgrade.js +162 -0
- package/dist/peers/resolve.d.ts +8 -0
- package/dist/peers/resolve.js +28 -0
- package/dist/peers/versions.d.ts +30 -0
- package/dist/peers/versions.js +32 -0
- package/dist/release/api-check.d.ts +27 -0
- package/dist/release/api-check.js +119 -0
- package/dist/release/args.d.ts +40 -0
- package/dist/release/args.js +120 -0
- package/dist/release/assets.d.ts +21 -0
- package/dist/release/assets.js +35 -0
- package/dist/release/build-check.d.ts +43 -0
- package/dist/release/build-check.js +184 -0
- package/dist/release/build-script.d.ts +12 -0
- package/dist/release/build-script.js +30 -0
- package/dist/release/build-tagged.d.ts +26 -0
- package/dist/release/build-tagged.js +52 -0
- package/dist/release/bump.d.ts +24 -0
- package/dist/release/bump.js +58 -0
- package/dist/release/changelog.d.ts +25 -0
- package/dist/release/changelog.js +148 -0
- package/dist/release/check.d.ts +38 -0
- package/dist/release/check.js +150 -0
- package/dist/release/commands.d.ts +3 -0
- package/dist/release/commands.js +154 -0
- package/dist/release/committed-tree.d.ts +63 -0
- package/dist/release/committed-tree.js +118 -0
- package/dist/release/config.d.ts +3 -0
- package/dist/release/config.js +28 -0
- package/dist/release/gh-access.d.ts +14 -0
- package/dist/release/gh-access.js +45 -0
- package/dist/release/gh.d.ts +10 -0
- package/dist/release/gh.js +33 -0
- package/dist/release/git.d.ts +49 -0
- package/dist/release/git.js +111 -0
- package/dist/release/interrupt.d.ts +30 -0
- package/dist/release/interrupt.js +60 -0
- package/dist/release/json.d.ts +33 -0
- package/dist/release/json.js +81 -0
- package/dist/release/kit-check.d.ts +8 -0
- package/dist/release/kit-check.js +51 -0
- package/dist/release/manifest-rules.d.ts +23 -0
- package/dist/release/manifest-rules.js +255 -0
- package/dist/release/preflight.d.ts +10 -0
- package/dist/release/preflight.js +65 -0
- package/dist/release/problems.d.ts +24 -0
- package/dist/release/problems.js +11 -0
- package/dist/release/project-files.d.ts +14 -0
- package/dist/release/project-files.js +16 -0
- package/dist/release/publish-command.d.ts +21 -0
- package/dist/release/publish-command.js +83 -0
- package/dist/release/publish-git.d.ts +37 -0
- package/dist/release/publish-git.js +108 -0
- package/dist/release/publish-state.d.ts +29 -0
- package/dist/release/publish-state.js +70 -0
- package/dist/release/publish-verify.d.ts +41 -0
- package/dist/release/publish-verify.js +112 -0
- package/dist/release/publish-wait.d.ts +25 -0
- package/dist/release/publish-wait.js +56 -0
- package/dist/release/publish.d.ts +35 -0
- package/dist/release/publish.js +181 -0
- package/dist/release/release-assets.d.ts +39 -0
- package/dist/release/release-assets.js +68 -0
- package/dist/release/release.d.ts +37 -0
- package/dist/release/release.js +179 -0
- package/dist/release/remote.d.ts +12 -0
- package/dist/release/remote.js +15 -0
- package/dist/release/reproducible.d.ts +16 -0
- package/dist/release/reproducible.js +34 -0
- package/dist/release/run-tests.d.ts +5 -0
- package/dist/release/run-tests.js +17 -0
- package/dist/release/semver.d.ts +8 -0
- package/dist/release/semver.js +60 -0
- package/dist/release/version-rules.d.ts +28 -0
- package/dist/release/version-rules.js +63 -0
- package/dist/release/versions-json.d.ts +15 -0
- package/dist/release/versions-json.js +88 -0
- package/dist/release/workflow-run.d.ts +44 -0
- package/dist/release/workflow-run.js +71 -0
- package/dist/scanner/code-checks.d.ts +41 -0
- package/dist/scanner/code-checks.js +82 -0
- package/dist/scanner/commands.d.ts +3 -0
- package/dist/scanner/commands.js +43 -0
- package/dist/scanner/config.d.ts +7 -0
- package/dist/scanner/config.js +25 -0
- package/dist/scanner/css-check.d.ts +26 -0
- package/dist/scanner/css-check.js +63 -0
- package/dist/scanner/eslint-nesting.d.ts +16 -0
- package/dist/scanner/eslint-nesting.js +45 -0
- package/dist/scanner/findings.d.ts +23 -0
- package/dist/scanner/findings.js +21 -0
- package/dist/scanner/git-files.d.ts +16 -0
- package/dist/scanner/git-files.js +73 -0
- package/dist/scanner/lint.d.ts +47 -0
- package/dist/scanner/lint.js +163 -0
- package/dist/scanner/meta-checks.d.ts +8 -0
- package/dist/scanner/meta-checks.js +22 -0
- package/dist/scanner/outside-project.d.ts +19 -0
- package/dist/scanner/outside-project.js +20 -0
- package/dist/scanner/run.d.ts +19 -0
- package/dist/scanner/run.js +78 -0
- package/dist/scanner/scanner-config.d.ts +114 -0
- package/dist/scanner/scanner-config.js +207 -0
- package/dist/scanner/typescript-gate.d.ts +30 -0
- package/dist/scanner/typescript-gate.js +73 -0
- package/dist/vitest/build-config.d.ts +17 -0
- package/dist/vitest/build-config.js +106 -0
- package/dist/vitest/define-unit-config.d.ts +27 -0
- package/dist/vitest/define-unit-config.js +45 -0
- package/dist/vitest/dom/elements.d.ts +87 -0
- package/dist/vitest/dom/elements.js +291 -0
- package/dist/vitest/dom/index.d.ts +1 -0
- package/dist/vitest/dom/index.js +1 -0
- package/dist/vitest/dom/install.d.ts +8 -0
- package/dist/vitest/dom/install.js +261 -0
- package/dist/vitest/dom/setup.d.ts +1 -0
- package/dist/vitest/dom/setup.js +3 -0
- package/dist/vitest/index.d.ts +3 -0
- package/dist/vitest/index.js +2 -0
- package/dist/vitest/options.d.ts +92 -0
- package/dist/vitest/options.js +136 -0
- package/dist/vitest/peers.d.ts +10 -0
- package/dist/vitest/peers.js +51 -0
- package/dist/vitest/workspace-root.d.ts +7 -0
- package/dist/vitest/workspace-root.js +39 -0
- package/docs/build.md +232 -0
- package/docs/ci.md +182 -0
- package/docs/demo.md +364 -0
- package/docs/e2e.md +563 -0
- package/docs/release.md +374 -0
- package/docs/scanner.md +204 -0
- package/docs/unit.md +291 -0
- package/package.json +100 -4
- package/plugins/opdk/skills/audit/SKILL.md +81 -0
- package/plugins/opdk/skills/build/SKILL.md +79 -0
- package/plugins/opdk/skills/demo/SKILL.md +102 -0
- package/plugins/opdk/skills/e2e/SKILL.md +132 -0
- package/plugins/opdk/skills/release/SKILL.md +84 -0
- package/plugins/opdk/skills/scanner/SKILL.md +60 -0
- package/plugins/opdk/skills/unit/SKILL.md +90 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/** The record of media `opdk demo` wrote, in the demo output folder (`demo.outDir`). */
|
|
4
|
+
export const PUBLISHED_FILE = "published.json";
|
|
5
|
+
const RECORD_VERSION = 1;
|
|
6
|
+
function isRecord(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
function own(record, key) {
|
|
10
|
+
return Object.hasOwn(record, key) ? record[key] : undefined;
|
|
11
|
+
}
|
|
12
|
+
/** Parses the record's text; throws a message that says what is wrong with it. */
|
|
13
|
+
export function parsePublished(text) {
|
|
14
|
+
let data;
|
|
15
|
+
try {
|
|
16
|
+
data = JSON.parse(text);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
throw new Error(`${PUBLISHED_FILE} is not valid JSON (${error instanceof Error ? error.message : String(error)})`, { cause: error });
|
|
20
|
+
}
|
|
21
|
+
const listed = isRecord(data) ? own(data, "files") : undefined;
|
|
22
|
+
if (!isRecord(data) || own(data, "version") !== RECORD_VERSION || !isRecord(listed)) {
|
|
23
|
+
throw new Error(`${PUBLISHED_FILE} is not a version ${String(RECORD_VERSION)} record of { "files": { "<path>": "<film>" } }`);
|
|
24
|
+
}
|
|
25
|
+
const files = {};
|
|
26
|
+
for (const [file, film] of Object.entries(listed)) {
|
|
27
|
+
if (typeof film !== "string" || film === "") {
|
|
28
|
+
throw new Error(`${PUBLISHED_FILE}: the entry for "${file}" must be a film name`);
|
|
29
|
+
}
|
|
30
|
+
files[file] = film;
|
|
31
|
+
}
|
|
32
|
+
return files;
|
|
33
|
+
}
|
|
34
|
+
export function serializePublished(record) {
|
|
35
|
+
const files = Object.fromEntries(Object.entries(record).sort(([a], [b]) => a.localeCompare(b)));
|
|
36
|
+
return `${JSON.stringify({ version: RECORD_VERSION, files }, null, 2)}\n`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The record after a run: entries whose file is gone from disk are dropped (the owner deleted an obsolete file, so it
|
|
40
|
+
* must not be named again), and the files this run wrote are added or re-pointed at their film.
|
|
41
|
+
*/
|
|
42
|
+
export function updatePublished(previous, written, exists) {
|
|
43
|
+
const next = {};
|
|
44
|
+
for (const [file, film] of Object.entries(previous)) {
|
|
45
|
+
if (exists(file)) {
|
|
46
|
+
next[file] = film;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { ...next, ...written };
|
|
50
|
+
}
|
|
51
|
+
export function sameRecord(a, b) {
|
|
52
|
+
const left = Object.entries(a);
|
|
53
|
+
return left.length === Object.keys(b).length && left.every(([file, film]) => b[file] === film);
|
|
54
|
+
}
|
|
55
|
+
/** Reads the record; a missing file is an empty record (the kit has published nothing yet), anything else wrong throws. */
|
|
56
|
+
export function readPublished(outDir) {
|
|
57
|
+
let text;
|
|
58
|
+
try {
|
|
59
|
+
text = fs.readFileSync(path.join(outDir, PUBLISHED_FILE), "utf8");
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
63
|
+
return {};
|
|
64
|
+
}
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
return parsePublished(text);
|
|
68
|
+
}
|
|
69
|
+
export function writePublished(outDir, record) {
|
|
70
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
71
|
+
fs.writeFileSync(path.join(outDir, PUBLISHED_FILE), serializePublished(record));
|
|
72
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Reporter } from "../cli/reporter.js";
|
|
2
|
+
import type { DemoConfig } from "../config/types.js";
|
|
3
|
+
import { type FfmpegTool } from "./ffmpeg-run.js";
|
|
4
|
+
import type { ComposeParams } from "./phone-render.js";
|
|
5
|
+
/** The two things the run does outside this process; tests replace them. */
|
|
6
|
+
export interface DemoDeps {
|
|
7
|
+
/** Finds ffmpeg and checks it can do the job; throws with the install hint otherwise. */
|
|
8
|
+
locateFfmpeg(env: Readonly<Record<string, string | undefined>>, needsMp4: boolean): Promise<FfmpegTool>;
|
|
9
|
+
/** Renders the caption page for every frame (needs Electron). */
|
|
10
|
+
compose(params: ComposeParams): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare const defaultDeps: DemoDeps;
|
|
13
|
+
export interface DemoRunOptions {
|
|
14
|
+
readonly cwd: string;
|
|
15
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
16
|
+
/** Film names to encode; empty means every complete film. */
|
|
17
|
+
readonly names: readonly string[];
|
|
18
|
+
readonly config: DemoConfig;
|
|
19
|
+
readonly reporter: Reporter;
|
|
20
|
+
readonly source: string;
|
|
21
|
+
readonly deps?: DemoDeps;
|
|
22
|
+
/** Where the work folders go while a film is encoded; removed afterwards. Default: the OS temp folder. */
|
|
23
|
+
readonly tmpDir?: string;
|
|
24
|
+
}
|
|
25
|
+
/** Encodes the films and returns the exit code: 1 when anything failed, warnings do not count. */
|
|
26
|
+
export declare function runDemo(options: DemoRunOptions): Promise<number>;
|
|
27
|
+
/** `x-light` without `x-dark` (or the other way round): the pair was meant to be both. */
|
|
28
|
+
export declare function pairWarnings(manifests: readonly {
|
|
29
|
+
name: string;
|
|
30
|
+
theme: "light" | "dark" | null;
|
|
31
|
+
}[]): string[];
|
package/dist/demo/run.js
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { readStillPublishing } from "../e2e/demo/still-options.js";
|
|
5
|
+
import { budgetVerdict, compareFrames, densityWarnings, describeLoopDifference, findStaleOutputs, formatBytes, shortHoldWarning } from "./checks.js";
|
|
6
|
+
import { baseFilmName, demoFolders, DEFAULT_GIF_FPS, MAX_AUTO_GIF_WIDTH, resolveFilmSettings, stillsSettings, } from "./config.js";
|
|
7
|
+
import { buildConcatList, gifArgs, locateFfmpeg, mp4Args, posterArgs, rawFrameArgs, resolveGifWidth } from "./ffmpeg.js";
|
|
8
|
+
import { createFfmpegTool, probeFfmpeg } from "./ffmpeg-run.js";
|
|
9
|
+
import { assertFrameFiles, listFilms, moveFile } from "./films.js";
|
|
10
|
+
import { PAGE_HEIGHT, PAGE_SCALE, PAGE_WIDTH, resolvePhoneLayout } from "./phone-layout.js";
|
|
11
|
+
import { PUBLISHED_FILE, readPublished, sameRecord, updatePublished, writePublished } from "./published.js";
|
|
12
|
+
import { listStills, publishStill, stillKey } from "./stills.js";
|
|
13
|
+
const STEP = "demo";
|
|
14
|
+
export const defaultDeps = {
|
|
15
|
+
locateFfmpeg: async (env, needsMp4) => {
|
|
16
|
+
const { command } = await locateFfmpeg(env, probeFfmpeg);
|
|
17
|
+
const tool = createFfmpegTool(command);
|
|
18
|
+
if (needsMp4 && !/\blibx264\b/.test(await tool.encoders())) {
|
|
19
|
+
throw new Error(`${command} has no libx264 encoder, which the MP4 needs. Install a full build of ffmpeg (macOS: brew install ffmpeg), ` +
|
|
20
|
+
`point OPDK_FFMPEG at one, or set "mp4: false" in the demo section of opdk.config.mjs.`);
|
|
21
|
+
}
|
|
22
|
+
return tool;
|
|
23
|
+
},
|
|
24
|
+
compose: async (params) => {
|
|
25
|
+
// Loaded here: Playwright and Electron are not dependencies of the kit and only the phone layout needs them.
|
|
26
|
+
const { composePhoneFrames } = await import("./phone-render.js");
|
|
27
|
+
await composePhoneFrames(params);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
/** Encodes the films and returns the exit code: 1 when anything failed, warnings do not count. */
|
|
31
|
+
export async function runDemo(options) {
|
|
32
|
+
const { reporter, config } = options;
|
|
33
|
+
const deps = options.deps ?? defaultDeps;
|
|
34
|
+
const folders = demoFolders(config);
|
|
35
|
+
const outDir = path.resolve(options.cwd, folders.outDir);
|
|
36
|
+
const output = path.resolve(options.cwd, folders.output);
|
|
37
|
+
const listing = listFilms(outDir);
|
|
38
|
+
const filmNames = new Set([...listing.complete, ...listing.incomplete, ...listing.broken].map((film) => film.name));
|
|
39
|
+
const stillsConfig = stillsSettings(config);
|
|
40
|
+
const stills = listStills(outDir);
|
|
41
|
+
// A name selects a film, a still, or both. With stills turned off a still's name is not one the command knows.
|
|
42
|
+
const stillNames = stillsConfig === null ? [] : stills;
|
|
43
|
+
const unknownNames = options.names.filter((name) => !filmNames.has(name) && !stillNames.includes(name));
|
|
44
|
+
if (unknownNames.length > 0) {
|
|
45
|
+
const hiddenStills = unknownNames.filter((name) => stills.includes(name));
|
|
46
|
+
reporter.failure(STEP, `no film${stillNames.length > 0 ? " or still" : ""} named ${unknownNames.map((name) => `"${name}"`).join(", ")} in ${outDir}`, {
|
|
47
|
+
details: [
|
|
48
|
+
filmNames.size === 0 ? "There are no films there." : `Films there: ${[...filmNames].join(", ")}`,
|
|
49
|
+
...(stillNames.length > 0 ? [`Stills there: ${stillNames.join(", ")}`] : []),
|
|
50
|
+
...(hiddenStills.length > 0 ? ["demo.stills is false, so stills are not selectable."] : []),
|
|
51
|
+
],
|
|
52
|
+
hint: "Run the demo specs first (npx playwright test), or fix the name.",
|
|
53
|
+
});
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
const wanted = (name) => options.names.length === 0 || options.names.includes(name);
|
|
57
|
+
const selectedStills = stillNames.filter(wanted);
|
|
58
|
+
let failed = false;
|
|
59
|
+
for (const film of listing.broken.filter((item) => wanted(item.name))) {
|
|
60
|
+
failed = true;
|
|
61
|
+
reporter.failure(STEP, `${film.name}: unusable manifest`, { details: [film.reason], hint: "Record the film again." });
|
|
62
|
+
}
|
|
63
|
+
for (const film of listing.incomplete.filter((item) => wanted(item.name))) {
|
|
64
|
+
// Named on the command line, a film that cannot be encoded is a failure; found by scanning it is a note.
|
|
65
|
+
if (options.names.length > 0) {
|
|
66
|
+
failed = true;
|
|
67
|
+
reporter.failure(STEP, `${film.name}: not encoded`, { details: [film.reason] });
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
reporter.warn(STEP, `${film.name}: skipped, ${film.reason}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Stills do not stand in for films: films were recorded and none can be encoded, so the run failed. With names,
|
|
74
|
+
// only what was named counts (an incomplete named film already failed above).
|
|
75
|
+
if (options.names.length === 0 && filmNames.size > 0 && listing.complete.length === 0 && !failed) {
|
|
76
|
+
failed = true;
|
|
77
|
+
reporter.failure(STEP, `no complete film among the ${String(filmNames.size)} recorded in ${path.join(outDir, "films")}`, {
|
|
78
|
+
hint: "Run the demo specs again (npx playwright test) and check that they pass.",
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const films = listing.complete.filter((film) => wanted(film.name));
|
|
82
|
+
if (films.length === 0 && selectedStills.length === 0) {
|
|
83
|
+
if (!failed && filmNames.size === 0) {
|
|
84
|
+
reporter.failure(STEP, `no films in ${path.join(outDir, "films")}`, {
|
|
85
|
+
hint: "Record them with the demo fixture (npx playwright test), or set demo.outDir in opdk.config.mjs to where the specs write.",
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return 1;
|
|
89
|
+
}
|
|
90
|
+
const planned = films.map((film) => ({ film, settings: resolveFilmSettings(config, film.name, film.manifest.theme, options.source) }));
|
|
91
|
+
// Before any work: a missing ffmpeg is the same message for every film. A run of stills only does not need one.
|
|
92
|
+
const ffmpeg = planned.length === 0 ? undefined : await deps.locateFfmpeg(options.env, planned.some((item) => item.settings.mp4));
|
|
93
|
+
if (planned.length > 0) {
|
|
94
|
+
fs.mkdirSync(output, { recursive: true });
|
|
95
|
+
}
|
|
96
|
+
const written = {};
|
|
97
|
+
// Films (and stills, by their key) that were written without a failure: only they can say that a recorded file of theirs is no longer produced.
|
|
98
|
+
const encoded = new Set();
|
|
99
|
+
for (const { film, settings } of planned) {
|
|
100
|
+
if (ffmpeg === undefined) {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
const outcome = await encodeFilm({ film, settings, ffmpeg, deps, options, output });
|
|
104
|
+
for (const file of outcome.files) {
|
|
105
|
+
written[projectPath(options.cwd, file)] = film.name;
|
|
106
|
+
}
|
|
107
|
+
if (outcome.failures.length > 0) {
|
|
108
|
+
failed = true;
|
|
109
|
+
for (const failure of outcome.failures) {
|
|
110
|
+
reporter.failure(STEP, `${film.name}: ${failure.message}`, failure.hint === undefined ? {} : { hint: failure.hint });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
encoded.add(film.name);
|
|
115
|
+
reporter.success(STEP, `${film.name}: ${outcome.written.join(", ")}`);
|
|
116
|
+
}
|
|
117
|
+
for (const warning of outcome.warnings) {
|
|
118
|
+
reporter.warn(STEP, `${film.name}: ${warning}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (stillsConfig !== null && publishStills({ names: selectedStills, outDir, folder: path.resolve(options.cwd, stillsConfig.output), outputs: stillsConfig.outputs, cwd: options.cwd, written, encoded, reporter, filmFiles: filmOwnedFiles(outDir) })) {
|
|
122
|
+
failed = true;
|
|
123
|
+
}
|
|
124
|
+
for (const warning of pairWarnings(listing.complete.map((film) => film.manifest))) {
|
|
125
|
+
reporter.warn(STEP, warning);
|
|
126
|
+
}
|
|
127
|
+
// Stills are known whether or not they are published now: turning `demo.stills` off must not make them look orphaned.
|
|
128
|
+
const known = new Set([...filmNames, ...stills.map(stillKey)]);
|
|
129
|
+
reportStale({ outDir, cwd: options.cwd, written, encoded, known, reporter });
|
|
130
|
+
return failed ? 1 : 0;
|
|
131
|
+
}
|
|
132
|
+
/** The files the published record gives to films (not stills). An unreadable record gives none; reportStale reports it. */
|
|
133
|
+
function filmOwnedFiles(outDir) {
|
|
134
|
+
let record;
|
|
135
|
+
try {
|
|
136
|
+
record = readPublished(outDir);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return {};
|
|
140
|
+
}
|
|
141
|
+
return Object.fromEntries(Object.entries(record).filter(([, owner]) => !owner.startsWith("still:")));
|
|
142
|
+
}
|
|
143
|
+
/** Copies the selected stills into `folder`, reporting each one that was copied. Returns true when any failed. */
|
|
144
|
+
function publishStills(params) {
|
|
145
|
+
const unchanged = [];
|
|
146
|
+
const kept = [];
|
|
147
|
+
let failed = false;
|
|
148
|
+
for (const name of params.names) {
|
|
149
|
+
let publishing;
|
|
150
|
+
try {
|
|
151
|
+
publishing = readStillPublishing(params.outDir, name);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
failed = true;
|
|
155
|
+
params.reporter.failure(STEP, `still ${name}: ${error instanceof Error ? error.message : String(error)}`);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (!publishing.publish) {
|
|
159
|
+
// Handled without a failure, so a copy an earlier run published is reported as no longer written.
|
|
160
|
+
kept.push(name);
|
|
161
|
+
params.encoded.add(stillKey(name));
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const folder = publishing.out === undefined ? params.folder : outputFolder(params.outputs, publishing.out, params.cwd);
|
|
165
|
+
if (folder === undefined) {
|
|
166
|
+
failed = true;
|
|
167
|
+
const known = Object.keys(params.outputs);
|
|
168
|
+
params.reporter.failure(STEP, `still "${name}" asks for the output folder "${String(publishing.out)}", which demo.outputs does not define`, {
|
|
169
|
+
hint: `${known.length > 0 ? `demo.outputs has: ${known.join(", ")}. ` : "demo.outputs is not set. "}Add ${String(publishing.out)}: "<folder>" to the demo section of opdk.config.mjs, or change out in demo.still("${name}", ...).`,
|
|
170
|
+
});
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
// A still must not replace a film's file, written in this run or recorded by an earlier one (a still named
|
|
174
|
+
// `<film>-poster` would take the poster).
|
|
175
|
+
const destination = projectPath(params.cwd, path.join(folder, `${name}.png`));
|
|
176
|
+
const owner = params.written[destination] ?? params.filmFiles[destination];
|
|
177
|
+
if (owner !== undefined) {
|
|
178
|
+
failed = true;
|
|
179
|
+
const what = destination.endsWith("-poster.png") ? "the poster" : "the file";
|
|
180
|
+
params.reporter.failure(STEP, `still "${name}" would overwrite ${what} of film "${owner}"; rename the still`, {
|
|
181
|
+
hint: `${destination} belongs to film "${owner}". Rename ${path.join(params.outDir, "stills", `${name}.png`)} by changing the name passed to demo.still().`,
|
|
182
|
+
});
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
const still = publishStill(params.outDir, name, folder);
|
|
187
|
+
params.written[projectPath(params.cwd, still.file)] = stillKey(name);
|
|
188
|
+
params.encoded.add(stillKey(name));
|
|
189
|
+
if (still.copied) {
|
|
190
|
+
params.reporter.success(STEP, `still ${name}: png ${formatBytes(still.bytes)}`);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
unchanged.push(name);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
failed = true;
|
|
198
|
+
params.reporter.failure(STEP, `still ${name}: ${error instanceof Error ? error.message : String(error)}`, {
|
|
199
|
+
hint: `Check that ${path.join(params.outDir, "stills", `${name}.png`)} can be read and ${folder} can be written, or run the spec again.`,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (unchanged.length > 0) {
|
|
204
|
+
params.reporter.info(STEP, `${String(unchanged.length)} ${unchanged.length === 1 ? "still" : "stills"} unchanged: ${unchanged.join(", ")}`);
|
|
205
|
+
}
|
|
206
|
+
if (kept.length > 0) {
|
|
207
|
+
params.reporter.info(STEP, `${String(kept.length)} ${kept.length === 1 ? "still" : "stills"} not published (publish: false), left in ${path.join(params.outDir, "stills")}: ${kept.join(", ")}`);
|
|
208
|
+
}
|
|
209
|
+
return failed;
|
|
210
|
+
}
|
|
211
|
+
/** The absolute folder of a named output, or undefined when `demo.outputs` has no such name. */
|
|
212
|
+
function outputFolder(outputs, name, cwd) {
|
|
213
|
+
return Object.hasOwn(outputs, name) ? path.resolve(cwd, outputs[name] ?? "") : undefined;
|
|
214
|
+
}
|
|
215
|
+
/** The record's key for a file: relative to the project, with `/` on every platform. */
|
|
216
|
+
function projectPath(cwd, file) {
|
|
217
|
+
return path.relative(cwd, file).split(path.sep).join("/");
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Warns about media the kit itself published on an earlier run that no film produces any more (the film is gone, or
|
|
221
|
+
* it encoded cleanly this run without writing the file), then saves the record with this
|
|
222
|
+
* run's files. Only recorded files are named: a folder like docs/screens holds pictures the kit never wrote. With no
|
|
223
|
+
* record yet nothing is stale. A record that cannot be read is reported and replaced, so one bad file does not hide
|
|
224
|
+
* the stale check for good.
|
|
225
|
+
*/
|
|
226
|
+
function reportStale(params) {
|
|
227
|
+
const { outDir, reporter } = params;
|
|
228
|
+
const exists = (file) => fs.existsSync(path.resolve(params.cwd, file));
|
|
229
|
+
let previous = {};
|
|
230
|
+
let readable = true;
|
|
231
|
+
try {
|
|
232
|
+
previous = readPublished(outDir);
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
readable = false;
|
|
236
|
+
reporter.warn(STEP, `${error instanceof Error ? error.message : String(error)}; ignoring it and writing a new one in ${path.join(outDir, PUBLISHED_FILE)}.`);
|
|
237
|
+
}
|
|
238
|
+
const stale = findStaleOutputs(previous, params.known, exists, { encoded: params.encoded, written: params.written });
|
|
239
|
+
if (stale.goneFilms.length > 0) {
|
|
240
|
+
reporter.warn(STEP, `media published by an earlier run of this command belongs to films or stills that no longer exist: ${stale.goneFilms.join(", ")}. Delete them if they are obsolete; the command never removes files.`);
|
|
241
|
+
}
|
|
242
|
+
if (stale.notWritten.length > 0) {
|
|
243
|
+
reporter.warn(STEP, `media published by an earlier run of this command is no longer written by its film or still (an output turned off, or moved): ${stale.notWritten.join(", ")}. Delete them if they are obsolete; the command never removes files.`);
|
|
244
|
+
}
|
|
245
|
+
const next = updatePublished(previous, params.written, exists);
|
|
246
|
+
if (!readable || !sameRecord(previous, next)) {
|
|
247
|
+
writePublished(outDir, next);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/** `x-light` without `x-dark` (or the other way round): the pair was meant to be both. */
|
|
251
|
+
export function pairWarnings(manifests) {
|
|
252
|
+
const names = new Set(manifests.map((manifest) => manifest.name));
|
|
253
|
+
const warnings = [];
|
|
254
|
+
for (const manifest of manifests) {
|
|
255
|
+
if (manifest.theme === null) {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
const other = manifest.theme === "light" ? "dark" : "light";
|
|
259
|
+
const partner = `${baseFilmName(manifest.name, manifest.theme)}-${other}`;
|
|
260
|
+
if (!names.has(partner)) {
|
|
261
|
+
warnings.push(`${manifest.name}: the ${other} film "${partner}" is missing, so the pair is incomplete. Record both themes, or encode with the pair's name.`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return warnings;
|
|
265
|
+
}
|
|
266
|
+
/** Never throws for a problem with one film: the problem goes into `failures`, so the other films still run. */
|
|
267
|
+
async function encodeFilm(params) {
|
|
268
|
+
const outcome = { written: [], files: [], warnings: [], failures: [] };
|
|
269
|
+
const { settings } = params;
|
|
270
|
+
const work = fs.mkdtempSync(path.join(params.options.tmpDir ?? os.tmpdir(), "opdk-demo-"));
|
|
271
|
+
try {
|
|
272
|
+
await encodeInto(params, settings, work, outcome);
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
outcome.failures.push({ message: error instanceof Error ? error.message : String(error) });
|
|
276
|
+
}
|
|
277
|
+
finally {
|
|
278
|
+
fs.rmSync(work, { recursive: true, force: true });
|
|
279
|
+
}
|
|
280
|
+
return outcome;
|
|
281
|
+
}
|
|
282
|
+
async function encodeInto(params, settings, work, outcome) {
|
|
283
|
+
const { film, ffmpeg, deps, options, output } = params;
|
|
284
|
+
const { manifest } = film;
|
|
285
|
+
assertFrameFiles(film.dir, manifest.frames, manifest);
|
|
286
|
+
outcome.warnings.push(...densityWarnings(manifest));
|
|
287
|
+
// The loop is the film as recorded: a layout puts the same caption list around both ends, so it cannot hide a jump.
|
|
288
|
+
if (settings.loop !== "off" && manifest.frames.length > 1) {
|
|
289
|
+
await checkLoop({ ffmpeg, frameDir: film.dir, film, size: { width: manifest.width ?? 0, height: manifest.height ?? 0 }, mode: settings.loop, outcome });
|
|
290
|
+
}
|
|
291
|
+
let frameDir = film.dir;
|
|
292
|
+
let size = { width: manifest.width ?? 0, height: manifest.height ?? 0 };
|
|
293
|
+
if (settings.layout === "phone-captions") {
|
|
294
|
+
if (manifest.kind !== "phone") {
|
|
295
|
+
throw new Error(`layout "phone-captions" is for phone films, and this is a ${manifest.kind} film. Use layout "plain" for it.`);
|
|
296
|
+
}
|
|
297
|
+
if (manifest.captions.length === 0) {
|
|
298
|
+
throw new Error(`layout "phone-captions" puts the film's captions beside the phone, and this film has none. Pass captions to demo.film(), or use layout "plain".`);
|
|
299
|
+
}
|
|
300
|
+
frameDir = path.join(work, "composed");
|
|
301
|
+
size = { width: PAGE_WIDTH * PAGE_SCALE, height: PAGE_HEIGHT * PAGE_SCALE };
|
|
302
|
+
options.reporter.info(STEP, `${film.name}: composing ${String(manifest.frames.length)} frames beside their captions in Electron`);
|
|
303
|
+
await deps.compose({
|
|
304
|
+
cwd: options.cwd,
|
|
305
|
+
filmDir: film.dir,
|
|
306
|
+
frames: manifest.frames,
|
|
307
|
+
captions: manifest.captions,
|
|
308
|
+
layout: resolvePhoneLayout(settings.phone, manifest.theme),
|
|
309
|
+
outDir: frameDir,
|
|
310
|
+
...(options.tmpDir !== undefined && { tmpDir: options.tmpDir }),
|
|
311
|
+
});
|
|
312
|
+
assertFrameFiles(frameDir, manifest.frames, size);
|
|
313
|
+
}
|
|
314
|
+
const list = path.join(work, "frames.ffconcat");
|
|
315
|
+
fs.writeFileSync(list, buildConcatList(frameDir, manifest.frames));
|
|
316
|
+
const first = manifest.frames[0];
|
|
317
|
+
if (first === undefined) {
|
|
318
|
+
throw new Error("the film has no frames");
|
|
319
|
+
}
|
|
320
|
+
const { width: gifWidth, clamped } = resolveGifWidth(settings.gif?.width ?? null, size.width, MAX_AUTO_GIF_WIDTH);
|
|
321
|
+
if (clamped) {
|
|
322
|
+
outcome.warnings.push(`gif.width ${String(settings.gif?.width)} is wider than the frames (${String(size.width)} px); using ${String(size.width)}. The GIF is not upscaled.`);
|
|
323
|
+
}
|
|
324
|
+
const gifFps = settings.gif === null ? null : (settings.gif.fps ?? Math.min(manifest.fps, DEFAULT_GIF_FPS));
|
|
325
|
+
if (gifFps !== null) {
|
|
326
|
+
const warning = shortHoldWarning(manifest.frames, gifFps);
|
|
327
|
+
if (warning !== null) {
|
|
328
|
+
outcome.warnings.push(warning);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
const budgetCheck = (label, file) => {
|
|
332
|
+
const bytes = fs.statSync(file).size;
|
|
333
|
+
const verdict = budgetVerdict(bytes, settings.budget);
|
|
334
|
+
if (verdict === "fail") {
|
|
335
|
+
outcome.failures.push({
|
|
336
|
+
message: `${label} is ${formatBytes(bytes)}, over the ${formatBytes(settings.budget.failBytes)} limit`,
|
|
337
|
+
hint: `Lower the size (demo.films.${baseFilmName(film.name, manifest.theme)}.gif: width, colors, fps), shorten the film, or raise demo.budget.failBytes. The file stays in ${output} for inspection.`,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
else if (verdict === "warn") {
|
|
341
|
+
outcome.warnings.push(`${label} is ${formatBytes(bytes)}, over the ${formatBytes(settings.budget.warnBytes)} budget`);
|
|
342
|
+
}
|
|
343
|
+
return `${label} ${formatBytes(bytes)}`;
|
|
344
|
+
};
|
|
345
|
+
/**
|
|
346
|
+
* ffmpeg writes to a temporary name in the work folder and the file is moved into the output folder once it is
|
|
347
|
+
* complete, so a failed encode leaves the previous good file where it was and no half-written one.
|
|
348
|
+
*/
|
|
349
|
+
const encode = async (fileName, args) => {
|
|
350
|
+
const staging = path.join(work, "encoded");
|
|
351
|
+
fs.mkdirSync(staging, { recursive: true });
|
|
352
|
+
const temporary = path.join(staging, fileName);
|
|
353
|
+
await ffmpeg.run(args(temporary));
|
|
354
|
+
const finished = path.join(output, fileName);
|
|
355
|
+
moveFile(temporary, finished);
|
|
356
|
+
outcome.files.push(finished);
|
|
357
|
+
return finished;
|
|
358
|
+
};
|
|
359
|
+
if (settings.mp4) {
|
|
360
|
+
const out = await encode(`${film.name}.mp4`, (file) => mp4Args({ list, frames: manifest.frames, fps: manifest.fps, out: file }));
|
|
361
|
+
outcome.written.push(budgetCheck("mp4", out));
|
|
362
|
+
}
|
|
363
|
+
if (settings.gif !== null && gifFps !== null) {
|
|
364
|
+
const colors = settings.gif.colors;
|
|
365
|
+
const out = await encode(`${film.name}.gif`, (file) => gifArgs({ list, frames: manifest.frames, fps: gifFps, width: gifWidth, colors, out: file }));
|
|
366
|
+
outcome.written.push(budgetCheck("gif", out));
|
|
367
|
+
}
|
|
368
|
+
if (settings.poster !== null) {
|
|
369
|
+
const { width: posterWidth, clamped: posterClamped } = resolveGifWidth(settings.poster.width, size.width, size.width);
|
|
370
|
+
if (posterClamped) {
|
|
371
|
+
outcome.warnings.push(`poster.width ${String(settings.poster.width)} is wider than the frames (${String(size.width)} px); using ${String(size.width)}. The poster is not upscaled.`);
|
|
372
|
+
}
|
|
373
|
+
const out = await encode(`${film.name}-poster.png`, (file) => posterArgs({ frame: path.join(frameDir, first.file), width: posterWidth, out: file }));
|
|
374
|
+
budgetCheck("poster", out);
|
|
375
|
+
outcome.written.push("poster");
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
async function checkLoop(params) {
|
|
379
|
+
const { frames } = params.film.manifest;
|
|
380
|
+
const first = frames[0];
|
|
381
|
+
const last = frames.at(-1);
|
|
382
|
+
if (first === undefined || last === undefined) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const decode = async (file) => params.ffmpeg.capture(rawFrameArgs(path.join(params.frameDir, file)));
|
|
386
|
+
const difference = compareFrames(await decode(first.file), await decode(last.file), params.size.width, params.size.height);
|
|
387
|
+
if (difference === null) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
const message = describeLoopDifference(difference);
|
|
391
|
+
if (params.mode === "fail") {
|
|
392
|
+
params.outcome.failures.push({ message });
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
params.outcome.warnings.push(message);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The record and the stale check name the owner of an output file by a film name. A still gets `still:<name>`: a film
|
|
3
|
+
* name is a folder name and cannot hold a colon, so a still never shares its key with a film of the same name.
|
|
4
|
+
*/
|
|
5
|
+
export declare function stillKey(name: string): string;
|
|
6
|
+
/** The names of the PNGs in `<outDir>/stills`, sorted. A missing folder is no stills. */
|
|
7
|
+
export declare function listStills(outDir: string): string[];
|
|
8
|
+
export interface PublishedStill {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
/** Absolute path of the file in the output folder. */
|
|
11
|
+
readonly file: string;
|
|
12
|
+
/** False when the file there already had the same bytes and was left alone. */
|
|
13
|
+
readonly copied: boolean;
|
|
14
|
+
readonly bytes: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Puts `<outDir>/stills/<name>.png` into `folder` as `<name>.png`, unless the file there already has the same bytes,
|
|
18
|
+
* so a retake of an unchanged picture does not touch the file (and shows no change in git). The copy goes to a
|
|
19
|
+
* temporary name next to the destination and is renamed, so a failed copy leaves the previous picture whole.
|
|
20
|
+
*/
|
|
21
|
+
export declare function publishStill(outDir: string, name: string, folder: string): PublishedStill;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { STILLS_DIR } from "../e2e/demo/ownership.js";
|
|
4
|
+
/**
|
|
5
|
+
* The record and the stale check name the owner of an output file by a film name. A still gets `still:<name>`: a film
|
|
6
|
+
* name is a folder name and cannot hold a colon, so a still never shares its key with a film of the same name.
|
|
7
|
+
*/
|
|
8
|
+
export function stillKey(name) {
|
|
9
|
+
return `still:${name}`;
|
|
10
|
+
}
|
|
11
|
+
function isMissing(error) {
|
|
12
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
13
|
+
}
|
|
14
|
+
/** The names of the PNGs in `<outDir>/stills`, sorted. A missing folder is no stills. */
|
|
15
|
+
export function listStills(outDir) {
|
|
16
|
+
let entries;
|
|
17
|
+
try {
|
|
18
|
+
entries = fs.readdirSync(path.join(outDir, STILLS_DIR), { withFileTypes: true });
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (isMissing(error)) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
return entries
|
|
27
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith(".png"))
|
|
28
|
+
.map((entry) => entry.name.slice(0, -".png".length))
|
|
29
|
+
.sort((a, b) => a.localeCompare(b));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Puts `<outDir>/stills/<name>.png` into `folder` as `<name>.png`, unless the file there already has the same bytes,
|
|
33
|
+
* so a retake of an unchanged picture does not touch the file (and shows no change in git). The copy goes to a
|
|
34
|
+
* temporary name next to the destination and is renamed, so a failed copy leaves the previous picture whole.
|
|
35
|
+
*/
|
|
36
|
+
export function publishStill(outDir, name, folder) {
|
|
37
|
+
const source = path.join(outDir, STILLS_DIR, `${name}.png`);
|
|
38
|
+
const file = path.join(folder, `${name}.png`);
|
|
39
|
+
const bytes = fs.readFileSync(source);
|
|
40
|
+
let current;
|
|
41
|
+
try {
|
|
42
|
+
current = fs.readFileSync(file);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (!isMissing(error)) {
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (current?.equals(bytes) === true) {
|
|
50
|
+
return { name, file, copied: false, bytes: bytes.length };
|
|
51
|
+
}
|
|
52
|
+
fs.mkdirSync(folder, { recursive: true });
|
|
53
|
+
const partial = `${file}.opdk-partial`;
|
|
54
|
+
try {
|
|
55
|
+
fs.writeFileSync(partial, bytes);
|
|
56
|
+
fs.renameSync(partial, file);
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
fs.rmSync(partial, { force: true });
|
|
60
|
+
}
|
|
61
|
+
return { name, file, copied: true, bytes: bytes.length };
|
|
62
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trace and video for the Obsidian window. Playwright's `use.trace` and `use.video` only apply to the browser
|
|
3
|
+
* contexts its own fixtures create; the window of an `_electron` launch is outside them, so the kit reads the same
|
|
4
|
+
* settings and does what Playwright does for a browser: decide per attempt whether to record, and whether to keep.
|
|
5
|
+
*/
|
|
6
|
+
export type ArtifactMode = "off" | "on" | "retain-on-failure" | "on-first-retry" | "on-all-retries" | "retain-on-first-failure" | "retain-on-failure-and-retries";
|
|
7
|
+
export interface TraceSettings {
|
|
8
|
+
readonly mode: ArtifactMode;
|
|
9
|
+
readonly screenshots: boolean;
|
|
10
|
+
readonly snapshots: boolean;
|
|
11
|
+
readonly sources: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface VideoSettings {
|
|
14
|
+
readonly mode: ArtifactMode;
|
|
15
|
+
readonly size?: {
|
|
16
|
+
readonly width: number;
|
|
17
|
+
readonly height: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Does this attempt record? `retry` is 0 for the first run, 1 for the first retry. */
|
|
21
|
+
export declare function shouldRecord(mode: ArtifactMode, retry: number): boolean;
|
|
22
|
+
/** Is a recording of this attempt kept? Only meaningful when `shouldRecord` is true; otherwise nothing exists to keep. */
|
|
23
|
+
export declare function shouldKeep(mode: ArtifactMode, failed: boolean, retry: number): boolean;
|
|
24
|
+
/** Reads `use.trace`: a mode string or `{ mode, screenshots, snapshots, sources }`. Unset means `off`. */
|
|
25
|
+
export declare function parseTraceSetting(value: unknown): TraceSettings;
|
|
26
|
+
/** Reads `use.video`: a mode string or `{ mode, size }`. Unset means `off`. */
|
|
27
|
+
export declare function parseVideoSetting(value: unknown): VideoSettings;
|