Unverified Commit 07d081d5 authored by Bradley Hilton's avatar Bradley Hilton
Browse files

Test compile the typescript before we package it. Update the test app to the promised

parent 9d4b77a8
......@@ -50,3 +50,4 @@ dist/
## dev env items
.server-dist/
.server-data/
.tmp/
......@@ -18,32 +18,33 @@ export class TestingApp extends App implements IPreMessageSentPrevent, IPreMessa
this.getLogger().debug('TestingApp\'s constructor is called and I logged debug.');
}
public onEnable(environment: IEnvironmentRead, configurationModify: IConfigurationModify): boolean {
this.testingPrefix = environment.getSettings().getValueById(TestingSettingsEnum.TESTING_PREFIX) as string;
public async onEnable(environment: IEnvironmentRead, configurationModify: IConfigurationModify): Promise<boolean> {
this.testingPrefix = await environment.getSettings().getValueById(TestingSettingsEnum.TESTING_PREFIX) as string;
return this.testingPrefix.length > 0;
}
// Test out IPreMessageSentPrevent
public checkPreMessageSentPrevent(message: IMessage): boolean {
public async checkPreMessageSentPrevent(message: IMessage): Promise<boolean> {
return typeof message.text === 'string' ? message.text.indexOf(this.testingPrefix) === 0 : false;
}
// Test out IPreMessageSentPrevent
public executePreMessageSentPrevent(message: IMessage, read: IRead, http: IHttp, persistence: IPersistence): boolean {
public async executePreMessageSentPrevent(message: IMessage, read: IRead, http: IHttp, persistence: IPersistence): Promise<boolean> {
return message.text === `${ this.testingPrefix } Prevent this`;
}
// Test out IPreMessageSentExtend
public checkPreMessageSentExtend(message: IMessage): boolean {
public async checkPreMessageSentExtend(message: IMessage): Promise<boolean> {
return typeof message.text === 'string' ? message.text.indexOf(this.testingPrefix) === 0 : false;
}
// Test out IPreMessageSentExtend
public executePreMessageSentExtend(message: IMessage, extend: IMessageExtender, read: IRead, http: IHttp, persistence: IPersistence): IMessage {
public async executePreMessageSentExtend(message: IMessage,
extend: IMessageExtender, read: IRead, http: IHttp, persistence: IPersistence): Promise<IMessage> {
const attach: IMessageAttachment = {
text: `${ this.testingPrefix } Attachment`,
color: read.getEnvironmentReader().getSettings().getValueById(TestingSettingsEnum.TESTING_A_COLOR),
color: await read.getEnvironmentReader().getSettings().getValueById(TestingSettingsEnum.TESTING_A_COLOR),
timestamp: new Date(1985, 6, 28, 12, 48, 30, 85),
};
......@@ -51,77 +52,78 @@ export class TestingApp extends App implements IPreMessageSentPrevent, IPreMessa
}
// Test out IPreMessageSentModify
public checkPreMessageSentModify(message: IMessage): boolean {
public async checkPreMessageSentModify(message: IMessage): Promise<boolean> {
return typeof message.text === 'string' ? message.text.indexOf(this.testingPrefix) === 0 : false;
}
// Test out IPreMessageSentModify
public executePreMessageSentModify(message: IMessage, builder: IMessageBuilder, read: IRead, http: IHttp, persistence: IPersistence): IMessage {
public async executePreMessageSentModify(message: IMessage,
builder: IMessageBuilder, read: IRead, http: IHttp, persistence: IPersistence): Promise<IMessage> {
const text = message.text;
return builder.setText(text + '\n\n> ' + text).getMessage();
}
// Test out IPostMessageSent
public checkPostMessageSent(message: IMessage): boolean {
public async checkPostMessageSent(message: IMessage): Promise<boolean> {
return typeof message.text === 'string' ? message.text.indexOf(this.testingPrefix) === 0 : false;
}
// Test out IPostMessageSent
public executePostMessageSent(message: IMessage, read: IRead, http: IHttp, persistence: IPersistence): void {
public async executePostMessageSent(message: IMessage, read: IRead, http: IHttp, persistence: IPersistence): Promise<void> {
read.getNotifier().notifyUser(message.sender, message);
}
// Test out IPreRoomCreatePrevent
public checkPreRoomCreatePrevent(room: IRoom): boolean {
public async checkPreRoomCreatePrevent(room: IRoom): Promise<boolean> {
return room.type === RoomType.PRIVATE_GROUP ? room.slugifiedName.indexOf(this.testingPrefix) === 0 : false;
}
// Test out IPreRoomCreatePrevent
public executePreRoomCreatePrevent(room: IRoom, read: IRead, http: IHttp, persistence: IPersistence): boolean {
public async executePreRoomCreatePrevent(room: IRoom, read: IRead, http: IHttp, persistence: IPersistence): Promise<boolean> {
return room.slugifiedName === `${ this.testingPrefix }-prevent`;
}
// Test out IPreRoomCreateExtend
public checkPreRoomCreateExtend(room: IRoom): boolean {
public async checkPreRoomCreateExtend(room: IRoom): Promise<boolean> {
return room.type === RoomType.PRIVATE_GROUP ? room.slugifiedName.indexOf(this.testingPrefix) === 0 : false;
}
// Test out IPreRoomCreateExtend
public executePreRoomCreateExtend(room: IRoom, extend: IRoomExtender, read: IRead, http: IHttp, persistence: IPersistence): IRoom {
const bot = read.getUserReader().getById('rocket.cat');
public async executePreRoomCreateExtend(room: IRoom, extend: IRoomExtender, read: IRead, http: IHttp, persistence: IPersistence): Promise<IRoom> {
const bot = await read.getUserReader().getById('rocket.cat');
return extend.addMember(bot).getRoom();
}
// Test out IPreRoomCreateModify
public checkPreRoomCreateModify(room: IRoom): boolean {
public async checkPreRoomCreateModify(room: IRoom): Promise<boolean> {
return room.type === RoomType.PRIVATE_GROUP ? room.slugifiedName.indexOf(this.testingPrefix) === 0 : false;
}
// Test out IPreRoomCreateModify
public executePreRoomCreateModify(room: IRoom, builder: IRoomBuilder, read: IRead, http: IHttp, persistence: IPersistence): IRoom {
public async executePreRoomCreateModify(room: IRoom, builder: IRoomBuilder, read: IRead, http: IHttp, persistence: IPersistence): Promise<IRoom> {
room.displaySystemMessages = false;
return room;
}
// Test out IPostRoomCreate
public checkPostRoomCreate(room: IRoom): boolean {
public async checkPostRoomCreate(room: IRoom): Promise<boolean> {
return room.type === RoomType.PRIVATE_GROUP ? room.slugifiedName.indexOf(this.testingPrefix) === 0 : false;
}
// Test out IPostRoomCreate
public executePostRoomCreate(room: IRoom, read: IRead, http: IHttp, persistence: IPersistence): void {
public async executePostRoomCreate(room: IRoom, read: IRead, http: IHttp, persistence: IPersistence): Promise<void> {
const msg = read.getNotifier().getMessageBuilder()
.setRoom(room).setText(`Welcome to #${ room.slugifiedName }! _testing:_ :heavy_check_mark:`)
.setEmojiAvatar(':ghost:').getMessage();
read.getNotifier().notifyRoom(room, msg);
await read.getNotifier().notifyRoom(room, msg);
}
// Test out various configuration extentions
protected extendConfiguration(configuration: IConfigurationExtend, environmentRead: IEnvironmentRead) {
protected async extendConfiguration(configuration: IConfigurationExtend, environmentRead: IEnvironmentRead): Promise<void> {
configuration.slashCommands.provideSlashCommand(new TestingNoPermission());
configuration.slashCommands.provideSlashCommand(new TestingWithPermission());
......
......@@ -3,8 +3,8 @@
"name": "Testing App",
"nameSlug": "testing-app",
"description": "A Rocket.Chat Application used to test out the various features.",
"version": "0.0.5",
"requiredApiVersion": ">=0.7.15",
"version": "0.0.6",
"requiredApiVersion": ">=0.9.2",
"author": {
"name": "Bradley Hilton",
"homepage": "https://github.com/RocketChat/Rocket.Chat.Apps-ts-definitions",
......
......@@ -13,12 +13,12 @@ export class TestingNoPermission implements ISlashCommand {
}
// tslint:disable-next-line:max-line-length
public executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp, persis: IPersistence): void {
public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp, persis: IPersistence): Promise<void> {
const msg = modify.getNotifer().getMessageBuilder()
.setRoom(context.getRoom())
.setUsernameAlias('Testing').setEmojiAvatar(':ghost:')
.setText('You have successfully tested the command, good job.').getMessage();
modify.getNotifer().notifyUser(context.getSender(), msg);
await modify.getNotifer().notifyUser(context.getSender(), msg);
}
}
......@@ -15,12 +15,12 @@ export class TestingWithPermission implements ISlashCommand {
}
// tslint:disable-next-line:max-line-length
public executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp, persis: IPersistence): void {
public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp, persis: IPersistence): Promise<void> {
const msg = modify.getNotifer().getMessageBuilder()
.setRoom(context.getRoom())
.setUsernameAlias('Testing').setEmojiAvatar(':ghost:')
.setText('You have permission, congrats.').getMessage();
modify.getNotifer().notifyUser(context.getSender(), msg);
await modify.getNotifer().notifyUser(context.getSender(), msg);
}
}
......@@ -122,6 +122,20 @@ gulp.task('default', ['clean-generated', 'lint-no-exit-ts', 'compile-server-ts',
['clean-generated', 'lint-no-exit-ts', 'compile-server-ts', 'compile-server-site-ts', 'copy-server-site', 'package-for-develop', 'refresh-lr', 'run-server']);
});
const appsTsCompileOptions = {
target: 'es5',
module: 'commonjs',
moduleResolution: 'node',
declaration: false,
noImplicitAny: false,
removeComments: true,
strictNullChecks: true,
noImplicitReturns: true,
emitDecoratorMetadata: true,
experimentalDecorators: true,
lib: [ 'es2017' ]
};
//Packaging related items
function _packageTheApps(callback) {
const folders = getFolders(appsPath)
......@@ -137,8 +151,41 @@ function _packageTheApps(callback) {
});
async.series([
function _testCompileTheTypeScript(next) {
const promises = folders.map((item) => {
return new Promise((resolve) => {
fs.writeFileSync(`.tmp/${ item.info.id }.json`, JSON.stringify({
compilerOptions: appsTsCompileOptions,
include: [ __dirname + '/' + item.dir ],
exclude: ['node_modules', 'bower_components', 'jspm_packages']
}), 'utf8');
gutil.log(gutil.colors.yellow(figures.ellipsis), gutil.colors.cyan(`Attempting to compile ${item.info.name} v${item.info.version}`));
const project = tsc.createProject(`.tmp/${ item.info.id }.json`);
project.src().pipe(project().on('error', () => {
item.valid = false;
})).pipe(through.obj((file, enc, done) => done(null, file), () => {
if (typeof item.valid === 'boolean' && !item.valid) {
gutil.log(gutil.colors.red(figures.cross), gutil.colors.cyan(`${item.info.name} v${item.info.version}`), 'has', gutil.colors.red('FAILED to compile.'));
} else {
gutil.log(gutil.colors.green(figures.tick), gutil.colors.cyan(`${item.info.name} v${item.info.version}`), 'has', gutil.colors.green('successfully compiled.'));
}
resolve();
}));
});
});
Promise.all(promises).then(() => next()).catch((e) => {
console.error(e);
throw e;
});
},
function _readTheAppJsonFiles(next) {
const promises = folders.map((item) => {
if (typeof item.valid === 'boolean' && !item.valid) return Promise.resolve();
return new Promise((resolve) => {
gulp.src(item.infoFile)
.pipe(jsonSchema({ schema: appSchema, emitError: false }))
......@@ -168,15 +215,27 @@ function _packageTheApps(callback) {
return;
}
const amount = Array.from(Array(10), () => figures.line);
gutil.log(gutil.colors.white(...amount));
gutil.log(gutil.colors.white(...amount));
gutil.log(gutil.colors.red('Errors are listed above'));
gutil.log(gutil.colors.white(...amount));
gutil.log(gutil.colors.white(...amount));
const zippers = validItems.filter((item) => fs.existsSync(path.join(item.dir, item.info.classFile))).map((item) => {
return new Promise((resolve) => {
gutil.log(gutil.colors.green(figures.tick), gutil.colors.cyan(item.info.name + ' ' + item.info.version));
const zipName = item.info.nameSlug + '_' + item.info.version + '.zip';
return gulp.src(item.toZip)
.pipe(file('.packagedby', fs.readFileSync('package.json')))
.pipe(zip(item.info.nameSlug + '_' + item.info.version + '.zip'))
.pipe(zip(zipName))
.pipe(gulp.dest('dist'))
.pipe(through.obj((file, enc, done) => done(null, file), () => resolve()));
.pipe(through.obj((file, enc, done) => done(null, file), () => {
gutil.log(gutil.colors.green(figures.tick),
gutil.colors.cyan(item.info.name + ' v' + item.info.version),
gutil.colors.blue('has been packaged at:'),
gutil.colors.black('dist/' + zipName));
resolve();
}));
});
});
......
This diff is collapsed.
......@@ -8,6 +8,7 @@
"noImplicitAny": false,
"removeComments": true,
"strictNullChecks": true,
"noImplicitReturns": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
......
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