Upload install_and_run.js
Browse files- install_and_run.js +20 -18
install_and_run.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
const zipUrl = process.env.ZIP_URL;
|
| 6 |
const downloadPath = '/tmp/app.zip';
|
| 7 |
const extractPath = '/app';
|
| 8 |
|
| 9 |
async function runCommand(command) {
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
});
|
| 22 |
-
});
|
| 23 |
}
|
| 24 |
|
| 25 |
async function main() {
|
|
@@ -36,7 +38,7 @@ async function main() {
|
|
| 36 |
await runCommand(`unzip -o ${downloadPath} -d ${extractPath}`);
|
| 37 |
|
| 38 |
console.log("Removing downloaded ZIP file...");
|
| 39 |
-
await
|
| 40 |
|
| 41 |
console.log("Starting the application...");
|
| 42 |
await runCommand('npm start');
|
|
@@ -47,4 +49,4 @@ async function main() {
|
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
| 50 |
-
main();
|
|
|
|
| 1 |
+
import { exec } from 'child_process';
|
| 2 |
+
import { promisify } from 'util';
|
| 3 |
+
import { unlink } from 'fs/promises';
|
| 4 |
+
import path from 'path';
|
| 5 |
+
import { fileURLToPath } from 'url';
|
| 6 |
+
|
| 7 |
+
const execAsync = promisify(exec);
|
| 8 |
|
| 9 |
const zipUrl = process.env.ZIP_URL;
|
| 10 |
const downloadPath = '/tmp/app.zip';
|
| 11 |
const extractPath = '/app';
|
| 12 |
|
| 13 |
async function runCommand(command) {
|
| 14 |
+
try {
|
| 15 |
+
const { stdout, stderr } = await execAsync(command);
|
| 16 |
+
console.log(`Command executed successfully: ${command}`);
|
| 17 |
+
if (stdout) console.log(stdout);
|
| 18 |
+
if (stderr) console.error(stderr);
|
| 19 |
+
return stdout;
|
| 20 |
+
} catch (error) {
|
| 21 |
+
console.error(`Error executing command: ${command}`);
|
| 22 |
+
console.error(error.stderr || error.message);
|
| 23 |
+
throw error;
|
| 24 |
+
}
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
|
| 27 |
async function main() {
|
|
|
|
| 38 |
await runCommand(`unzip -o ${downloadPath} -d ${extractPath}`);
|
| 39 |
|
| 40 |
console.log("Removing downloaded ZIP file...");
|
| 41 |
+
await unlink(downloadPath);
|
| 42 |
|
| 43 |
console.log("Starting the application...");
|
| 44 |
await runCommand('npm start');
|
|
|
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|
| 52 |
+
main();
|