-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathbuild-plugin.ts
64 lines (49 loc) · 2.2 KB
/
build-plugin.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
import { EOL } from "os";
import * as path from "path";
import * as constants from "../../constants";
import * as temp from "temp";
export class BuildPluginCommand implements ICommand {
public allowedParameters: ICommandParameter[] = [];
public pluginProjectPath: string;
constructor(private $androidPluginBuildService: IAndroidPluginBuildService,
private $errors: IErrors,
private $logger: ILogger,
private $fs: IFileSystem,
private $options: IOptions) {
this.pluginProjectPath = path.resolve(this.$options.path || ".");
}
public async execute(args: string[]): Promise<void> {
const platformsAndroidPath = path.join(this.pluginProjectPath, constants.PLATFORMS_DIR_NAME, "android");
let pluginName = "";
const pluginPackageJsonPath = path.join(this.pluginProjectPath, constants.PACKAGE_JSON_FILE_NAME);
if (this.$fs.exists(pluginPackageJsonPath)) {
const packageJsonContents = this.$fs.readJson(pluginPackageJsonPath);
if (packageJsonContents && packageJsonContents["name"]) {
pluginName = packageJsonContents["name"];
}
}
temp.track();
const tempAndroidProject = temp.mkdirSync("android-project");
const options: IPluginBuildOptions = {
aarOutputDir: platformsAndroidPath,
platformsAndroidDirPath: platformsAndroidPath,
pluginName: pluginName,
tempPluginDirPath: tempAndroidProject
};
const androidPluginBuildResult = await this.$androidPluginBuildService.buildAar(options);
if (androidPluginBuildResult) {
this.$logger.info(`${pluginName} successfully built aar at ${platformsAndroidPath}.${EOL}Temporary Android project can be found at ${tempAndroidProject}.`);
}
const migratedIncludeGradle = this.$androidPluginBuildService.migrateIncludeGradle(options);
if (migratedIncludeGradle) {
this.$logger.info(`${pluginName} include gradle updated.`);
}
}
public async canExecute(args: string[]): Promise<boolean> {
if (!this.$fs.exists(path.join(this.pluginProjectPath, constants.PLATFORMS_DIR_NAME, "android"))) {
this.$errors.fail("No plugin found at the current directory, or the plugin does not need to have its platforms/android components built into an `.aar`.");
}
return true;
}
}
$injector.registerCommand("plugin|build", BuildPluginCommand);