Unverified Commit e7f66d3f authored by Bradley Hilton's avatar Bradley Hilton
Browse files

Update to the promises of everything

parent baa3a3b5
import { IAppActivationBridge } from '@rocket.chat/apps-engine/server/bridges';
import { ProxiedApp } from '@rocket.chat/apps-engine/server/ProxiedApp';
import { AppStatus } from '@rocket.chat/apps-ts-definition/AppStatus';
export class ServerAppActivationBridge implements IAppActivationBridge {
public appEnabled(app: ProxiedApp): void {
console.log(`The App ${ app.getName() } (${ app.getID() }) has been enabled.`);
public async appAdded(app: ProxiedApp): Promise<void> {
console.log(`The App ${ app.getName() } (${ app.getID() }) has been added.`);
}
public appDisabled(app: ProxiedApp): void {
console.log(`The App ${ app.getName() } (${ app.getID() }) has been disabled.`);
}
public appLoaded(app: ProxiedApp, enabled: boolean): void {
console.log(`The App ${ app.getName() } (${ app.getID() }) has been loaded.`);
}
public appUpdated(app: ProxiedApp, enabled: boolean): void {
public async appUpdated(app: ProxiedApp): Promise<void> {
console.log(`The App ${ app.getName() } (${ app.getID() }) has been updated.`);
}
public appRemoved(app: ProxiedApp): void {
public async appRemoved(app: ProxiedApp): Promise<void> {
console.log(`The App ${ app.getName() } (${ app.getID() }) has been removed.`);
}
public async appStatusChanged(app: ProxiedApp, status: AppStatus): Promise<void> {
console.log(`The App ${ app.getName() } (${ app.getID() }) status has changed to: ${ status }`);
}
}
......@@ -7,8 +7,10 @@ import {
AppBridges,
IAppActivationBridge,
IAppCommandBridge,
IAppDetailChangesBridge,
IEnvironmentalVariableBridge,
IHttpBridge,
IListenerBridge,
IMessageBridge,
IPersistenceBridge,
IRoomBridge,
......@@ -65,4 +67,12 @@ export class ServerAppBridges extends AppBridges {
public getUserBridge(): IUserBridge {
throw new Error('Method not implemented.');
}
public getAppDetailChangesBridge(): IAppDetailChangesBridge {
throw new Error('Method not implemented.');
}
public getListenerBridge(): IListenerBridge {
throw new Error('Method not implemented.');
}
}
import { IEnvironmentalVariableBridge } from '@rocket.chat/apps-engine/server/bridges';
export class ServerEnvironmentalVariableBridge implements IEnvironmentalVariableBridge {
public getValueByName(envVarName: string, appId: string): string {
public getValueByName(envVarName: string, appId: string): Promise<string> {
throw new Error('Method not implemented.');
}
public isReadable(envVarName: string, appId: string): boolean {
public isReadable(envVarName: string, appId: string): Promise<boolean> {
throw new Error('Method not implemented.');
}
public isSet(envVarName: string, appId: string): boolean {
public isSet(envVarName: string, appId: string): Promise<boolean> {
throw new Error('Method not implemented.');
}
}
......@@ -2,27 +2,27 @@ import { IServerSettingBridge } from '@rocket.chat/apps-engine/server/bridges';
import { ISetting } from '@rocket.chat/apps-ts-definition/settings';
export class ServerSettingBridge implements IServerSettingBridge {
public getAll(appId: string): Array<ISetting> {
public getAll(appId: string): Promise<Array<ISetting>> {
throw new Error('Method not implemented.');
}
public getOneById(id: string, appId: string): ISetting {
public getOneById(id: string, appId: string): Promise<ISetting> {
throw new Error('Method not implemented.');
}
public hideGroup(name: string, appId: string): void {
public hideGroup(name: string): Promise<void> {
throw new Error('Method not implemented.');
}
public hideSetting(id: string, appId: string): void {
public hideSetting(id: string): Promise<void> {
throw new Error('Method not implemented.');
}
public isReadableById(id: string, appId: string): boolean {
public isReadableById(id: string, appId: string): Promise<boolean> {
throw new Error('Method not implemented.');
}
public updateOne(setting: ISetting, appId: string): void {
public updateOne(setting: ISetting, appId: string): Promise<void> {
throw new Error('Method not implemented.');
}
}
import { AppManager } from '@rocket.chat/apps-engine/server/AppManager';
import { AppFabricationFulfillment } from '@rocket.chat/apps-engine/server/compiler';
import { ProxiedApp } from '@rocket.chat/apps-engine/server/ProxiedApp';
import { App } from '@rocket.chat/apps-ts-definition/App';
import { AppStatusUtils } from '@rocket.chat/apps-ts-definition/AppStatus';
import { IAppInfo } from '@rocket.chat/apps-ts-definition/metadata';
import * as AdmZip from 'adm-zip';
import * as fs from 'fs';
import * as path from 'path';
import * as socketIO from 'socket.io';
......@@ -16,35 +21,64 @@ export class Orchestrator {
private io: SocketIO.Server;
private folder: string;
constructor() {
this.bridges = new ServerAppBridges();
this.storage = new ServerAppStorage();
this.logStorage = new ServerAppLogStorage();
this.folder = 'dist';
this.manager = new AppManager(this.storage, this.logStorage, this.bridges);
}
public loadAndUpdate(): Promise<boolean> {
return this.manager.load().then(() => {
return Promise.all(fs.readdirSync('dist')
.filter((file) => file.endsWith('.zip') && fs.statSync(path.join('dist', file)).isFile())
.map((file) => fs.readFileSync(path.join('dist', file), 'base64'))
.map((zip) => this.manager.add(zip).catch((err: Error) => {
if (err.message === 'App already exists.') {
return this.manager.update(zip);
} else {
console.log(err);
throw err;
}
})));
}).then(() => {
if (typeof this.io !== 'undefined') {
this.io.emit('status', { loaded: this.manager.areAppsLoaded() });
this.sendAppsInfo();
public async loadAndUpdate(): Promise<boolean> {
const appsLoaded = await this.manager.load();
console.log(`!!!! Manager has finished loading ${ appsLoaded.length } Apps !!!!`);
const files = fs.readdirSync(this.folder)
.filter((file) => file.endsWith('.zip') && fs.statSync(path.join(this.folder, file)).isFile());
for (const file of files) {
const zipBase64 = fs.readFileSync(path.join(this.folder, file), 'base64');
const zip = new AdmZip(new Buffer(zipBase64, 'base64'));
const infoZip = zip.getEntry('app.json');
let info: IAppInfo;
if (infoZip && !infoZip.isDirectory) {
try {
info = JSON.parse(infoZip.getData().toString()) as IAppInfo;
} catch (e) {
throw new Error('Invalid App package. The "app.json" file is not valid json.');
}
}
this.manager.get().forEach((rl) => console.log('Successfully loaded:', rl.getName()));
return true;
try {
if (info && this.manager.getOneById(info.id)) {
console.log(`!!!! Updating the App ${ info.name } to v${ info.version } !!!!`);
this.handleAppFabFulfilled(await this.manager.update(zipBase64));
} else {
console.log(`!!!! Installing the App ${ info.name } v${ info.version } !!!!`);
this.handleAppFabFulfilled(await this.manager.add(zipBase64));
}
} catch (e) {
console.log('Got an error while working with:', file);
console.error(e);
throw e;
}
}
this.manager.get().forEach((rl: ProxiedApp) => {
if (AppStatusUtils.isEnabled(rl.getStatus())) {
console.log(`Successfully loaded: ${ rl.getName() } v${ rl.getVersion() }`);
} else if (AppStatusUtils.isDisabled(rl.getStatus())) {
console.log(`Failed to load: ${ rl.getName() } v${ rl.getVersion() }`);
} else {
console.log(`Neither failed nor succeeded in loading: ${ rl.getName() } v${ rl.getVersion() }`);
}
});
return true;
}
public setSocketServer(server: SocketIO.Server): void {
......@@ -80,4 +114,11 @@ export class Orchestrator {
this.io.emit('apps', { enabled, disabled });
}
}
private handleAppFabFulfilled(aff: AppFabricationFulfillment): void {
if (aff.getCompilerErrors().length !== 0) {
aff.getCompilerErrors().forEach((e) => console.error(e.message));
console.log(`!!!! Failure due to ${ aff.getCompilerErrors().length } errors !!!!`);
}
}
}
......@@ -13,6 +13,7 @@
"files.exclude": {
".server/": true,
".server-data/": true,
".server-dist/": true,
".site/": true,
".tmp/": true
}
......
......@@ -103,9 +103,9 @@ export class TestingApp extends App implements IPreMessageSentPrevent, IPreMessa
// Test out IPreRoomCreateModify
public async executePreRoomCreateModify(room: IRoom, builder: IRoomBuilder, read: IRead, http: IHttp, persistence: IPersistence): Promise<IRoom> {
room.displaySystemMessages = false;
builder.setDisplayingOfSystemMessages(false);
return room;
return builder.getRoom();
}
// Test out IPostRoomCreate
......
......@@ -3,7 +3,7 @@
"name": "Testing App",
"nameSlug": "testing-app",
"description": "A Rocket.Chat Application used to test out the various features.",
"version": "0.0.7",
"version": "0.0.8",
"requiredApiVersion": ">=0.9.6",
"author": {
"name": "Bradley Hilton",
......
......@@ -33,7 +33,7 @@
"integrity": "sha512-9NGTnWrnVlRyMyRxYvjiAKjr0K+Of7m7ij2zMRDx6MSH2fvLbjJyiVnkk2k3kagykTdVA1ir80kKSQz7J9FXDQ==",
"requires": {
"@rocket.chat/apps-ts-definition": "0.9.6",
"adm-zip": "0.4.7",
"adm-zip": "0.4.8",
"lodash.clonedeep": "4.5.0",
"semver": "5.5.0",
"stack-trace": "0.0.10",
......@@ -63,6 +63,15 @@
"resolved": "https://registry.npmjs.org/@rocket.chat/apps-ts-definition/-/apps-ts-definition-0.9.6.tgz",
"integrity": "sha512-WY6OrZSvBnyAfsgIYk8ab4wgSWRd4x+wLYEUjm07hVG5EjE2SMB7HNybFWKKQPQ4CpV0oHt1dAObtSbEXwSQTA=="
},
"@types/adm-zip": {
"version": "0.4.31",
"resolved": "https://registry.npmjs.org/@types/adm-zip/-/adm-zip-0.4.31.tgz",
"integrity": "sha1-ozdrn6j0xunAeMF20t8srreTneM=",
"dev": true,
"requires": {
"@types/node": "9.6.4"
}
},
"@types/body-parser": {
"version": "1.16.4",
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.16.4.tgz",
......@@ -169,9 +178,9 @@
}
},
"adm-zip": {
"version": "0.4.7",
"resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.7.tgz",
"integrity": "sha1-hgbCy/HEJs6MjsABdER/1Jtur8E="
"version": "0.4.8",
"resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.8.tgz",
"integrity": "sha512-PcFQf6E2HFbI24MM4wttwKQ/UmBIfPk5qA7+fqXjL+sMQTrE2FykQ3j50TL+MlaEKN+/4IYqTpYfZ2I7Xec2cg=="
},
"after": {
"version": "0.8.2",
......@@ -2301,7 +2310,7 @@
"integrity": "sha1-nsJWt6m0eG3qwdhlovjqGds7s/E=",
"dev": true,
"requires": {
"adm-zip": "0.4.7",
"adm-zip": "0.4.8",
"gulp-util": "3.0.8",
"needle": "1.6.0",
"path": "0.12.7",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment