@navipartner/demo-video 0.4.0 → 0.5.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 +135 -109
- package/bin/args.d.mts +39 -30
- package/bin/args.mjs +158 -153
- package/bin/demo-video.mjs +425 -272
- package/bin/encode.mjs +187 -187
- package/bin/init.d.mts +30 -24
- package/bin/init.mjs +521 -447
- package/bin/pick.d.mts +23 -18
- package/bin/pick.mjs +265 -252
- package/bin/pitch.d.mts +17 -0
- package/bin/pitch.mjs +261 -0
- package/dist/{adapter-CWqMoNdw.d.ts → adapter-D_iU2dh2.d.ts} +19 -0
- package/dist/index.d.ts +3 -3
- package/dist/runner/index.d.ts +2 -2
- package/dist/runner/index.js +61 -3
- package/package.json +1 -1
- package/skills/np-demo-video/SKILL.md +364 -348
- package/skills/np-demo-video/look.md +158 -158
- package/skills/np-demo-video/pitch.md +99 -0
- package/skills/np-demo-video/reference.md +92 -82
package/bin/args.mjs
CHANGED
|
@@ -1,153 +1,158 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
export const COMMANDS = [
|
|
5
|
-
"check",
|
|
6
|
-
"render",
|
|
7
|
-
"record",
|
|
8
|
-
"encode",
|
|
9
|
-
"stills",
|
|
10
|
-
"list",
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
--
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export const COMMANDS = [
|
|
5
|
+
"check",
|
|
6
|
+
"render",
|
|
7
|
+
"record",
|
|
8
|
+
"encode",
|
|
9
|
+
"stills",
|
|
10
|
+
"list",
|
|
11
|
+
"brand-needs",
|
|
12
|
+
];
|
|
13
|
+
const NEEDS_STORYBOARD = new Set(["check", "render", "record"]);
|
|
14
|
+
const USAGE = `Usage: demo-video <${COMMANDS.join("|")}> [--app <dir>] [--story <name|file.json>] [--brand <name>] [--brands <dir>] [--draft] [--json]
|
|
15
|
+
Without --story, check, render and record use the app's primary story.
|
|
16
|
+
--draft renders at 30 fps (about half the time) to iterate on a story.
|
|
17
|
+
--brands adds a brands folder outside the repo, searched first.
|
|
18
|
+
brand-needs: what a brand must give this app (its adapter's brandNeeds).
|
|
19
|
+
Setup: demo-video init [--app <dir>] [--dry-run]
|
|
20
|
+
For a /demo-video request: demo-video pick --request "<text>" [--json] <app dir>...
|
|
21
|
+
For a pitch draft (the skill's pitch.md): demo-video pitch <proposal.json> [--app <dir>] [--story <name>] [--out <dir>] [--json]`;
|
|
22
|
+
|
|
23
|
+
export const resolveStoryboard = (value, cwd, demoDir) => {
|
|
24
|
+
if (value.endsWith(".json")) {
|
|
25
|
+
const file = path.resolve(cwd, value);
|
|
26
|
+
if (!fs.existsSync(file)) {
|
|
27
|
+
throw new Error(`Story file ${file} does not exist`);
|
|
28
|
+
}
|
|
29
|
+
return file;
|
|
30
|
+
}
|
|
31
|
+
const dir = path.join(demoDir, "stories");
|
|
32
|
+
const file = path.join(dir, `${value}.json`);
|
|
33
|
+
if (!fs.existsSync(file)) {
|
|
34
|
+
const known = fs.existsSync(dir)
|
|
35
|
+
? fs
|
|
36
|
+
.readdirSync(dir)
|
|
37
|
+
.filter((f) => f.endsWith(".json"))
|
|
38
|
+
.map((f) => f.slice(0, -".json".length))
|
|
39
|
+
: [];
|
|
40
|
+
throw new Error(
|
|
41
|
+
`No story "${value}" in ${dir}. Known: ${known.join(", ") || "(none)"}`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return file;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The app's stories, primary first, then by name. Reads only `description`
|
|
49
|
+
* and `primary`: the full check needs the adapter and runs in `check`.
|
|
50
|
+
*/
|
|
51
|
+
export const listStories = (demoDir) => {
|
|
52
|
+
const dir = path.join(demoDir, "stories");
|
|
53
|
+
if (!fs.existsSync(dir)) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
const stories = fs
|
|
57
|
+
.readdirSync(dir)
|
|
58
|
+
.filter((f) => f.endsWith(".json"))
|
|
59
|
+
.map((f) => {
|
|
60
|
+
const story = JSON.parse(fs.readFileSync(path.join(dir, f), "utf8"));
|
|
61
|
+
return {
|
|
62
|
+
name: f.slice(0, -".json".length),
|
|
63
|
+
description: story.description ?? null,
|
|
64
|
+
primary: story.primary === true,
|
|
65
|
+
// A variant: the base story's flow, for one brand.
|
|
66
|
+
...(story.extends
|
|
67
|
+
? { extends: story.extends, brand: story.brand ?? null }
|
|
68
|
+
: {}),
|
|
69
|
+
};
|
|
70
|
+
})
|
|
71
|
+
.sort(
|
|
72
|
+
(a, b) =>
|
|
73
|
+
Number(b.primary) - Number(a.primary) || a.name.localeCompare(b.name),
|
|
74
|
+
);
|
|
75
|
+
const primaries = stories.filter((s) => s.primary).map((s) => s.name);
|
|
76
|
+
if (primaries.length > 1) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Only one story can be primary; ${primaries.join(", ")} all are (in ${dir})`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return stories;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const parseArgs = (argv, cwd) => {
|
|
85
|
+
const [command, ...rest] = argv;
|
|
86
|
+
if (!COMMANDS.includes(command)) {
|
|
87
|
+
throw new Error(USAGE);
|
|
88
|
+
}
|
|
89
|
+
const opts = {
|
|
90
|
+
app: ".",
|
|
91
|
+
story: undefined,
|
|
92
|
+
brand: undefined,
|
|
93
|
+
json: false,
|
|
94
|
+
draft: false,
|
|
95
|
+
};
|
|
96
|
+
for (let i = 0; i < rest.length; i++) {
|
|
97
|
+
const arg = rest[i];
|
|
98
|
+
if (arg === "--json") {
|
|
99
|
+
opts.json = true;
|
|
100
|
+
} else if (arg === "--draft") {
|
|
101
|
+
opts.draft = true;
|
|
102
|
+
} else if (["--app", "--story", "--brand", "--brands"].includes(arg)) {
|
|
103
|
+
const value = rest[++i];
|
|
104
|
+
if (!value) {
|
|
105
|
+
throw new Error(`${arg} needs a value`);
|
|
106
|
+
}
|
|
107
|
+
opts[arg.slice(2)] = value;
|
|
108
|
+
} else {
|
|
109
|
+
throw new Error(`Unknown option ${arg}\n${USAGE}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const appDir = path.resolve(cwd, opts.app);
|
|
113
|
+
const demoDir = path.join(appDir, "demo");
|
|
114
|
+
const adapterPath = path.join(demoDir, "demo.config.ts");
|
|
115
|
+
if (!fs.existsSync(adapterPath)) {
|
|
116
|
+
throw new Error(`No demo adapter: expected ${adapterPath}`);
|
|
117
|
+
}
|
|
118
|
+
// Everything a run needs only while it runs (the generated Playwright
|
|
119
|
+
// config and spec, the check report, the raw recording, Playwright's
|
|
120
|
+
// results) goes here, inside demo/out/ (gitignored), and is deleted when
|
|
121
|
+
// the command ends. Only a failure's results are kept, in demo/out/failed/.
|
|
122
|
+
// `check` has its own folder, so it never touches the take that `record`
|
|
123
|
+
// leaves for `encode`.
|
|
124
|
+
const workDir = path.join(
|
|
125
|
+
demoDir,
|
|
126
|
+
"out",
|
|
127
|
+
".work",
|
|
128
|
+
command === "check" || command === "brand-needs" ? command : "take",
|
|
129
|
+
);
|
|
130
|
+
const runnerDir = path.join(workDir, "runner");
|
|
131
|
+
let storyboardPath = null;
|
|
132
|
+
if (NEEDS_STORYBOARD.has(command)) {
|
|
133
|
+
// No --story: the app's primary story, its main journey.
|
|
134
|
+
const story =
|
|
135
|
+
opts.story ?? listStories(demoDir).find((s) => s.primary)?.name;
|
|
136
|
+
if (!story) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
`No --story given and no primary story in ${path.join(demoDir, "stories")}. Name one with --story, or mark the app's main journey "primary": true.`,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
storyboardPath = resolveStoryboard(story, cwd, demoDir);
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
command,
|
|
145
|
+
appDir,
|
|
146
|
+
demoDir,
|
|
147
|
+
adapterPath,
|
|
148
|
+
workDir,
|
|
149
|
+
runnerDir,
|
|
150
|
+
configPath: path.join(runnerDir, "playwright.config.mjs"),
|
|
151
|
+
outDir: path.join(demoDir, "out"),
|
|
152
|
+
storyboardPath,
|
|
153
|
+
brand: opts.brand ?? null,
|
|
154
|
+
brandsDir: opts.brands ? path.resolve(cwd, opts.brands) : null,
|
|
155
|
+
json: opts.json,
|
|
156
|
+
draft: opts.draft,
|
|
157
|
+
};
|
|
158
|
+
};
|