botserver/boot.mjs

59 lines
2 KiB
JavaScript
Raw Normal View History

2019-12-30 12:51:11 -03:00
#!/usr/bin/env node
import Fs from 'fs';
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.
console.log(``);
console.log(``);
console.log(``);
2023-02-24 13:37:06 -03:00
console.log(` █████ ██████ ███ ██ ██████ █████ █████ ██ █████ █████ ██████ ███ ® `);
console.log(` ██ ███ ██ █ ██ █ ██ ██ █ ██ ██ ███ ███ ██ ██████ █ * * █ ██ █ `);
console.log(` ██████ ██████ ██ ███ ██████ ██ ██ ██ ██ █████ █████ █████ ██ ████ 3.0`);
console.log(``);
2023-02-24 13:31:40 -03:00
console.debug(`botserver@${pjson.version}, botlib@${pjson.dependencies.botlib}, botbuilder@${pjson.dependencies.botbuilder}, nodeJS: ${process.version}, platform: ${process.platform}, architecture: ${process.arch}.`);
var now = () => {
return new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '') + ' UTC';
};
var __dirname = process.env.PWD;
2019-12-30 12:51:11 -03:00
try {
var run = () => {
import('./dist/src/app.js').then((gb)=> gb.GBServer.run());
};
var processDist = () => {
if (!Fs.existsSync('dist')) {
console.log(`${now()} - 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(`${now()} - 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);
}