@revideo/cli 0.3.7-alpha.986 → 0.3.7-beta.987

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
File without changes
@@ -1,26 +1,30 @@
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 });
1
+ 'use strict';
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : {default: mod};
6
+ };
7
+ Object.defineProperty(exports, '__esModule', {value: true});
6
8
  exports.download = void 0;
7
- const fs_1 = require("fs");
8
- const path_1 = __importDefault(require("path"));
9
+ const fs_1 = require('fs');
10
+ const path_1 = __importDefault(require('path'));
9
11
  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
- }
12
+ const {projectName} = req.params;
13
+ const resultFilePath = path_1.default.join(
14
+ process.cwd(),
15
+ `output/${projectName}`,
16
+ );
17
+ try {
18
+ await fs_1.promises.access(resultFilePath);
19
+ res.download(resultFilePath, `${projectName}`, async err => {
20
+ if (err) {
21
+ console.error(err);
22
+ res.status(500).send('Error downloading the file.');
23
+ }
24
+ });
25
+ } catch (error) {
26
+ console.error(`File not found ${resultFilePath}:`, error);
27
+ res.status(404).send('File not found.');
28
+ }
25
29
  }
26
30
  exports.download = download;
@@ -1,60 +1,91 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
1
+ 'use strict';
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (
9
+ !desc ||
10
+ ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)
11
+ ) {
12
+ desc = {
13
+ enumerable: true,
14
+ get: function () {
15
+ return m[k];
16
+ },
17
+ };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }
21
+ : function (o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ });
25
+ var __setModuleDefault =
26
+ (this && this.__setModuleDefault) ||
27
+ (Object.create
28
+ ? function (o, v) {
29
+ Object.defineProperty(o, 'default', {enumerable: true, value: v});
30
+ }
31
+ : function (o, v) {
32
+ o['default'] = v;
33
+ });
34
+ var __importStar =
35
+ (this && this.__importStar) ||
36
+ function (mod) {
19
37
  if (mod && mod.__esModule) return mod;
20
38
  var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
39
+ if (mod != null)
40
+ for (var k in mod)
41
+ if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
42
+ __createBinding(result, mod, k);
22
43
  __setModuleDefault(result, mod);
23
44
  return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
45
+ };
46
+ Object.defineProperty(exports, '__esModule', {value: true});
26
47
  exports.player = exports.createHotReloader = exports.buildProject = void 0;
27
- const chokidar_1 = require("chokidar");
28
- const fs_1 = require("fs");
29
- const path = __importStar(require("path"));
30
- const vite_1 = require("vite");
48
+ const chokidar_1 = require('chokidar');
49
+ const fs_1 = require('fs');
50
+ const path = __importStar(require('path'));
51
+ const vite_1 = require('vite');
31
52
  const YELLOW_DOT = '\u001b[33m•\u001b[0m';
32
53
  const GREEN_CHECK = '\u001b[32m✔\u001b[0m';
33
54
  const RED_CROSS = '\u001b[31m✘\u001b[0m';
34
- const fileNotFoundMessage = (filePath) => `${YELLOW_DOT} File ${filePath} not found. Building project...`;
35
- const fileNotFoundAfterBuildingMessage = (filePath, padding) => `\r${RED_CROSS} File ${filePath} still not found after building project...`.padEnd(padding, ' ') + '\n';
36
- const fileChangedMessage = (filePath) => `${YELLOW_DOT} File ${filePath} has changed. Rebuilding...`;
37
- const successMessage = (time, padding) => `\r${GREEN_CHECK} Project built successfully. ${time}ms`.padEnd(padding, ' ') + '\n';
55
+ const fileNotFoundMessage = filePath =>
56
+ `${YELLOW_DOT} File ${filePath} not found. Building project...`;
57
+ const fileNotFoundAfterBuildingMessage = (filePath, padding) =>
58
+ `\r${RED_CROSS} File ${filePath} still not found after building project...`.padEnd(
59
+ padding,
60
+ ' ',
61
+ ) + '\n';
62
+ const fileChangedMessage = filePath =>
63
+ `${YELLOW_DOT} File ${filePath} has changed. Rebuilding...`;
64
+ const successMessage = (time, padding) =>
65
+ `\r${GREEN_CHECK} Project built successfully. ${time}ms`.padEnd(
66
+ padding,
67
+ ' ',
68
+ ) + '\n';
38
69
  async function buildProject() {
39
- try {
40
- await (0, vite_1.build)({
41
- configFile: path.join(process.cwd(), process.env.PROJECT_FILE || ''),
42
- build: {
43
- outDir: 'dist',
44
- rollupOptions: {
45
- output: {
46
- entryFileNames: '[name].js',
47
- chunkFileNames: '[name].js',
48
- assetFileNames: '[name].[ext]',
49
- },
50
- },
51
- },
52
- });
53
- }
54
- catch (error) {
55
- console.error('Error building project:', error);
56
- throw error;
57
- }
70
+ try {
71
+ await (0, vite_1.build)({
72
+ configFile: path.join(process.cwd(), process.env.PROJECT_FILE || ''),
73
+ publicDir: false,
74
+ build: {
75
+ outDir: 'dist',
76
+ rollupOptions: {
77
+ output: {
78
+ entryFileNames: '[name].js',
79
+ chunkFileNames: '[name].js',
80
+ assetFileNames: '[name].[ext]',
81
+ },
82
+ },
83
+ },
84
+ });
85
+ } catch (error) {
86
+ console.error('Error building project:', error);
87
+ throw error;
88
+ }
58
89
  }
59
90
  exports.buildProject = buildProject;
60
91
  /**
@@ -62,49 +93,62 @@ exports.buildProject = buildProject;
62
93
  * @param dir - Directory to watch for changes.
63
94
  */
64
95
  async function createHotReloader(dir) {
65
- const watcher = (0, chokidar_1.watch)(dir, {
66
- ignored: ['**/*.meta'],
67
- });
68
- watcher.on('change', async (path) => {
69
- const rebuildingMessage = fileChangedMessage(path);
70
- process.stdout.write(rebuildingMessage);
71
- const start = Date.now();
72
- try {
73
- await buildProject();
74
- process.stdout.write(successMessage(Date.now() - start, rebuildingMessage.length + 1));
75
- }
76
- catch (e) {
77
- // TODO: Add more detailed error message
78
- console.error('Error building project. Try to run `npm run build` manually and check for errors.');
79
- }
80
- });
96
+ const watcher = (0, chokidar_1.watch)(dir, {
97
+ ignored: ['**/*.meta'],
98
+ });
99
+ watcher.on('change', async path => {
100
+ const rebuildingMessage = fileChangedMessage(path);
101
+ process.stdout.write(rebuildingMessage);
102
+ const start = Date.now();
103
+ try {
104
+ await buildProject();
105
+ process.stdout.write(
106
+ successMessage(Date.now() - start, rebuildingMessage.length + 1),
107
+ );
108
+ } catch (e) {
109
+ // TODO: Add more detailed error message
110
+ console.error(
111
+ 'Error building project. Try to run `npm run build` manually and check for errors.',
112
+ );
113
+ }
114
+ });
81
115
  }
82
116
  exports.createHotReloader = createHotReloader;
83
117
  async function player(req, res) {
84
- const path = `./dist/${req.params.file}`;
85
- let buildTime = undefined;
86
- let error = false;
87
- // Check if the file exists and build the project if it doesn't.
88
- await fs_1.promises.access(path).catch(async () => {
89
- buildTime = Date.now();
90
- process.stdout.write(fileNotFoundMessage(path));
91
- await buildProject().catch(() => {
92
- res.status(500).send('Error building project');
93
- });
94
- });
95
- // If the file still doesn't exist, send an error response.
96
- await fs_1.promises.access(path).catch(() => {
97
- process.stdout.write(fileNotFoundAfterBuildingMessage(path, fileNotFoundMessage(path).length + 1));
98
- res.status(404).send(`File ${path} not found`);
99
- error = true;
118
+ const path = `./dist/${req.params.file}`;
119
+ let buildTime = undefined;
120
+ let error = false;
121
+ // Check if the file exists and build the project if it doesn't.
122
+ await fs_1.promises.access(path).catch(async () => {
123
+ buildTime = Date.now();
124
+ process.stdout.write(fileNotFoundMessage(path));
125
+ await buildProject().catch(() => {
126
+ res.status(500).send('Error building project');
100
127
  });
101
- if (error) {
102
- return;
103
- }
104
- // If we built the project, update the log message.
105
- if (buildTime) {
106
- process.stdout.write(successMessage(Date.now() - buildTime, fileNotFoundMessage(path).length + 1));
107
- }
108
- return res.sendFile(path, { root: './' });
128
+ });
129
+ // If the file still doesn't exist, send an error response.
130
+ await fs_1.promises.access(path).catch(() => {
131
+ process.stdout.write(
132
+ fileNotFoundAfterBuildingMessage(
133
+ path,
134
+ fileNotFoundMessage(path).length + 1,
135
+ ),
136
+ );
137
+ res.status(404).send(`File ${path} not found`);
138
+ error = true;
139
+ });
140
+ if (error) {
141
+ return;
142
+ }
143
+ // If we built the project, update the log message.
144
+ if (buildTime) {
145
+ process.stdout.write(
146
+ successMessage(
147
+ Date.now() - buildTime,
148
+ fileNotFoundMessage(path).length + 1,
149
+ ),
150
+ );
151
+ }
152
+ return res.sendFile(path, {root: './'});
109
153
  }
110
154
  exports.player = player;
package/dist/server.js ADDED
@@ -0,0 +1,109 @@
1
+ 'use strict';
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : {default: mod};
6
+ };
7
+ Object.defineProperty(exports, '__esModule', {value: true});
8
+ const renderer_1 = require('@revideo/renderer');
9
+ const axios_1 = __importDefault(require('axios'));
10
+ const express_1 = __importDefault(require('express'));
11
+ const fs_1 = require('fs');
12
+ const path_1 = __importDefault(require('path'));
13
+ const uuid_1 = require('uuid');
14
+ const App = (0, express_1.default)();
15
+ const Port = process.env.REVIDEO_PORT || 3000;
16
+ App.use(express_1.default.json());
17
+ App.post('/render', async (req, res) => {
18
+ const {variables, callbackUrl} = req.body;
19
+ if (!callbackUrl) {
20
+ return res.status(400).send('Callback URL is required.');
21
+ }
22
+ const jobId = (0, uuid_1.v4)();
23
+ res.json({jobId});
24
+ try {
25
+ const tempProjectName = (0, uuid_1.v4)();
26
+ await (0, renderer_1.renderVideo)(
27
+ process.env.PROJECT_FILE || '',
28
+ variables,
29
+ {
30
+ name: tempProjectName,
31
+ },
32
+ );
33
+ const resultFilePath = path_1.default.join(
34
+ process.cwd(),
35
+ `output/${tempProjectName}.mp4`,
36
+ );
37
+ const downloadLink = `${req.protocol}://${req.get('host')}/download/${tempProjectName}.mp4`;
38
+ const response = await axios_1.default.post(
39
+ callbackUrl,
40
+ {
41
+ jobId,
42
+ status: 'success',
43
+ downloadLink,
44
+ },
45
+ {
46
+ headers: {
47
+ // eslint-disable-next-line
48
+ 'Content-Type': 'application/json',
49
+ },
50
+ },
51
+ );
52
+ if (response.status !== 200) {
53
+ throw new Error('Callback URL responded with an error');
54
+ }
55
+ scheduleCleanup(resultFilePath);
56
+ } catch (error) {
57
+ console.error(error);
58
+ await axios_1.default.post(
59
+ callbackUrl,
60
+ {
61
+ jobId,
62
+ status: 'error',
63
+ error: error.message,
64
+ },
65
+ {
66
+ headers: {
67
+ // eslint-disable-next-line
68
+ 'Content-Type': 'application/json',
69
+ },
70
+ },
71
+ );
72
+ }
73
+ });
74
+ App.get('/download/:projectName', async (req, res) => {
75
+ const {projectName} = req.params;
76
+ const resultFilePath = path_1.default.join(
77
+ process.cwd(),
78
+ `output/${projectName}`,
79
+ );
80
+ try {
81
+ await fs_1.promises.access(resultFilePath);
82
+ res.download(resultFilePath, `${projectName}`, async err => {
83
+ if (err) {
84
+ console.error(err);
85
+ res.status(500).send('Error downloading the file.');
86
+ }
87
+ });
88
+ } catch (error) {
89
+ console.error(`File not found ${resultFilePath}:`, error);
90
+ res.status(404).send('File not found.');
91
+ }
92
+ });
93
+ App.listen(Port, () => {
94
+ console.log(`Server running on port ${Port}`);
95
+ });
96
+ function scheduleCleanup(filePath) {
97
+ // wait 10 minutes before removing file
98
+ setTimeout(
99
+ async () => {
100
+ try {
101
+ await fs_1.promises.unlink(filePath);
102
+ console.log(`Successfully deleted file: ${filePath}`);
103
+ } catch (error) {
104
+ console.error(`Error deleting file ${filePath}: ${error}`);
105
+ }
106
+ },
107
+ 10 * 60 * 1000,
108
+ );
109
+ }
package/dist/utils.js CHANGED
@@ -1,18 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', {value: true});
3
3
  exports.scheduleCleanup = void 0;
4
- const fs_1 = require("fs");
4
+ const fs_1 = require('fs');
5
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);
6
+ const clean = async () => {
7
+ try {
8
+ await fs_1.promises.unlink(filePath);
9
+ console.log(`Successfully deleted file: ${filePath}`);
10
+ } catch (error) {
11
+ console.error(`Error deleting file ${filePath}: ${error}`);
12
+ }
13
+ };
14
+ // Wait 10 minutes before removing file.
15
+ setTimeout(clean, 10 * 60 * 1000);
17
16
  }
18
17
  exports.scheduleCleanup = scheduleCleanup;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revideo/cli",
3
- "version": "0.3.7-alpha.986+40c195c6",
3
+ "version": "0.3.7-beta.987+48e808f",
4
4
  "description": "A CLI for revideo",
5
5
  "main": "dist/index.js",
6
6
  "author": "revideo",
@@ -25,13 +25,13 @@
25
25
  "typescript": "^5.4.3"
26
26
  },
27
27
  "dependencies": {
28
- "@revideo/renderer": "^0.3.7-alpha.986+40c195c6",
29
- "@revideo/telemetry": "^0.3.7-alpha.986+40c195c6",
28
+ "@revideo/renderer": "^0.3.7-beta.987+48e808f",
29
+ "@revideo/telemetry": "^0.3.7-beta.987+48e808f",
30
30
  "chokidar": "^3.5.3",
31
31
  "commander": "^12.0.0",
32
32
  "cors": "^2.8.5",
33
33
  "express": "^4.19.2",
34
34
  "uuid": "^9.0.1"
35
35
  },
36
- "gitHead": "40c195c6ca30e24a57dac56d0c760ed5825b6f56"
36
+ "gitHead": "48e808fd7b34bb02659214d502b2b7765076a76b"
37
37
  }