2019-12-30 12:51:11 -03:00
|
|
|
#!/usr/bin/env node
|
2019-07-23 14:41:39 +00:00
|
|
|
|
2025-04-25 02:24:52 -03:00
|
|
|
process.stdout.write(`General Bots 5 VM: node@${process.version.replace('v', '')}, ${process.platform} ${process.arch} `);
|
2024-08-26 20:04:12 -03:00
|
|
|
|
2024-09-07 18:13:36 -03:00
|
|
|
import fs from 'fs/promises';
|
2024-03-13 20:12:05 -03:00
|
|
|
import os from 'node:os';
|
2024-09-06 15:30:03 -03:00
|
|
|
import path from 'path';
|
2022-11-18 22:39:14 -03:00
|
|
|
import { exec } from 'child_process';
|
2024-09-24 16:44:03 -03:00
|
|
|
|
|
|
|
import {GBUtil} from './dist/src/util.js'
|
2024-08-23 17:23:22 -03:00
|
|
|
|
2020-01-08 17:52:46 -03:00
|
|
|
// Displays version of Node JS being used at runtime and others attributes.
|
2023-04-09 19:20:15 -03:00
|
|
|
|
2024-09-15 14:41:56 -03:00
|
|
|
console.log(`\nLoading General Bots VM...`);
|
2024-03-13 09:04:30 -03:00
|
|
|
|
2023-02-24 19:26:09 -03:00
|
|
|
var __dirname = process.env.PWD || process.cwd();
|
2019-12-30 12:51:11 -03:00
|
|
|
try {
|
2024-09-07 18:13:36 -03:00
|
|
|
var run = async () => {
|
2024-01-13 14:23:04 -03:00
|
|
|
|
2024-09-24 16:44:03 -03:00
|
|
|
import('./dist/src/app.js').then(async (gb)=> {
|
2024-09-07 18:13:36 -03:00
|
|
|
await gb.GBServer.run()
|
2023-02-26 06:05:57 -03:00
|
|
|
});
|
2023-02-24 10:18:04 -03:00
|
|
|
};
|
2024-09-07 18:13:36 -03:00
|
|
|
var processDist = async () => {
|
2024-09-24 16:44:03 -03:00
|
|
|
if (!await GBUtil.exists('dist')) {
|
|
|
|
console.log(`\n`);
|
|
|
|
console.log(`General Bots: Compiling...`);
|
|
|
|
exec(path.join(__dirname, 'node_modules/.bin/tsc'), async (err, stdout, stderr) => {
|
|
|
|
if (err) {
|
|
|
|
console.error(err);
|
|
|
|
return;
|
|
|
|
}
|
2024-09-07 18:13:36 -03:00
|
|
|
await run();
|
2024-09-24 16:44:03 -03:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
await run();
|
|
|
|
}
|
2023-02-24 10:18:04 -03:00
|
|
|
};
|
2019-07-23 14:41:39 +00:00
|
|
|
|
2023-02-24 10:18:04 -03:00
|
|
|
// Installing modules if it has not been done yet.
|
2020-01-08 17:52:46 -03:00
|
|
|
|
2024-09-07 18:13:36 -03:00
|
|
|
if (!await GBUtil.exists('node_modules')) {
|
2023-03-26 19:33:58 -03:00
|
|
|
console.log(`\n`);
|
2024-09-15 14:41:56 -03:00
|
|
|
console.log(`General Bots: Installing modules for the first time, please wait...`);
|
2024-09-07 18:13:36 -03:00
|
|
|
exec('npm install', async (err, stdout, stderr) => {
|
2023-02-24 10:18:04 -03:00
|
|
|
if (err) {
|
|
|
|
console.error(err);
|
|
|
|
return;
|
|
|
|
}
|
2024-09-07 18:13:36 -03:00
|
|
|
await processDist();
|
2023-02-24 10:18:04 -03:00
|
|
|
});
|
|
|
|
} else {
|
2024-09-07 18:13:36 -03:00
|
|
|
await processDist();
|
2023-02-24 10:18:04 -03:00
|
|
|
}
|
2019-12-30 12:51:11 -03:00
|
|
|
} catch (e) {
|
2023-02-24 10:18:04 -03:00
|
|
|
console.log(e);
|
2019-07-23 14:41:39 +00:00
|
|
|
}
|