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", "program": "${workspaceRoot}/boot.mjs",
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"env": { "env": {
"NODE_ENV": "development" "NODE_ENV": "development",
"NODE_NO_WARNINGS":"1"
}, },
"args": [ "args": [
"--no-deprecation" "--no-deprecation",
"--loader ts-node/esm",
"--require ${workspaceRoot}/suppress-node-warnings.cjs",
], ],
"skipFiles": [ "skipFiles": [
"node_modules/**/*.js" "node_modules/**/*.js"

View file

@ -3,63 +3,60 @@
import Fs from 'fs'; import Fs from 'fs';
import Path from 'path'; import Path from 'path';
import { exec } from 'child_process'; import { exec } from 'child_process';
import pjson from './package.json' assert { type: "json" }; import pjson from './package.json' assert { type: 'json' };
import * as GBServer from "./dist/src/app.js";
// Displays version of Node JS being used at runtime and others attributes. // 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 = () => { var now = () => {
return (new Date()).toISOString().replace(/T/, ' ').replace(/\..+/, '') + ' UTC'; return new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '') + ' UTC';
} };
var __dirname = process.env.PWD; var __dirname = process.env.PWD;
try { try {
var run = () => {
var run = () => { import('./dist/src/app.js').then((gb)=> gb.GBServer.run());
};
console.log(`[GB Runtime] Initializing General Bots (BotServer)...`); var processDist = () => {
console.log(`[GB Runtime] ${now()} - Running on '${import.meta.url}'`); if (!Fs.existsSync('dist')) {
GBServer.GBServer.run(); console.log(`${now()} - Compiling...`);
} exec(Path.join(__dirname, 'node_modules/.bin/tsc'), (err, stdout, stderr) => {
var processDist = () => { if (err) {
if (!Fs.existsSync('dist')) { console.error(err);
console.log(`${now()} - Compiling...`); return;
exec(Path.join(__dirname, 'node_modules/.bin/tsc'), (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
run();
});
} }
else { run();
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();
} }
};
// 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) { } catch (e) {
console.log(e); console.log(e);
} }

View file

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

View file

@ -34,7 +34,7 @@
"build-gbui": "cd packages/default.gbui && echo SKIP_PREFLIGHT_CHECK=true >.env && npm install && npm run build", "build-gbui": "cd packages/default.gbui && echo SKIP_PREFLIGHT_CHECK=true >.env && npm install && npm run build",
"build-docs": "typedoc --options typedoc.json src/", "build-docs": "typedoc --options typedoc.json src/",
"test": "node test.js", "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", "reverse-proxy": "node_modules/.bin/ngrok http 4242",
"watch:build": "tsc --watch", "watch:build": "tsc --watch",
"posttypedoc": "shx cp .nojekyll docs/reference/.nojekyll", "posttypedoc": "shx cp .nojekyll docs/reference/.nojekyll",

View file

@ -144,7 +144,7 @@ export class GBMinService {
if (process.env.DISABLE_WEB !== 'true') { if (process.env.DISABLE_WEB !== 'true') {
// SSR processing and default.gbui access definition. // 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); await GBSSR.ssrFilter(req, res, next);
}); });
@ -225,11 +225,43 @@ export class GBMinService {
const url = `/api/messages/${botId}`; const url = `/api/messages/${botId}`;
removeRoute(GBServer.globals.server, url); removeRoute(GBServer.globals.server, url);
const uiUrl = `/${botId}`; const uiUrl = `/${botId}`;
removeRoute(GBServer.globals.server, uiUrl); removeRoute(GBServer.globals.server, uiUrl);
GBServer.globals.minInstances = GBServer.globals.minInstances.filter(p => p.instance.botId !== botId); 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') { if (process.env.DISABLE_WEB !== 'true') {
const uiUrl = `/${instance.botId}`; 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); await GBSSR.ssrFilter(req, res, next);
}); });
const uiUrlAlt = `/${instance.activationCode}`; 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); 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}.`); GBLog.verbose(`Bot UI ${GBMinService.uiPackage} accessible at: ${uiUrl} and ${uiUrlAlt}.`);
} }
@ -879,7 +903,6 @@ export class GBMinService {
data: data.slice(0, 10) data: data.slice(0, 10)
}); });
} }
} }
// Required for MSTEAMS handling of persisted conversations. // Required for MSTEAMS handling of persisted conversations.
@ -918,7 +941,7 @@ export class GBMinService {
if (startDialog) { if (startDialog) {
await sec.setParam(userId, 'welcomed', 'true'); await sec.setParam(userId, 'welcomed', 'true');
GBLog.info(`Auto start (teams) dialog is now being called: ${startDialog} for ${min.instance.botId}...`); 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); await this.processEventActivity(min, user, context, step);
} }
} catch (error) { } catch (error) {
const msg = `ERROR: ${error.message} ${error.stack ? error.stack : ''}`; const msg = `ERROR: ${error.message} ${error.stack ? error.stack : ''}`;
GBLog.error(msg); GBLog.error(msg);
@ -1120,7 +1142,7 @@ export class GBMinService {
const member = context.activity.from; const member = context.activity.from;
let user = await sec.ensureUser(min.instance.instanceId, member.id, member.name, '', 'web', member.name, null); let user = await sec.ensureUser(min.instance.instanceId, member.id, member.name, '', 'web', member.name, null);
const userId = user.userId; const userId = user.userId;
const params = user.params ? JSON.parse(user.params) : {}; const params = user.params ? JSON.parse(user.params) : {};
@ -1137,7 +1159,6 @@ export class GBMinService {
user.conversationId = conversation.Id; user.conversationId = conversation.Id;
} }
message = await analytics.createMessage( message = await analytics.createMessage(
min.instance.instanceId, min.instance.instanceId,
user.conversationId, user.conversationId,
@ -1206,7 +1227,7 @@ export class GBMinService {
await min.conversationalService.sendEvent(min, step, 'loadInstance', {}); await min.conversationalService.sendEvent(min, step, 'loadInstance', {});
} else if (cmdOrDialogName === '/call') { } 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') { } else if (cmdOrDialogName === '/callsch') {
await GBVMService.callVM(args, min, null, null, null, false); await GBVMService.callVM(args, min, null, null, null, false);
} else if (cmdOrDialogName === '/calldbg') { } else if (cmdOrDialogName === '/calldbg') {

View file

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