@revideo/cli 0.2.14-alpha.933 → 0.2.14-alpha.937

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/dist/index.js CHANGED
@@ -1,28 +1,38 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
3
  Object.defineProperty(exports, "__esModule", { value: true });
7
- const child_process_1 = require("child_process");
4
+ const telemetry_1 = require("@revideo/telemetry");
8
5
  const commander_1 = require("commander");
9
- const path_1 = __importDefault(require("path"));
10
- const Program = new commander_1.Command();
11
- Program.name('revideo')
6
+ const index_1 = require("./server/index");
7
+ const player_1 = require("./server/player");
8
+ const program = new commander_1.Command();
9
+ program
10
+ .name('revideo')
12
11
  .description('CLI to interact with the revideo service')
13
- .version('1.0.0');
14
- Program.command('serve')
15
- .description('Start the revideo server')
16
- .option('--projectFile <path>', 'Path to the project file')
12
+ .version('0.2.13');
13
+ program
14
+ .command('serve')
15
+ .description('UNSTABLE (still WIP): Start the revideo server in development mode. Watches for changes ' +
16
+ 'in the project directory and re-builds the player on each change.')
17
+ .option('--projectFile <path>', 'Path to the project file', './vite.config.ts')
17
18
  .option('--port <number>', 'Port on which to start the server', '4000')
18
- .action(options => {
19
+ .option('--watchDir <path>', 'Directory to watch for changes', 'src')
20
+ .action(async (options) => {
21
+ (0, telemetry_1.sendEvent)(telemetry_1.EventName.CLICommand);
19
22
  if (!options.projectFile) {
20
23
  console.error('Error: --projectFile option must be specified.');
21
24
  process.exit(1);
22
25
  }
26
+ await (0, player_1.buildProject)().catch(() => {
27
+ console.error('Error building project');
28
+ process.exit(1);
29
+ });
23
30
  const { projectFile, port } = options;
24
31
  process.env.PROJECT_FILE = projectFile;
25
32
  process.env.REVIDEO_PORT = port;
26
- (0, child_process_1.execSync)(`node ${path_1.default.join(__dirname, './server.js')}`, { stdio: 'inherit' });
33
+ (0, index_1.createServer)(options.watchDir).listen(port, () => {
34
+ console.log(`Server listening on port ${port}`);
35
+ console.log();
36
+ });
27
37
  });
28
- Program.parse(process.argv);
38
+ program.parse(process.argv);
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.download = void 0;
7
+ const fs_1 = require("fs");
8
+ const path_1 = __importDefault(require("path"));
9
+ async function download(req, res) {
10
+ const { projectName } = req.params;
11
+ const resultFilePath = path_1.default.join(process.cwd(), `output/${projectName}`);
12
+ try {
13
+ await fs_1.promises.access(resultFilePath);
14
+ res.download(resultFilePath, `${projectName}`, async (err) => {
15
+ if (err) {
16
+ console.error(err);
17
+ res.status(500).send('Error downloading the file.');
18
+ }
19
+ });
20
+ }
21
+ catch (error) {
22
+ console.error(`File not found ${resultFilePath}:`, error);
23
+ res.status(404).send('File not found.');
24
+ }
25
+ }
26
+ exports.download = download;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createServer = void 0;
7
+ const express_1 = __importDefault(require("express"));
8
+ const download_1 = require("./download");
9
+ const player_1 = require("./player");
10
+ const render_1 = require("./render");
11
+ function createServer(hotReloadDir) {
12
+ const app = (0, express_1.default)();
13
+ app.use(express_1.default.json());
14
+ app.post('/render', render_1.render);
15
+ app.get('/download/:projectName', download_1.download);
16
+ app.use('/player/project.js', player_1.player);
17
+ if (hotReloadDir) {
18
+ (0, player_1.createHotReloader)(hotReloadDir);
19
+ }
20
+ return app;
21
+ }
22
+ exports.createServer = createServer;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.player = exports.createHotReloader = exports.buildProject = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const chokidar_1 = require("chokidar");
6
+ const fs_1 = require("fs");
7
+ const YELLOW_DOT = '\u001b[33m•\u001b[0m';
8
+ const GREEN_CHECK = '\u001b[32m✔\u001b[0m';
9
+ const RED_CROSS = '\u001b[31m✘\u001b[0m';
10
+ const fileNotFoundMessage = (filePath) => `${YELLOW_DOT} File ${filePath} not found. Building project...`;
11
+ const fileNotFoundAfterBuildingMessage = (filePath, padding) => `\r${RED_CROSS} File ${filePath} still not found after building project...`.padEnd(padding, ' ') + '\n';
12
+ const fileChangedMessage = (filePath) => `${YELLOW_DOT} File ${filePath} has changed. Rebuilding...`;
13
+ const successMessage = (time, padding) => `\r${GREEN_CHECK} Project built successfully. ${time}ms`.padEnd(padding, ' ') + '\n';
14
+ /**
15
+ * Runs `npm run build`.
16
+ */
17
+ async function buildProject() {
18
+ const buildProcess = (0, child_process_1.spawn)('npm', ['run', 'build']);
19
+ return new Promise((resolve, reject) => {
20
+ buildProcess.on('close', code => {
21
+ if (code === 0) {
22
+ resolve();
23
+ return;
24
+ }
25
+ reject();
26
+ });
27
+ });
28
+ }
29
+ exports.buildProject = buildProject;
30
+ /**
31
+ * Watches the given directory for changes and rebuilds the project on each change.
32
+ * @param dir - Directory to watch for changes.
33
+ */
34
+ async function createHotReloader(dir) {
35
+ const watcher = (0, chokidar_1.watch)(dir);
36
+ watcher.on('change', async (path) => {
37
+ const rebuildingMessage = fileChangedMessage(path);
38
+ process.stdout.write(rebuildingMessage);
39
+ const start = Date.now();
40
+ try {
41
+ await buildProject();
42
+ process.stdout.write(successMessage(Date.now() - start, rebuildingMessage.length + 1));
43
+ }
44
+ catch (e) {
45
+ // TODO: Add more detailed error message
46
+ console.error('Error building project. Try to run `npm run build` manually and check for errors.');
47
+ }
48
+ });
49
+ }
50
+ exports.createHotReloader = createHotReloader;
51
+ async function player(_, res) {
52
+ const path = './dist/project.js';
53
+ let buildTime = undefined;
54
+ let error = false;
55
+ // Check if the file exists and build the project if it doesn't.
56
+ await fs_1.promises.access(path).catch(async () => {
57
+ buildTime = Date.now();
58
+ process.stdout.write(fileNotFoundMessage(path));
59
+ await buildProject();
60
+ });
61
+ // If the file still doesn't exist, send an error response.
62
+ await fs_1.promises.access(path).catch(() => {
63
+ process.stdout.write(fileNotFoundAfterBuildingMessage(path, fileNotFoundMessage(path).length + 1));
64
+ res.status(500).send('Error building project');
65
+ error = true;
66
+ });
67
+ if (error) {
68
+ return;
69
+ }
70
+ // If we built the project, update the log message.
71
+ if (buildTime) {
72
+ process.stdout.write(successMessage(Date.now() - buildTime, fileNotFoundMessage(path).length + 1));
73
+ }
74
+ return res.sendFile('./dist/project.js', { root: './' });
75
+ }
76
+ exports.player = player;
@@ -3,16 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.render = void 0;
6
7
  const renderer_1 = require("@revideo/renderer");
7
8
  const axios_1 = __importDefault(require("axios"));
8
- const express_1 = __importDefault(require("express"));
9
- const fs_1 = require("fs");
10
9
  const path_1 = __importDefault(require("path"));
11
10
  const uuid_1 = require("uuid");
12
- const App = (0, express_1.default)();
13
- const Port = process.env.REVIDEO_PORT || 3000;
14
- App.use(express_1.default.json());
15
- App.post('/render', async (req, res) => {
11
+ const utils_1 = require("../utils");
12
+ async function render(req, res) {
16
13
  const { variables, callbackUrl } = req.body;
17
14
  if (!callbackUrl) {
18
15
  return res.status(400).send('Callback URL is required.');
@@ -21,7 +18,7 @@ App.post('/render', async (req, res) => {
21
18
  res.json({ jobId });
22
19
  try {
23
20
  const tempProjectName = (0, uuid_1.v4)();
24
- await (0, renderer_1.renderVideo)(process.env.PROJECT_FILE || '', variables, {
21
+ await (0, renderer_1.renderVideo)(process.env.PROJECT_FILE || '', variables, () => { }, {
25
22
  name: tempProjectName,
26
23
  });
27
24
  const resultFilePath = path_1.default.join(process.cwd(), `output/${tempProjectName}.mp4`);
@@ -39,7 +36,7 @@ App.post('/render', async (req, res) => {
39
36
  if (response.status !== 200) {
40
37
  throw new Error('Callback URL responded with an error');
41
38
  }
42
- scheduleCleanup(resultFilePath);
39
+ (0, utils_1.scheduleCleanup)(resultFilePath);
43
40
  }
44
41
  catch (error) {
45
42
  console.error(error);
@@ -54,36 +51,5 @@ App.post('/render', async (req, res) => {
54
51
  },
55
52
  });
56
53
  }
57
- });
58
- App.get('/download/:projectName', async (req, res) => {
59
- const { projectName } = req.params;
60
- const resultFilePath = path_1.default.join(process.cwd(), `output/${projectName}`);
61
- try {
62
- await fs_1.promises.access(resultFilePath);
63
- res.download(resultFilePath, `${projectName}`, async (err) => {
64
- if (err) {
65
- console.error(err);
66
- res.status(500).send('Error downloading the file.');
67
- }
68
- });
69
- }
70
- catch (error) {
71
- console.error(`File not found ${resultFilePath}:`, error);
72
- res.status(404).send('File not found.');
73
- }
74
- });
75
- App.listen(Port, () => {
76
- console.log(`Server running on port ${Port}`);
77
- });
78
- function scheduleCleanup(filePath) {
79
- // wait 10 minutes before removing file
80
- setTimeout(async () => {
81
- try {
82
- await fs_1.promises.unlink(filePath);
83
- console.log(`Successfully deleted file: ${filePath}`);
84
- }
85
- catch (error) {
86
- console.error(`Error deleting file ${filePath}: ${error}`);
87
- }
88
- }, 10 * 60 * 1000);
89
54
  }
55
+ exports.render = render;
package/dist/utils.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scheduleCleanup = void 0;
4
+ const fs_1 = require("fs");
5
+ function scheduleCleanup(filePath) {
6
+ const clean = async () => {
7
+ try {
8
+ await fs_1.promises.unlink(filePath);
9
+ console.log(`Successfully deleted file: ${filePath}`);
10
+ }
11
+ catch (error) {
12
+ console.error(`Error deleting file ${filePath}: ${error}`);
13
+ }
14
+ };
15
+ // Wait 10 minutes before removing file.
16
+ setTimeout(clean, 10 * 60 * 1000);
17
+ }
18
+ exports.scheduleCleanup = scheduleCleanup;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revideo/cli",
3
- "version": "0.2.14-alpha.933+2129297",
3
+ "version": "0.2.14-alpha.937+a9767dd",
4
4
  "description": "A CLI for revideo",
5
5
  "main": "dist/index.js",
6
6
  "author": "revideo",
@@ -24,10 +24,11 @@
24
24
  "typescript": "^5.4.3"
25
25
  },
26
26
  "dependencies": {
27
- "@revideo/renderer": "^0.2.14-alpha.933+2129297",
27
+ "@revideo/renderer": "^0.2.14-alpha.937+a9767dd",
28
+ "@revideo/telemetry": "^0.2.14-alpha.937+a9767dd",
28
29
  "commander": "^12.0.0",
29
30
  "express": "^4.19.2",
30
31
  "uuid": "^9.0.1"
31
32
  },
32
- "gitHead": "2129297c5dde033fd30431ab92d3cfffa372326d"
33
+ "gitHead": "a9767dda0cdc696547a1b2397a707a90a4f63a1a"
33
34
  }