botserver/boot.js

66 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-12-30 12:51:11 -03:00
#!/usr/bin/env node
const Fs = require('fs');
const Path = require('path');
const { exec } = require('child_process');
var pjson = require('./package.json');
// Displays version of Node JS being used at runtime and others attributes.
console.log(`[GB Runtime] BotServer = v${pjson.version}`);
console.log(`[GB Runtime] BotLib = v${pjson.dependencies.botlib}`);
console.log(`[GB Runtime] BotBuilder (MS) = v${pjson.dependencies.botbuilder}`);
console.log(`[GB Runtime] NodeJS = ${process.version}`);
console.log(`[GB Runtime] platform = ${process.platform}`);
console.log(`[GB Runtime] architecture = ${process.arch}`);
console.log(`[GB Runtime] argv = ${process.argv}`);
console.log(`[GB Runtime] debugPort = ${process.debugPort}`);
var now = () => {
2019-12-30 12:51:11 -03:00
return (new Date()).toISOString().replace(/T/, ' ').replace(/\..+/, '') + ' UTC';
}
2019-12-30 12:51:11 -03:00
try {
var run = () => {
console.log(`[GB Runtime] Initializing General Bots (BotServer)...`);
const GBServer = require("./dist/src/app").GBServer
console.log(`[GB Runtime] ${now()} - Running '${GBServer.name}' on '${__dirname}' directory`);
process.env.PWD = __dirname;
GBServer.run();
}
var processDist = () => {
if (!Fs.existsSync('dist')) {
2019-12-30 12:51:11 -03:00
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')) {
2019-12-30 12:51:11 -03:00
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);
}