new(all): Review order of boot.mjs and imports calls from compiled js #302 and new boot logo.

This commit is contained in:
rodrigorodriguez 2023-02-24 10:18:04 -03:00
parent a0211ff441
commit 2f9d07908f
7 changed files with 108 additions and 78 deletions

7
.vscode/launch.json vendored
View file

@ -9,10 +9,13 @@
"program": "${workspaceRoot}/boot.mjs",
"cwd": "${workspaceRoot}",
"env": {
"NODE_ENV": "development"
"NODE_ENV": "development",
"NODE_NO_WARNINGS":"1"
},
"args": [
"--no-deprecation"
"--no-deprecation",
"--loader ts-node/esm",
"--require ${workspaceRoot}/suppress-node-warnings.cjs",
],
"skipFiles": [
"node_modules/**/*.js"

View file

@ -3,63 +3,60 @@
import Fs from 'fs';
import Path from 'path';
import { exec } from 'child_process';
import pjson from './package.json' assert { type: "json" };
import * as GBServer from "./dist/src/app.js";
import pjson from './package.json' assert { type: '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}`);
console.log(``);
console.log(``);
console.log(``);
console.log(` ██████ ███████ ███ ██ ███████ ██████ █████ ██ ██████ ██████ ████████ ███████ ®`);
console.log(`██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ `);
console.log(`██ ███ █████ ██ ██ ██ █████ ██████ ███████ ██ ██████ ██ ██ ██ ███████ `);
console.log(`██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ `);
console.log(` ██████ ███████ ██ ████ ███████ ██ ██ ██ ██ ███████ ██████ ██████ ██ ███████ 3.0`);
console.log(``);
console.log(`botserver@${pjson.version}, botlib@${pjson.dependencies.botlib}, botbuilder@${pjson.dependencies.botbuilder}, nodeJS: ${process.version}, platform: ${process.platform}, architecture: ${process.arch}.`);
console.log(``);
console.log(``);
var now = () => {
return (new Date()).toISOString().replace(/T/, ' ').replace(/\..+/, '') + ' UTC';
}
return new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '') + ' UTC';
};
var __dirname = process.env.PWD;
try {
var run = () => {
console.log(`[GB Runtime] Initializing General Bots (BotServer)...`);
console.log(`[GB Runtime] ${now()} - Running on '${import.meta.url}'`);
GBServer.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();
});
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;
}
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();
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();
}
} catch (e) {
console.log(e);
console.log(e);
}

View file

@ -1,5 +1,2 @@
echo General Bots
echo Installing modules for the first time...
npm i
node .
echo Starting General Bots...
node boot.mjs --no-warnings

View file

@ -34,7 +34,7 @@
"build-gbui": "cd packages/default.gbui && echo SKIP_PREFLIGHT_CHECK=true >.env && npm install && npm run build",
"build-docs": "typedoc --options typedoc.json src/",
"test": "node test.js",
"start": "node ./boot.cjs",
"start": "NODE_NO_WARNINGS=1 node ./boot.mjs --loader ts-node/esm --require ./suppress-node-warnings.cjs ",
"reverse-proxy": "node_modules/.bin/ngrok http 4242",
"watch:build": "tsc --watch",
"posttypedoc": "shx cp .nojekyll docs/reference/.nojekyll",

View file

@ -144,7 +144,7 @@ export class GBMinService {
if (process.env.DISABLE_WEB !== 'true') {
// SSR processing and default.gbui access definition.
GBServer.globals.server.get('/', async (req, res, next)=> {
GBServer.globals.server.get('/', async (req, res, next) => {
await GBSSR.ssrFilter(req, res, next);
});
@ -225,11 +225,43 @@ export class GBMinService {
const url = `/api/messages/${botId}`;
removeRoute(GBServer.globals.server, url);
const uiUrl = `/${botId}`;
removeRoute(GBServer.globals.server, uiUrl);
GBServer.globals.minInstances = GBServer.globals.minInstances.filter(p => p.instance.botId !== botId);
}
/**
* Mount the bot web site (default.gbui) secure domain.
*/
public async loadDomain(min: GBMinInstance) {
// TODO: https://github.com/GeneralBots/BotServer/issues/321
const options = {
passphrase: process.env.CERTIFICATE2_PASSPHRASE,
pfx: Fs.readFileSync(process.env.CERTIFICATE2_PFX)
};
const domain = min.core.getParam(min.instance, 'Domain', null);
if (domain) {
GBServer.globals.server.get(domain, async (req, res, next) => {
await GBSSR.ssrFilter(req, res, next);
});
GBLog.verbose(`Bot UI ${GBMinService.uiPackage} accessible at custom domain: ${domain}.`);
}
GBServer.globals.httpsServer.addContext(process.env.CERTIFICATE2_DOMAIN, options);
}
/**
* Unmounts the bot web site (default.gbui) secure domain, if any.
*/
public async unloadDomain(instance: IGBInstance) {
}
/**
@ -364,23 +396,15 @@ export class GBMinService {
if (process.env.DISABLE_WEB !== 'true') {
const uiUrl = `/${instance.botId}`;
GBServer.globals.server.get(uiUrl, async (req, res, next)=> {
GBServer.globals.server.get(uiUrl, async (req, res, next) => {
await GBSSR.ssrFilter(req, res, next);
});
const uiUrlAlt = `/${instance.activationCode}`;
GBServer.globals.server.get(uiUrlAlt, async (req, res, next)=> {
GBServer.globals.server.get(uiUrlAlt, async (req, res, next) => {
await GBSSR.ssrFilter(req, res, next);
});
const domain = min.core.getParam(min.instance, 'Domain', null);
if (domain) {
GBServer.globals.server.get(domain, async (req, res, next)=> {
await GBSSR.ssrFilter(req, res, next);
});
GBLog.verbose(`Bot UI ${GBMinService.uiPackage} accessible at custom domain: ${domain}.`);
}
GBLog.verbose(`Bot UI ${GBMinService.uiPackage} accessible at: ${uiUrl} and ${uiUrlAlt}.`);
}
@ -879,7 +903,6 @@ export class GBMinService {
data: data.slice(0, 10)
});
}
}
// Required for MSTEAMS handling of persisted conversations.
@ -918,7 +941,7 @@ export class GBMinService {
if (startDialog) {
await sec.setParam(userId, 'welcomed', 'true');
GBLog.info(`Auto start (teams) dialog is now being called: ${startDialog} for ${min.instance.botId}...`);
await GBVMService.callVM(startDialog.toLowerCase(), min, step, user, this.deployer, false);
await GBVMService.callVM(startDialog.toLowerCase(), min, step, user, this.deployer, false);
}
}
}
@ -994,7 +1017,6 @@ export class GBMinService {
await this.processEventActivity(min, user, context, step);
}
} catch (error) {
const msg = `ERROR: ${error.message} ${error.stack ? error.stack : ''}`;
GBLog.error(msg);
@ -1120,7 +1142,7 @@ export class GBMinService {
const member = context.activity.from;
let user = await sec.ensureUser(min.instance.instanceId, member.id, member.name, '', 'web', member.name, null);
const userId = user.userId;
const params = user.params ? JSON.parse(user.params) : {};
@ -1137,7 +1159,6 @@ export class GBMinService {
user.conversationId = conversation.Id;
}
message = await analytics.createMessage(
min.instance.instanceId,
user.conversationId,
@ -1206,7 +1227,7 @@ export class GBMinService {
await min.conversationalService.sendEvent(min, step, 'loadInstance', {});
} else if (cmdOrDialogName === '/call') {
await GBVMService.callVM(args, min, step, user, this.deployer, false);
await GBVMService.callVM(args, min, step, user, this.deployer, false);
} else if (cmdOrDialogName === '/callsch') {
await GBVMService.callVM(args, min, null, null, null, false);
} else if (cmdOrDialogName === '/calldbg') {

View file

@ -36,6 +36,9 @@
'use strict';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
import Path from 'path';
import Fs from 'fs';
import { NextFunction, Request, Response } from 'express';
@ -43,11 +46,9 @@ import urljoin from 'url-join';
import { GBMinInstance } from 'botlib';
import { GBServer } from '../../../src/app.js';
import { GBLogEx } from './GBLogEx.js';
import { createRequire } from 'module';
import urlJoin from 'url-join';
import { GBDeployer } from './GBDeployer.js';
import { GBMinService } from './GBMinService.js';
const require = createRequire(import.meta.url);
const puppeteer = require('puppeteer-extra');
const hidden = require('puppeteer-extra-plugin-stealth');
const { executablePath } = require('puppeteer');

View file

@ -0,0 +1,11 @@
// inspired by
// https://github.com/nodejs/node/issues/30810#issuecomment-1383184769
const { emit: originalEmit } = process;
function suppresser(event, error) {
return event === 'warning' && error.name === 'ExperimentalWarning'
? false
: originalEmit.apply(process, arguments);
}
process.emit = suppresser;