@navipartner/demo-video 0.7.3 → 0.7.4
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/bin/args.d.mts +2 -0
- package/bin/args.mjs +28 -0
- package/bin/init.mjs +27 -0
- package/bin/runner.mjs +2 -8
- package/package.json +4 -6
- package/skills/np-demo-video/reference.md +5 -0
package/bin/args.d.mts
CHANGED
|
@@ -22,6 +22,8 @@ export interface DemoArgs {
|
|
|
22
22
|
draft: boolean;
|
|
23
23
|
}
|
|
24
24
|
export const COMMANDS: readonly string[];
|
|
25
|
+
/** The package.json that makes demo.config.ts CommonJS, or null. */
|
|
26
|
+
export function commonJsDemo(demoDir: string): string | null;
|
|
25
27
|
export function parseArgs(argv: string[], cwd: string): DemoArgs;
|
|
26
28
|
export interface StoryEntry {
|
|
27
29
|
name: string;
|
package/bin/args.mjs
CHANGED
|
@@ -11,6 +11,28 @@ export const COMMANDS = [
|
|
|
11
11
|
"brand-needs",
|
|
12
12
|
];
|
|
13
13
|
const NEEDS_STORYBOARD = new Set(["check", "render", "record"]);
|
|
14
|
+
// Commands whose Playwright run loads demo.config.ts.
|
|
15
|
+
const LOADS_ADAPTER = new Set(["check", "render", "record", "brand-needs"]);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The package.json that makes demo.config.ts CommonJS, or null. Playwright
|
|
19
|
+
* compiles a .ts file as CommonJS unless the nearest package.json says
|
|
20
|
+
* "type": "module", and the adapter's imports then fail to load. An app
|
|
21
|
+
* that isn't ESM gets demo/package.json from init, scoped to demo/ so its
|
|
22
|
+
* e2e suite loads as before.
|
|
23
|
+
*/
|
|
24
|
+
export const commonJsDemo = (demoDir) => {
|
|
25
|
+
for (let dir = demoDir; ; dir = path.dirname(dir)) {
|
|
26
|
+
const file = path.join(dir, "package.json");
|
|
27
|
+
if (fs.existsSync(file)) {
|
|
28
|
+
const type = JSON.parse(fs.readFileSync(file, "utf8")).type;
|
|
29
|
+
return type === "module" ? null : file;
|
|
30
|
+
}
|
|
31
|
+
if (path.dirname(dir) === dir) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
14
36
|
const USAGE = `Usage: demo-video <${COMMANDS.join("|")}> [--app <dir>] [--story <name|file.json>] [--brand <name>] [--brands <dir>] [--draft] [--json]
|
|
15
37
|
Without --story, check, render and record use the app's primary story.
|
|
16
38
|
--draft renders at 30 fps (about half the time) to iterate on a story.
|
|
@@ -111,6 +133,12 @@ export const parseArgs = (argv, cwd) => {
|
|
|
111
133
|
if (!fs.existsSync(adapterPath)) {
|
|
112
134
|
throw new Error(`No demo adapter: expected ${adapterPath}`);
|
|
113
135
|
}
|
|
136
|
+
const commonJs = LOADS_ADAPTER.has(command) ? commonJsDemo(demoDir) : null;
|
|
137
|
+
if (commonJs) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
`${path.relative(cwd, commonJs) || "package.json"} has no "type": "module", so Playwright would load demo/demo.config.ts as CommonJS and its imports would fail. Add ${path.relative(cwd, path.join(demoDir, "package.json"))} containing {"type": "module"} (init writes it).`,
|
|
140
|
+
);
|
|
141
|
+
}
|
|
114
142
|
// Everything a run needs only while it runs (the generated Playwright
|
|
115
143
|
// config and spec, the check report, the raw recording, Playwright's
|
|
116
144
|
// results) goes here, inside demo/out/ (gitignored), and is deleted when
|
package/bin/init.mjs
CHANGED
|
@@ -432,6 +432,33 @@ export const initApp = (appDir, { dryRun = false } = {}) => {
|
|
|
432
432
|
: "skeleton; webServer to fill in (TODO)",
|
|
433
433
|
]);
|
|
434
434
|
}
|
|
435
|
+
// Playwright compiles demo.config.ts as CommonJS in an app that isn't
|
|
436
|
+
// ESM, and the adapter's imports then fail. "type": "module" for demo/
|
|
437
|
+
// only: setting it for the app would change how its e2e suite loads.
|
|
438
|
+
if (pkg.type !== "module") {
|
|
439
|
+
const demoPkg = path.join(demoDir, "package.json");
|
|
440
|
+
const existing = read(demoPkg);
|
|
441
|
+
if (existing === null) {
|
|
442
|
+
if (!dryRun) {
|
|
443
|
+
fs.mkdirSync(demoDir, { recursive: true });
|
|
444
|
+
fs.writeFileSync(
|
|
445
|
+
demoPkg,
|
|
446
|
+
`${JSON.stringify({ type: "module" }, null, 2)}\n`,
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
changes.push([
|
|
450
|
+
"added",
|
|
451
|
+
"demo/package.json",
|
|
452
|
+
'"type": "module" (the app is CommonJS)',
|
|
453
|
+
]);
|
|
454
|
+
} else if (JSON.parse(existing).type === "module") {
|
|
455
|
+
changes.push(["ok", "demo/package.json", '"type": "module"']);
|
|
456
|
+
} else {
|
|
457
|
+
todo.push(
|
|
458
|
+
'Set "type": "module" in demo/package.json: Playwright loads demo.config.ts as CommonJS otherwise.',
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
435
462
|
todo.push(
|
|
436
463
|
"Ask Claude for a demo video of this app: it finishes demo.config.ts and writes the primary story, then runs demo-video check.",
|
|
437
464
|
);
|
package/bin/runner.mjs
CHANGED
|
@@ -14,12 +14,6 @@ const importPath = (from, to) => {
|
|
|
14
14
|
const HEADER =
|
|
15
15
|
"// Generated by @navipartner/demo-video on every run; do not edit.\n";
|
|
16
16
|
|
|
17
|
-
// In an app that isn't ESM, Playwright compiles demo.config.ts as CommonJS,
|
|
18
|
-
// and its `export default` arrives wrapped: { __esModule, default }.
|
|
19
|
-
const importAdapter = (from) => `import loaded from ${from};
|
|
20
|
-
|
|
21
|
-
const adapter = loaded?.__esModule ? loaded.default : loaded;`;
|
|
22
|
-
|
|
23
17
|
/** Writes playwright.config.mjs and demo.spec.mjs; returns the config path. */
|
|
24
18
|
export const writeRunner = ({
|
|
25
19
|
runnerDir,
|
|
@@ -34,7 +28,7 @@ export const writeRunner = ({
|
|
|
34
28
|
configPath,
|
|
35
29
|
`${HEADER}import { createDemoConfig } from "@navipartner/demo-video/runner";
|
|
36
30
|
|
|
37
|
-
${
|
|
31
|
+
import adapter from ${adapter};
|
|
38
32
|
|
|
39
33
|
export default createDemoConfig(adapter, ${dirs});
|
|
40
34
|
`,
|
|
@@ -44,7 +38,7 @@ export default createDemoConfig(adapter, ${dirs});
|
|
|
44
38
|
`${HEADER}import { registerDemoTests } from "@navipartner/demo-video/runner";
|
|
45
39
|
import { test } from "@playwright/test";
|
|
46
40
|
|
|
47
|
-
${
|
|
41
|
+
import adapter from ${adapter};
|
|
48
42
|
|
|
49
43
|
registerDemoTests(test, adapter, ${JSON.stringify(demoDir)});
|
|
50
44
|
`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navipartner/demo-video",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "Marketing demo videos of a React app, filmed by Playwright against the app's own e2e mocks.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -9,20 +9,18 @@
|
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"engines": {
|
|
12
|
-
"node": ">=22
|
|
12
|
+
"node": ">=22"
|
|
13
13
|
},
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
18
|
"types": "./dist/index.d.ts",
|
|
19
|
-
"import": "./dist/index.js"
|
|
20
|
-
"default": "./dist/index.js"
|
|
19
|
+
"import": "./dist/index.js"
|
|
21
20
|
},
|
|
22
21
|
"./runner": {
|
|
23
22
|
"types": "./dist/runner/index.d.ts",
|
|
24
|
-
"import": "./dist/runner/index.js"
|
|
25
|
-
"default": "./dist/runner/index.js"
|
|
23
|
+
"import": "./dist/runner/index.js"
|
|
26
24
|
}
|
|
27
25
|
},
|
|
28
26
|
"bin": {
|
|
@@ -12,6 +12,11 @@ Optional: `actions` (app steps such as a barcode scan), `idleTimeoutSeconds`,
|
|
|
12
12
|
`{ what, optional: true }`. A brand without a need that isn't optional fails
|
|
13
13
|
`check`.
|
|
14
14
|
|
|
15
|
+
In an app that isn't ESM (no `"type": "module"` in its package.json),
|
|
16
|
+
`demo/package.json` holds `{ "type": "module" }`, so `demo.config.ts` loads
|
|
17
|
+
as ESM while the app's own files stay as they are. `init` writes it, and
|
|
18
|
+
`check` says so if it's missing.
|
|
19
|
+
|
|
15
20
|
```ts
|
|
16
21
|
import { defineDemo, overlayResponse } from "@navipartner/demo-video";
|
|
17
22
|
|