Skip to content

Commit

Permalink
fix(core.gbapp): .gbapp now can be debugged within .ts files.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Jul 20, 2020
1 parent 4ba3db7 commit 10990e6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 53 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"type": "node",
"request": "launch",
"sourceMaps": true,
"name": "Debug Program",
"program": "${workspaceRoot}/boot.js",
"cwd": "${workspaceRoot}",
Expand Down
2 changes: 1 addition & 1 deletion packages/admin.gbapp/services/GBAdminService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export class GBAdminService implements IGBAdminService {
if (packageType !== '.gbot') {
let s = new GBSharePointService();

let localFolder = Path.join('work', Path.basename(folderName));
let localFolder = Path.join('work', `${min.instance.botId}.gbai`, Path.basename(folderName));
GBLog.warn(`${GBConfigService.get('CLOUD_USERNAME')} must be authorized on SharePoint related site`);
await s.downloadFolder(localFolder, siteName, folderName,
GBConfigService.get('CLOUD_USERNAME'), GBConfigService.get('CLOUD_PASSWORD'))
Expand Down
63 changes: 17 additions & 46 deletions packages/core.gbapp/services/GBDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ export class GBDeployer implements IGBDeployer {
public async deployPackages(core: IGBCoreService, server: any, appPackages: IGBPackage[]) {
const _this = this;


GBLog.info(`PWD ${process.env.PWD}...`);
let totalPackages = 0;
let paths = [urlJoin(process.env.PWD, GBDeployer.deployFolder), urlJoin(process.env.PWD, GBDeployer.workFolder)];
const additionalPath = GBConfigService.get('ADDITIONAL_DEPLOY_PATH');
if (additionalPath !== undefined && additionalPath !== '') {
Expand Down Expand Up @@ -151,14 +148,12 @@ export class GBDeployer implements IGBDeployer {

GBLog.info(`App Package deployment done.`);

({ generalPackages, totalPackages } = await this.deployDataPackages(
({ generalPackages } = await this.deployDataPackages(

core,
botPackages,
_this,
generalPackages,
server,
totalPackages
generalPackages
));

}
Expand Down Expand Up @@ -337,7 +332,7 @@ export class GBDeployer implements IGBDeployer {
}
GBServer.globals.minService.unmountBot(botId);
await this.core.deleteInstance(botId);
const packageFolder = Path.join(process.env.PWD, 'work', packageName);
const packageFolder = Path.join(process.env.PWD, 'work', `${botId}.gbai`, packageName);
}
public async deployPackageToStorage(instanceId: number, packageName: string): Promise<GuaribasPackage> {
return GuaribasPackage.create({
Expand Down Expand Up @@ -373,8 +368,8 @@ export class GBDeployer implements IGBDeployer {
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
if (pck = await e.onExchangeData(min, "handlePackage", {
name: localPath,
createPackage: async () => {
return await _this.deployPackageToStorage(min.instance.instanceId, localPath);
createPackage: async (packageName) => {
return await _this.deployPackageToStorage(min.instance.instanceId, packageName);
}, updatePackage: async (p: GuaribasPackage) => {
p.save();
}
Expand Down Expand Up @@ -540,10 +535,7 @@ export class GBDeployer implements IGBDeployer {
core: IGBCoreService,
botPackages: string[],
_this: this,
generalPackages: string[],
server: any,
totalPackages: number

generalPackages: string[]
) {
try {
await core.syncDatabaseStructure();
Expand All @@ -563,44 +555,23 @@ export class GBDeployer implements IGBDeployer {

// Then all remaining generalPackages are loaded.

generalPackages = generalPackages.filter(p => !p.endsWith('.git'));
await CollectionUtil.asyncForEach(generalPackages, async filename => {
const filenameOnly = Path.basename(filename);
GBLog.info(`Deploying package: ${filename}...`);

// Handles apps for general bots - .gbapp must stay out of deploy folder.

if (Path.extname(filename) === '.gbapp' || Path.extname(filename) === '.gblib') {
// Themes for bots.
} else if (Path.extname(filename) === '.gbtheme') {
} else if (Path.extname(filename) === '.gbkb') {
this.mountGBKBAssets(filenameOnly, filename);
} else if (Path.extname(filename) === '.gbui') {
// Already Handled
} else if (Path.extname(filename) === '.gbdialog') {
// Already Handled
} else if (Path.extname(filename) === '.gbignore') {
// Ignored
} else {
// Unknown package format.
const err = new Error(`Package type not handled: ${filename}.`);
throw err;
const instances = core.loadInstances();
await CollectionUtil.asyncForEach(instances, async instance => {

}
totalPackages++;
this.mountGBKBAssets(`{instance.botId}.gbkb`, instance.botId, `{instance.botId}.gbkb`);
});

GBLog.info(`Package deployment done.`);
return { generalPackages, totalPackages };
return { generalPackages};
}

public mountGBKBAssets(packageName: any, filename: string) {
GBServer.globals.server.use(`/kb/${packageName}/subjects`, express.static(urlJoin(filename, 'subjects')));
GBServer.globals.server.use(`/kb/${packageName}/assets`, express.static(urlJoin(filename, 'assets')));
GBServer.globals.server.use(`/kb/${packageName}/images`, express.static(urlJoin(filename, 'images')));
GBServer.globals.server.use(`/kb/${packageName}/audios`, express.static(urlJoin(filename, 'audios')));
GBServer.globals.server.use(`/kb/${packageName}/videos`, express.static(urlJoin(filename, 'videos')));
GBLog.info(`KB (.gbkb) assets accessible at: /kb/${packageName}.`);
public mountGBKBAssets(packageName: any, botId: string, filename: string) {
GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/subjects`, express.static(urlJoin(filename, 'subjects')));
GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/assets`, express.static(urlJoin(filename, 'assets')));
GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/images`, express.static(urlJoin(filename, 'images')));
GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/audios`, express.static(urlJoin(filename, 'audios')));
GBServer.globals.server.use(`/kb/${botId}.gbai/${packageName}/videos`, express.static(urlJoin(filename, 'videos')));
GBLog.info(`KB (.gbkb) assets accessible at: /kb/${botId}.gbai/${packageName}.`);
}

private isSystemPackage(name: string): Boolean {
Expand Down
8 changes: 4 additions & 4 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,19 @@ export class GBMinService {

// Install per bot deployed packages.

let packagePath = `work/${min.botId}.gbdialog`;
let packagePath = `work/${min.botId}.gbai/${min.botId}.gbdialog`;
if (fs.existsSync(packagePath)) {
await this.deployer.deployPackage(min, packagePath);
}
packagePath = `work/${min.botId}.gbapp`;
packagePath = `work/${min.botId}.gbai/${min.botId}.gbapp`;
if (fs.existsSync(packagePath)) {
await this.deployer.deployPackage(min, packagePath);
}
packagePath = `work/${min.botId}.gbtheme`;
packagePath = `work/${min.botId}.gbai/${min.botId}.gbtheme`;
if (fs.existsSync(packagePath)) {
await this.deployer.deployPackage(min, packagePath);
}
packagePath = `work/${min.botId}.gblib`;
packagePath = `work/${min.botId}.gbai/${min.botId}.gblib`;
if (fs.existsSync(packagePath)) {
await this.deployer.deployPackage(min, packagePath);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/kb.gbapp/services/KBService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ export class KBService implements IGBKBService {
GBLog.info(`[GBDeployer] Importing: ${localPath}`);
const p = await deployer.deployPackageToStorage(instance.instanceId, packageName);
await this.importKbPackage(localPath, p, instance);
deployer.mountGBKBAssets(packageName, localPath);
deployer.mountGBKBAssets(packageName,min.botId, localPath);

await deployer.rebuildIndex(instance, new AzureDeployerService(deployer).getKBSearchSchema(instance.searchIndex));
GBLog.info(`[GBDeployer] Finished import of ${localPath}`);
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class GBServer {
GBLog.info(`Defining server address at ${serverAddress}...`);
GBServer.globals.publicAddress = serverAddress;
}

// Creates a boot instance or load it from storage.

try {
Expand Down

0 comments on commit 10990e6

Please sign in to comment.