botserver/boot.mjs

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-12-30 12:51:11 -03:00
#!/usr/bin/env node
import Fs from 'fs';
import os from 'node:os';
import Path from 'path';
import { exec } from 'child_process';
import pjson from './package.json' assert { type: 'json' };
// Displays version of Node JS being used at runtime and others attributes.
2024-08-20 15:13:43 -03:00
process.stdout.write(`General Bots. BotServer@${pjson.version}, botlib@${pjson.dependencies.botlib}, node@${process.version.replace('v', '')}, ${process.platform} ${process.arch} `);
console.log(`\nLoading virtual machine source code files...`);
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 {
var run = () => {
2023-02-26 06:05:57 -03:00
import('./dist/src/app.js').then((gb)=> {
gb.GBServer.run()
});
};
var processDist = () => {
if (!Fs.existsSync('dist')) {
console.log(`\n`);
console.log(`Generall Bots: Compiling...`);
exec(Path.join(__dirname, 'node_modules/.bin/tsc'), (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
run();
});
} else {
run();
}
};
// Installing modules if it has not been done yet.
if (!Fs.existsSync('node_modules')) {
console.log(`\n`);
console.log(`Generall Bots: Installing modules for the first time, please wait...`);
exec('npm install', (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
processDist();
});
} else {
processDist();
}
2019-12-30 12:51:11 -03:00
} catch (e) {
console.log(e);
}