-
Notifications
You must be signed in to change notification settings - Fork 27
/
package.ts
68 lines (52 loc) · 2.02 KB
/
package.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Command, flags } from '@oclif/command';
import { ICompilerDiagnostic } from '@rocket.chat/apps-compiler/definition';
import chalk from 'chalk';
import cli from 'cli-ux';
import { AppCompiler, AppPackager, FolderDetails } from '../misc';
export default class Package extends Command {
public static description = 'packages up your App in a distributable format';
public static aliases = ['p', 'pack'];
public static flags = {
'help': flags.help({ char: 'h' }),
// flag with no value (-f, --force)
'no-compile': flags.boolean({
description: "don't compile the source, package as is (for older Rocket.Chat versions)",
}),
'force': flags.boolean({
char: 'f',
description: 'forcefully package the App, ignores lint & TypeScript errors',
}),
};
public async run(): Promise<void> {
cli.action.start('packaging your app');
const fd = new FolderDetails(this);
try {
await fd.readInfoFile();
} catch (e) {
this.error(e && e.message ? e.message : e);
return;
}
const compiler = new AppCompiler(fd);
const result = await compiler.compile();
const { flags } = this.parse(Package);
if (result.diagnostics.length && !flags.force) {
this.reportDiagnostics(result.diagnostics);
this.error('TypeScript compiler error(s) occurred');
this.exit(1);
return;
}
let zipName: string;
if (flags['no-compile']) {
const packager = new AppPackager(this, fd);
zipName = await packager.zipItUp();
} else {
zipName = await compiler.outputZip();
}
cli.action.stop('finished!');
this.log(chalk.black(' '));
this.log(chalk.green('App packaged up at:'), fd.mergeWithFolder(zipName));
}
private reportDiagnostics(diag: Array<ICompilerDiagnostic>): void {
diag.forEach((d) => this.error(d.message));
}
}