@revideo/cli 0.3.3-alpha.981 → 0.3.3-final.955
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 +3 -8
- package/dist/server/index.js +3 -1
- package/dist/server/player.js +54 -19
- package/dist/server/render.js +71 -9
- package/dist/server.js +89 -0
- package/package.json +7 -4
package/dist/index.js
CHANGED
|
@@ -19,17 +19,12 @@ program
|
|
|
19
19
|
.option('--watchDir <path>', 'Directory to watch for changes', 'src')
|
|
20
20
|
.action(async (options) => {
|
|
21
21
|
(0, telemetry_1.sendEvent)(telemetry_1.EventName.CLICommand);
|
|
22
|
-
if (!options.projectFile) {
|
|
23
|
-
console.error('Error: --projectFile option must be specified.');
|
|
24
|
-
process.exit(1);
|
|
25
|
-
}
|
|
26
|
-
await (0, player_1.buildProject)().catch(() => {
|
|
27
|
-
console.error('Error building project');
|
|
28
|
-
process.exit(1);
|
|
29
|
-
});
|
|
30
22
|
const { projectFile, port } = options;
|
|
31
23
|
process.env.PROJECT_FILE = projectFile;
|
|
32
24
|
process.env.REVIDEO_PORT = port;
|
|
25
|
+
await (0, player_1.buildProject)().catch(() => {
|
|
26
|
+
process.exit(1);
|
|
27
|
+
});
|
|
33
28
|
(0, index_1.createServer)(options.watchDir).listen(port, () => {
|
|
34
29
|
console.log(`Server listening on port ${port}`);
|
|
35
30
|
console.log();
|
package/dist/server/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createServer = void 0;
|
|
7
|
+
const cors_1 = __importDefault(require("cors"));
|
|
7
8
|
const express_1 = __importDefault(require("express"));
|
|
8
9
|
const download_1 = require("./download");
|
|
9
10
|
const player_1 = require("./player");
|
|
@@ -11,9 +12,10 @@ const render_1 = require("./render");
|
|
|
11
12
|
function createServer(hotReloadDir) {
|
|
12
13
|
const app = (0, express_1.default)();
|
|
13
14
|
app.use(express_1.default.json());
|
|
15
|
+
app.use((0, cors_1.default)());
|
|
14
16
|
app.post('/render', render_1.render);
|
|
15
17
|
app.get('/download/:projectName', download_1.download);
|
|
16
|
-
app.
|
|
18
|
+
app.get('/player/:file', player_1.player);
|
|
17
19
|
if (hotReloadDir) {
|
|
18
20
|
(0, player_1.createHotReloader)(hotReloadDir);
|
|
19
21
|
}
|
package/dist/server/player.js
CHANGED
|
@@ -1,9 +1,33 @@
|
|
|
1
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) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.player = exports.createHotReloader = exports.buildProject = void 0;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
27
|
const chokidar_1 = require("chokidar");
|
|
6
28
|
const fs_1 = require("fs");
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
const vite_1 = require("vite");
|
|
7
31
|
const YELLOW_DOT = '\u001b[33m•\u001b[0m';
|
|
8
32
|
const GREEN_CHECK = '\u001b[32m✔\u001b[0m';
|
|
9
33
|
const RED_CROSS = '\u001b[31m✘\u001b[0m';
|
|
@@ -11,20 +35,27 @@ const fileNotFoundMessage = (filePath) => `${YELLOW_DOT} File ${filePath} not fo
|
|
|
11
35
|
const fileNotFoundAfterBuildingMessage = (filePath, padding) => `\r${RED_CROSS} File ${filePath} still not found after building project...`.padEnd(padding, ' ') + '\n';
|
|
12
36
|
const fileChangedMessage = (filePath) => `${YELLOW_DOT} File ${filePath} has changed. Rebuilding...`;
|
|
13
37
|
const successMessage = (time, padding) => `\r${GREEN_CHECK} Project built successfully. ${time}ms`.padEnd(padding, ' ') + '\n';
|
|
14
|
-
/**
|
|
15
|
-
* Runs `npm run build`.
|
|
16
|
-
*/
|
|
17
38
|
async function buildProject() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
39
|
+
try {
|
|
40
|
+
await (0, vite_1.build)({
|
|
41
|
+
configFile: path.join(process.cwd(), process.env.PROJECT_FILE || ''),
|
|
42
|
+
publicDir: false,
|
|
43
|
+
build: {
|
|
44
|
+
outDir: 'dist',
|
|
45
|
+
rollupOptions: {
|
|
46
|
+
output: {
|
|
47
|
+
entryFileNames: '[name].js',
|
|
48
|
+
chunkFileNames: '[name].js',
|
|
49
|
+
assetFileNames: '[name].[ext]',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
26
53
|
});
|
|
27
|
-
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error('Error building project:', error);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
28
59
|
}
|
|
29
60
|
exports.buildProject = buildProject;
|
|
30
61
|
/**
|
|
@@ -32,7 +63,9 @@ exports.buildProject = buildProject;
|
|
|
32
63
|
* @param dir - Directory to watch for changes.
|
|
33
64
|
*/
|
|
34
65
|
async function createHotReloader(dir) {
|
|
35
|
-
const watcher = (0, chokidar_1.watch)(dir
|
|
66
|
+
const watcher = (0, chokidar_1.watch)(dir, {
|
|
67
|
+
ignored: ['**/*.meta'],
|
|
68
|
+
});
|
|
36
69
|
watcher.on('change', async (path) => {
|
|
37
70
|
const rebuildingMessage = fileChangedMessage(path);
|
|
38
71
|
process.stdout.write(rebuildingMessage);
|
|
@@ -48,20 +81,22 @@ async function createHotReloader(dir) {
|
|
|
48
81
|
});
|
|
49
82
|
}
|
|
50
83
|
exports.createHotReloader = createHotReloader;
|
|
51
|
-
async function player(
|
|
52
|
-
const path =
|
|
84
|
+
async function player(req, res) {
|
|
85
|
+
const path = `./dist/${req.params.file}`;
|
|
53
86
|
let buildTime = undefined;
|
|
54
87
|
let error = false;
|
|
55
88
|
// Check if the file exists and build the project if it doesn't.
|
|
56
89
|
await fs_1.promises.access(path).catch(async () => {
|
|
57
90
|
buildTime = Date.now();
|
|
58
91
|
process.stdout.write(fileNotFoundMessage(path));
|
|
59
|
-
await buildProject()
|
|
92
|
+
await buildProject().catch(() => {
|
|
93
|
+
res.status(500).send('Error building project');
|
|
94
|
+
});
|
|
60
95
|
});
|
|
61
96
|
// If the file still doesn't exist, send an error response.
|
|
62
97
|
await fs_1.promises.access(path).catch(() => {
|
|
63
98
|
process.stdout.write(fileNotFoundAfterBuildingMessage(path, fileNotFoundMessage(path).length + 1));
|
|
64
|
-
res.status(
|
|
99
|
+
res.status(404).send(`File ${path} not found`);
|
|
65
100
|
error = true;
|
|
66
101
|
});
|
|
67
102
|
if (error) {
|
|
@@ -71,6 +106,6 @@ async function player(_, res) {
|
|
|
71
106
|
if (buildTime) {
|
|
72
107
|
process.stdout.write(successMessage(Date.now() - buildTime, fileNotFoundMessage(path).length + 1));
|
|
73
108
|
}
|
|
74
|
-
return res.sendFile(
|
|
109
|
+
return res.sendFile(path, { root: './' });
|
|
75
110
|
}
|
|
76
111
|
exports.player = player;
|
package/dist/server/render.js
CHANGED
|
@@ -10,21 +10,28 @@ const path_1 = __importDefault(require("path"));
|
|
|
10
10
|
const uuid_1 = require("uuid");
|
|
11
11
|
const utils_1 = require("../utils");
|
|
12
12
|
async function render(req, res) {
|
|
13
|
-
const {
|
|
14
|
-
if (
|
|
15
|
-
|
|
13
|
+
const { callbackUrl } = req.body;
|
|
14
|
+
if (callbackUrl) {
|
|
15
|
+
await renderWithCallback(req, res);
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
else {
|
|
18
|
+
await renderWithoutCallback(req, res);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.render = render;
|
|
22
|
+
async function renderWithCallback(req, res) {
|
|
23
|
+
const { variables, callbackUrl, settings } = req.body;
|
|
24
|
+
const tempProjectName = (0, uuid_1.v4)();
|
|
25
|
+
res.json({ tempProjectName });
|
|
19
26
|
try {
|
|
20
|
-
const tempProjectName = (0, uuid_1.v4)();
|
|
21
27
|
await (0, renderer_1.renderVideo)(process.env.PROJECT_FILE || '', variables, () => { }, {
|
|
28
|
+
...settings,
|
|
22
29
|
name: tempProjectName,
|
|
23
30
|
});
|
|
24
31
|
const resultFilePath = path_1.default.join(process.cwd(), `output/${tempProjectName}.mp4`);
|
|
25
32
|
const downloadLink = `${req.protocol}://${req.get('host')}/download/${tempProjectName}.mp4`;
|
|
26
33
|
const response = await axios_1.default.post(callbackUrl, {
|
|
27
|
-
|
|
34
|
+
tempProjectName,
|
|
28
35
|
status: 'success',
|
|
29
36
|
downloadLink,
|
|
30
37
|
}, {
|
|
@@ -41,7 +48,7 @@ async function render(req, res) {
|
|
|
41
48
|
catch (error) {
|
|
42
49
|
console.error(error);
|
|
43
50
|
await axios_1.default.post(callbackUrl, {
|
|
44
|
-
|
|
51
|
+
tempProjectName,
|
|
45
52
|
status: 'error',
|
|
46
53
|
error: error.message,
|
|
47
54
|
}, {
|
|
@@ -52,4 +59,59 @@ async function render(req, res) {
|
|
|
52
59
|
});
|
|
53
60
|
}
|
|
54
61
|
}
|
|
55
|
-
|
|
62
|
+
async function renderWithoutCallback(req, res) {
|
|
63
|
+
const { variables, streamProgress, settings } = req.body;
|
|
64
|
+
const tempProjectName = (0, uuid_1.v4)();
|
|
65
|
+
const resultFilePath = path_1.default.join(process.cwd(), `output/${tempProjectName}.mp4`);
|
|
66
|
+
if (streamProgress) {
|
|
67
|
+
res.writeHead(200, {
|
|
68
|
+
// eslint-disable-next-line
|
|
69
|
+
'Content-Type': 'text/event-stream',
|
|
70
|
+
// eslint-disable-next-line
|
|
71
|
+
'Cache-Control': 'no-cache',
|
|
72
|
+
// eslint-disable-next-line
|
|
73
|
+
Connection: 'keep-alive',
|
|
74
|
+
});
|
|
75
|
+
const sendProgress = (worker, progress) => {
|
|
76
|
+
res.write(`event: progress\n`);
|
|
77
|
+
res.write(`data: ${JSON.stringify({ worker, progress })}\n\n`);
|
|
78
|
+
};
|
|
79
|
+
try {
|
|
80
|
+
await (0, renderer_1.renderVideo)(process.env.PROJECT_FILE || '', variables, sendProgress, {
|
|
81
|
+
...settings,
|
|
82
|
+
name: tempProjectName,
|
|
83
|
+
});
|
|
84
|
+
const downloadLink = `${req.protocol}://${req.get('host')}/download/${tempProjectName}.mp4`;
|
|
85
|
+
res.write(`event: completed\n`);
|
|
86
|
+
res.write(`data: ${JSON.stringify({ status: 'success', downloadLink })}\n\n`);
|
|
87
|
+
res.end();
|
|
88
|
+
(0, utils_1.scheduleCleanup)(resultFilePath);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.error(error);
|
|
92
|
+
res.write(`event: error\n`);
|
|
93
|
+
res.write(`data: ${JSON.stringify({ status: 'error', message: error.message })}\n\n`);
|
|
94
|
+
res.end();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
try {
|
|
99
|
+
await (0, renderer_1.renderVideo)(process.env.PROJECT_FILE || '', variables, () => { }, {
|
|
100
|
+
name: tempProjectName,
|
|
101
|
+
});
|
|
102
|
+
const downloadLink = `${req.protocol}://${req.get('host')}/download/${tempProjectName}.mp4`;
|
|
103
|
+
res.json({
|
|
104
|
+
status: 'success',
|
|
105
|
+
downloadLink: downloadLink,
|
|
106
|
+
});
|
|
107
|
+
(0, utils_1.scheduleCleanup)(resultFilePath);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
console.error(error);
|
|
111
|
+
res.status(500).json({
|
|
112
|
+
status: 'error',
|
|
113
|
+
message: error.message,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
const renderer_1 = require("@revideo/renderer");
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const express_1 = __importDefault(require("express"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
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) => {
|
|
16
|
+
const { variables, callbackUrl } = req.body;
|
|
17
|
+
if (!callbackUrl) {
|
|
18
|
+
return res.status(400).send('Callback URL is required.');
|
|
19
|
+
}
|
|
20
|
+
const jobId = (0, uuid_1.v4)();
|
|
21
|
+
res.json({ jobId });
|
|
22
|
+
try {
|
|
23
|
+
const tempProjectName = (0, uuid_1.v4)();
|
|
24
|
+
await (0, renderer_1.renderVideo)(process.env.PROJECT_FILE || '', variables, {
|
|
25
|
+
name: tempProjectName,
|
|
26
|
+
});
|
|
27
|
+
const resultFilePath = path_1.default.join(process.cwd(), `output/${tempProjectName}.mp4`);
|
|
28
|
+
const downloadLink = `${req.protocol}://${req.get('host')}/download/${tempProjectName}.mp4`;
|
|
29
|
+
const response = await axios_1.default.post(callbackUrl, {
|
|
30
|
+
jobId,
|
|
31
|
+
status: 'success',
|
|
32
|
+
downloadLink,
|
|
33
|
+
}, {
|
|
34
|
+
headers: {
|
|
35
|
+
// eslint-disable-next-line
|
|
36
|
+
'Content-Type': 'application/json',
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
if (response.status !== 200) {
|
|
40
|
+
throw new Error('Callback URL responded with an error');
|
|
41
|
+
}
|
|
42
|
+
scheduleCleanup(resultFilePath);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error(error);
|
|
46
|
+
await axios_1.default.post(callbackUrl, {
|
|
47
|
+
jobId,
|
|
48
|
+
status: 'error',
|
|
49
|
+
error: error.message,
|
|
50
|
+
}, {
|
|
51
|
+
headers: {
|
|
52
|
+
// eslint-disable-next-line
|
|
53
|
+
'Content-Type': 'application/json',
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revideo/cli",
|
|
3
|
-
"version": "0.3.3-
|
|
3
|
+
"version": "0.3.3-final.955+b769002",
|
|
4
4
|
"description": "A CLI for revideo",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "revideo",
|
|
@@ -20,15 +20,18 @@
|
|
|
20
20
|
"types"
|
|
21
21
|
],
|
|
22
22
|
"devDependencies": {
|
|
23
|
+
"@types/cors": "^2.8.17",
|
|
23
24
|
"@types/express": "^4.17.21",
|
|
24
25
|
"typescript": "^5.4.3"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@revideo/renderer": "^0.3.3-
|
|
28
|
-
"@revideo/telemetry": "^0.3.3-
|
|
28
|
+
"@revideo/renderer": "^0.3.3-final.955+b769002",
|
|
29
|
+
"@revideo/telemetry": "^0.3.3-final.955+b769002",
|
|
30
|
+
"chokidar": "^3.5.3",
|
|
29
31
|
"commander": "^12.0.0",
|
|
32
|
+
"cors": "^2.8.5",
|
|
30
33
|
"express": "^4.19.2",
|
|
31
34
|
"uuid": "^9.0.1"
|
|
32
35
|
},
|
|
33
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "b769002f09e1a58f0b3795eedcc6ed1b625654b3"
|
|
34
37
|
}
|