@editframe/cli 0.7.0-beta.1 → 0.7.0-beta.11

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.
Files changed (53) hide show
  1. package/dist/VERSION.cjs +1 -1
  2. package/dist/VERSION.js +1 -1
  3. package/dist/commands/auth.cjs +14 -11
  4. package/dist/commands/auth.js +15 -12
  5. package/dist/commands/check.cjs +2 -2
  6. package/dist/commands/check.js +2 -2
  7. package/dist/commands/process.cjs +36 -0
  8. package/dist/commands/process.js +35 -0
  9. package/dist/commands/render.cjs +34 -25
  10. package/dist/commands/render.js +34 -25
  11. package/dist/index.cjs +1 -11
  12. package/dist/index.js +1 -12
  13. package/dist/operations/getRenderInfo.cjs +59 -0
  14. package/dist/operations/getRenderInfo.js +59 -0
  15. package/dist/operations/processRenderInfo.cjs +30 -0
  16. package/dist/operations/processRenderInfo.js +30 -0
  17. package/dist/operations/syncAssetsDirectory.cjs +83 -40
  18. package/dist/operations/syncAssetsDirectory.js +82 -39
  19. package/dist/utils/index.cjs +8 -15
  20. package/dist/utils/index.js +8 -15
  21. package/dist/utils/launchBrowserAndWaitForSDK.cjs +7 -3
  22. package/dist/utils/launchBrowserAndWaitForSDK.js +7 -3
  23. package/dist/utils/validateVideoResolution.cjs +27 -0
  24. package/dist/utils/validateVideoResolution.js +27 -0
  25. package/package.json +6 -12
  26. package/src/commands/auth.ts +14 -12
  27. package/src/commands/check.ts +2 -2
  28. package/src/commands/process.ts +43 -37
  29. package/src/commands/render.ts +32 -30
  30. package/src/operations/getRenderInfo.ts +80 -0
  31. package/src/operations/processRenderInfo.ts +37 -0
  32. package/src/operations/syncAssetsDirectory.ts +77 -40
  33. package/src/utils/index.ts +7 -16
  34. package/src/utils/launchBrowserAndWaitForSDK.ts +9 -3
  35. package/src/utils/validateVideoResolution.ts +33 -0
  36. package/dist/api/caption-file.cjs +0 -48
  37. package/dist/api/caption-file.js +0 -48
  38. package/dist/api/image-file.cjs +0 -49
  39. package/dist/api/image-file.js +0 -49
  40. package/dist/api/index.cjs +0 -12
  41. package/dist/api/index.js +0 -12
  42. package/dist/api/isobmff-file.cjs +0 -48
  43. package/dist/api/isobmff-file.js +0 -48
  44. package/dist/api/isobmff-track.cjs +0 -63
  45. package/dist/api/isobmff-track.js +0 -63
  46. package/dist/api/renders.cjs +0 -51
  47. package/dist/api/renders.js +0 -51
  48. package/src/api/caption-file.ts +0 -60
  49. package/src/api/image-file.ts +0 -58
  50. package/src/api/index.ts +0 -17
  51. package/src/api/isobmff-file.ts +0 -59
  52. package/src/api/isobmff-track.ts +0 -77
  53. package/src/api/renders.ts +0 -59
@@ -0,0 +1,27 @@
1
+ import { z } from "zod";
2
+ import ora from "ora";
3
+ import debug from "debug";
4
+ const log = debug("ef:cli:auth");
5
+ const schema = z.object({
6
+ width: z.number().int(),
7
+ height: z.number().int()
8
+ }).refine((data) => data.width % 2 === 0 && data.height % 2 === 0, {
9
+ message: "Both width and height must be divisible by 2.",
10
+ path: ["width", "height"]
11
+ });
12
+ const validateVideoResolution = async (rawPayload) => {
13
+ const spinner = ora("Validating video resolution").start();
14
+ const result = schema.safeParse(rawPayload);
15
+ if (result.success) {
16
+ spinner.succeed("Video resolution is valid");
17
+ return result.data;
18
+ }
19
+ spinner.fail("Invalid video resolution");
20
+ process.stderr.write(result.error?.errors.map((e) => e.message).join("\n"));
21
+ process.stderr.write("\n");
22
+ log("Error:", result.error?.errors.map((e) => e.message).join("\n"));
23
+ process.exit(1);
24
+ };
25
+ export {
26
+ validateVideoResolution
27
+ };
package/package.json CHANGED
@@ -1,17 +1,10 @@
1
1
  {
2
2
  "name": "@editframe/cli",
3
- "version": "0.7.0-beta.1",
3
+ "version": "0.7.0-beta.11",
4
4
  "description": "Command line interface for EditFrame",
5
5
  "bin": {
6
6
  "editframe": "./dist/index.js"
7
7
  },
8
- "exports": {
9
- "./api": {
10
- "import": "./dist/api/index.js",
11
- "require": "./dist/api/index.cjs"
12
- }
13
- },
14
- "types": "./dist/index.d.ts",
15
8
  "type": "module",
16
9
  "scripts": {
17
10
  "typecheck": "tsc --noEmit --emitDeclarationOnly false",
@@ -29,13 +22,14 @@
29
22
  "vite-tsconfig-paths": "^4.3.2"
30
23
  },
31
24
  "dependencies": {
32
- "@editframe/assets": "0.7.0-beta.1",
33
- "@editframe/elements": "0.7.0-beta.1",
34
- "@editframe/vite-plugin": "0.7.0-beta.1",
25
+ "@editframe/api": "0.7.0-beta.11",
26
+ "@editframe/assets": "0.7.0-beta.11",
27
+ "@editframe/elements": "0.7.0-beta.11",
28
+ "@editframe/vite-plugin": "0.7.0-beta.11",
35
29
  "axios": "^1.6.8",
36
30
  "chalk": "^5.3.0",
37
31
  "commander": "^12.0.0",
38
- "debug": "^4.3.4",
32
+ "debug": "^4.3.5",
39
33
  "dotenv": "^16.4.5",
40
34
  "mime": "^4.0.3",
41
35
  "mp4box": "^0.5.2",
@@ -1,7 +1,11 @@
1
1
  import { program } from "commander";
2
2
  import ora from "ora";
3
3
  import chalk from "chalk";
4
- import { authenticatedFetch } from "../utils";
4
+ import debug from "debug";
5
+
6
+ import { getClient } from "../utils";
7
+
8
+ const log = debug("ef:cli:auth");
5
9
 
6
10
  export interface APIOrgResult {
7
11
  name: string;
@@ -13,32 +17,30 @@ export interface APIOrgResult {
13
17
  }
14
18
 
15
19
  export const getApiData = async () => {
16
- const response = await authenticatedFetch("/api/org");
20
+ const response = await getClient().authenticatedFetch("/api/org");
17
21
  return response.json() as Promise<APIOrgResult>;
18
22
  };
19
23
 
20
24
  const authCommand = program
21
25
  .command("auth")
22
26
  .description("Fetch organization data using API token")
23
- .option("-d, --debug", "output extra debugging")
24
27
  .action(async () => {
25
28
  const options = authCommand.opts();
26
- if (options.debug) {
27
- console.log("Options:", options);
28
- }
29
+ log("Options:", options);
29
30
 
30
31
  const spinner = ora("Loading...").start();
31
32
 
32
33
  try {
33
34
  const apiData = await getApiData();
34
35
  spinner.succeed("You are authenticated! 🎉");
35
- console.log(chalk.green(`Name: ${apiData.name}`));
36
- console.log(chalk.green(`Welcome to ${apiData.org_display_name}!`));
36
+ process.stderr.write(chalk.green(`Name: ${apiData.name}\n`));
37
+ process.stderr.write(
38
+ chalk.green(`Welcome to ${apiData.org_display_name}!\n`),
39
+ );
37
40
  } catch (error: any) {
38
41
  spinner.fail("Authentication failed!");
39
- console.error(error?.message);
40
- if (options.debug) {
41
- console.error(error);
42
- }
42
+ process.stderr.write(error?.message);
43
+ process.stderr.write("\n");
44
+ log("Error:", error);
43
45
  }
44
46
  });
@@ -122,8 +122,8 @@ program
122
122
  );
123
123
  } catch (error) {
124
124
  spinner.fail(chalk.white.bgRed(` Check for ${checkName} failed `));
125
- console.log(chalk.red(check.message().join("\n\n")));
126
- console.log();
125
+ process.stderr.write(chalk.red(check.message().join("\n\n")));
126
+ process.stderr.write("\n");
127
127
  }
128
128
  }
129
129
  });
@@ -1,38 +1,44 @@
1
- // import { program, Option } from "commander";
2
- // import { withSpinner } from "../utils/withSpinner";
3
- // import type {} from "@/elements/elements";
4
- // import { launchBrowserAndWaitForSDK } from "../utils/launchBrowserAndWaitForSDK";
1
+ import { spawnSync } from "node:child_process";
2
+ import path from "node:path";
5
3
 
6
- // program
7
- // .command("process <url>")
8
- // .description("Process a URL")
9
- // .addOption(
10
- // new Option("-h, --host <host>", "Editframe host")
11
- // .env("EF_HOST")
12
- // .makeOptionMandatory(),
13
- // )
14
- // .action(async (url: string, options) => {
15
- // await launchBrowserAndWaitForSDK({ url }, async (page) => {
16
- // const htmlWithProductionSrcs = await withSpinner(
17
- // "Fingerprinting assets",
18
- // () =>
19
- // page.evaluate(
20
- // async ([host]) => {
21
- // const workbench = document.querySelector("ef-workbench");
22
- // if (!workbench) {
23
- // throw new Error("Workbench not found");
24
- // }
25
- // workbench.apiHost = host;
26
- // await workbench.loadMd5Sums();
27
- // for (const sheet of document.styleSheets) {
28
- // // sheet.
29
- // }
30
- // document.styleSheets;
31
- // return document.documentElement.outerHTML;
32
- // },
33
- // [options.host] as [host: string],
34
- // ),
35
- // );
36
- // process.stdout.write(htmlWithProductionSrcs);
37
- // });
38
- // });
4
+ import { program } from "commander";
5
+
6
+ import { withSpinner } from "../utils/withSpinner";
7
+ import { launchBrowserAndWaitForSDK } from "../utils/launchBrowserAndWaitForSDK";
8
+ import { PreviewServer } from "../utils/startPreviewServer";
9
+ import { getRenderInfo } from "../operations/getRenderInfo";
10
+ import { processRenderInfo } from "../operations/processRenderInfo";
11
+
12
+ program
13
+ .command("process [directory]")
14
+ .description(
15
+ "Process's a directory's index.html file, analyzing assets and processing them for rendering",
16
+ )
17
+ .action(async (directory) => {
18
+ directory ??= ".";
19
+
20
+ // const srcDir = path.join(directory, "src");
21
+ const distDir = path.join(directory, "dist");
22
+ await withSpinner("Building\n", async () => {
23
+ spawnSync("npx", ["vite", "build", directory], {
24
+ stdio: "inherit",
25
+ });
26
+ });
27
+
28
+ const previewServer = await PreviewServer.start(distDir);
29
+ process.stderr.write("Preview server started at ");
30
+ process.stderr.write(previewServer.url);
31
+ process.stderr.write("\n");
32
+ await launchBrowserAndWaitForSDK(
33
+ {
34
+ url: previewServer.url,
35
+ efInteractive: false,
36
+ interactive: false,
37
+ headless: true,
38
+ },
39
+ async (page) => {
40
+ const renderInfo = await page.evaluate(getRenderInfo);
41
+ await processRenderInfo(renderInfo);
42
+ },
43
+ );
44
+ });
@@ -1,20 +1,24 @@
1
- import { spawnSync } from "node:child_process";
2
1
  import path from "node:path";
3
2
  import { readFile, writeFile } from "node:fs/promises";
4
3
 
5
4
  import * as tar from "tar";
6
5
  import { program, Option } from "commander";
7
6
  import { parse as parseHTML } from "node-html-parser";
7
+ import { build } from "vite";
8
8
 
9
9
  import { md5Directory, md5FilePath } from "@editframe/assets";
10
- import type { EFTimegroup } from "@editframe/elements";
11
10
 
12
11
  import { withSpinner } from "../utils/withSpinner";
13
- import { createRender, uploadRender } from "../api/renders";
12
+ import { createRender, uploadRender } from "@editframe/api";
14
13
  import { launchBrowserAndWaitForSDK } from "../utils/launchBrowserAndWaitForSDK";
15
14
  import { PreviewServer } from "../utils/startPreviewServer";
16
15
  import { PassThrough } from "node:stream";
17
16
  import { syncAssetDirectory } from "../operations/syncAssetsDirectory";
17
+ import { getClient } from "../utils";
18
+ import { getRenderInfo } from "../operations/getRenderInfo";
19
+ import { processRenderInfo } from "../operations/processRenderInfo";
20
+ import { inspect } from "node:util";
21
+ import { validateVideoResolution } from "../utils/validateVideoResolution";
18
22
 
19
23
  interface StrategyBuilder {
20
24
  buildProductionUrl: (tagName: string, assetPath: string) => Promise<string>;
@@ -87,13 +91,21 @@ program
87
91
  return;
88
92
  }
89
93
  await withSpinner("Building\n", async () => {
90
- spawnSync("npx", ["vite", "build", directory], {
91
- stdio: "inherit",
92
- });
94
+ try {
95
+ await build({
96
+ root: directory,
97
+ logLevel: "info", // Optional: adjust log level as needed
98
+ clearScreen: false, // Optional: keep console output clean
99
+ });
100
+ } catch (error) {
101
+ console.error("Build failed:", error);
102
+ }
93
103
  });
94
104
 
95
105
  const previewServer = await PreviewServer.start(distDir);
96
- console.log("Preview server started at", previewServer.url);
106
+ process.stderr.write("Preview server started at:");
107
+ process.stderr.write(previewServer.url);
108
+ process.stderr.write("\n");
97
109
  await launchBrowserAndWaitForSDK(
98
110
  {
99
111
  url: previewServer.url,
@@ -102,26 +114,15 @@ program
102
114
  headless: true,
103
115
  },
104
116
  async (page) => {
105
- const renderInfo = await page.evaluate(async () => {
106
- const rootTimeGroup = document.querySelector("ef-timegroup") as
107
- | EFTimegroup
108
- | undefined;
109
- if (!rootTimeGroup) {
110
- throw new Error("No ef-timegroup found");
111
- }
112
-
113
- console.log("Waiting for media durations", rootTimeGroup);
114
- await rootTimeGroup.waitForMediaDurations();
115
-
116
- const width = rootTimeGroup.clientWidth;
117
- const height = rootTimeGroup.clientHeight;
118
- const fps = 30;
119
- const durationMs = Math.round(rootTimeGroup.durationMs);
117
+ const renderInfo = await page.evaluate(getRenderInfo);
120
118
 
121
- return { width, height, fps, durationMs };
119
+ validateVideoResolution({
120
+ width: renderInfo.width,
121
+ height: renderInfo.height,
122
122
  });
123
123
 
124
- console.log("RENDER INFO", renderInfo);
124
+ await processRenderInfo(renderInfo);
125
+
125
126
  const doc = parseHTML(
126
127
  await readFile(path.join(distDir, "index.html"), "utf-8"),
127
128
  );
@@ -147,7 +148,7 @@ program
147
148
  await writeFile(path.join(distDir, "index.html"), doc.toString());
148
149
 
149
150
  const md5 = await md5Directory(distDir);
150
- const render = await createRender({
151
+ const render = await createRender(getClient(), {
151
152
  id: md5,
152
153
  width: renderInfo.width,
153
154
  height: renderInfo.height,
@@ -157,8 +158,8 @@ program
157
158
  strategy: options.strategy,
158
159
  });
159
160
  if (render?.status !== "created") {
160
- console.error(
161
- `Render is in '${render?.status}' status. It cannot be recreated while in this status.`,
161
+ process.stderr.write(
162
+ `Render is in '${render?.status}' status. It cannot be recreated while in this status.\n`,
162
163
  );
163
164
  return;
164
165
  }
@@ -178,9 +179,10 @@ program
178
179
  );
179
180
  const readable = new PassThrough();
180
181
  tarStream.pipe(readable);
181
- await uploadRender(md5, readable);
182
- console.log("Render assets uploaded");
183
- console.log(render);
182
+ await uploadRender(getClient(), md5, readable);
183
+ process.stderr.write("Render assets uploaded\n");
184
+ process.stderr.write(inspect(render));
185
+ process.stderr.write("\n");
184
186
  },
185
187
  );
186
188
  });
@@ -0,0 +1,80 @@
1
+ /**
2
+ * THIS MODULE DOESNT USE THE DEBUG LOGGER BECAUSE IT IS
3
+ * RUN IN A WEB BROWSER. LOGS ARE CAPTURED AND RE-LOGGED.
4
+ */
5
+
6
+ import type {
7
+ EFCaptions,
8
+ EFImage,
9
+ EFMedia,
10
+ EFTimegroup,
11
+ } from "@editframe/elements";
12
+
13
+ export const getRenderInfo = async () => {
14
+ const rootTimeGroup = document.querySelector("ef-timegroup") as
15
+ | EFTimegroup
16
+ | undefined;
17
+ if (!rootTimeGroup) {
18
+ throw new Error("No ef-timegroup found");
19
+ }
20
+
21
+ console.error("Waiting for media durations", rootTimeGroup);
22
+ await rootTimeGroup.waitForMediaDurations();
23
+
24
+ const width = rootTimeGroup.clientWidth;
25
+ const height = rootTimeGroup.clientHeight;
26
+ const fps = 30;
27
+ const durationMs = Math.round(rootTimeGroup.durationMs);
28
+
29
+ const elements = document.querySelectorAll(
30
+ "ef-audio, ef-video, ef-image, ef-captions",
31
+ );
32
+
33
+ const assets = {
34
+ efMedia: <Record<string, any>>{},
35
+ efCaptions: new Set<string>(),
36
+ efImage: new Set<string>(),
37
+ };
38
+
39
+ for (const element of elements) {
40
+ switch (element.tagName) {
41
+ case "EF-AUDIO":
42
+ case "EF-VIDEO": {
43
+ const src = (element as EFMedia).src;
44
+ console.error("Processing element", element.tagName, src);
45
+ assets.efMedia[src] = (
46
+ element as EFMedia
47
+ ).trackFragmentIndexLoader.value;
48
+ break;
49
+ }
50
+ case "EF-IMAGE": {
51
+ const src = (element as EFImage).src;
52
+ console.error("Processing element", element.tagName, src);
53
+ assets.efImage.add(src);
54
+ break;
55
+ }
56
+ case "EF-CAPTIONS": {
57
+ const src = (element as EFCaptions).targetElement?.src;
58
+ console.error("Processing element", element.tagName, src);
59
+ assets.efCaptions.add(src);
60
+ break;
61
+ }
62
+ }
63
+ }
64
+
65
+ const renderInfo = {
66
+ width,
67
+ height,
68
+ fps,
69
+ durationMs,
70
+ assets: {
71
+ efMedia: assets.efMedia,
72
+ efCaptions: Array.from(assets.efCaptions),
73
+ efImage: Array.from(assets.efImage),
74
+ },
75
+ };
76
+
77
+ console.error("Render info", renderInfo);
78
+
79
+ return renderInfo;
80
+ };
@@ -0,0 +1,37 @@
1
+ import {
2
+ generateTrack,
3
+ cacheImage,
4
+ findOrCreateCaptions,
5
+ } from "@editframe/assets";
6
+ import type { getRenderInfo } from "./getRenderInfo";
7
+
8
+ export const processRenderInfo = async (
9
+ renderInfo: Awaited<ReturnType<typeof getRenderInfo>>,
10
+ ) => {
11
+ for (const [src, tracks] of Object.entries(renderInfo.assets.efMedia)) {
12
+ process.stderr.write("Processing media asset: ");
13
+ process.stderr.write(src);
14
+ process.stderr.write("\n");
15
+ for (const trackId in tracks) {
16
+ await generateTrack(
17
+ "./src/assets",
18
+ `./src${src}`,
19
+ `src?trackId=${trackId}`,
20
+ );
21
+ }
22
+ }
23
+
24
+ for (const imageAsset of renderInfo.assets.efImage) {
25
+ process.stderr.write("Processing image asset: ");
26
+ process.stderr.write(imageAsset);
27
+ process.stderr.write("\n");
28
+ await cacheImage("./src/assets", `./src${imageAsset}`);
29
+ }
30
+
31
+ for (const captionsAsset of renderInfo.assets.efCaptions) {
32
+ process.stderr.write("Processing captions asset: ");
33
+ process.stderr.write(captionsAsset);
34
+ process.stderr.write("\n");
35
+ await findOrCreateCaptions("./src/assets", `./src${captionsAsset}`);
36
+ }
37
+ };