forked from NativeScript/nativescript-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-plugin.ts
100 lines (85 loc) · 2.76 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { EOL } from "os";
import * as path from "path";
import * as constants from "../../constants";
import { IOptions } from "../../declarations";
import {
IAndroidPluginBuildService,
IPluginBuildOptions,
} from "../../definitions/android-plugin-migrator";
import { ICommand, ICommandParameter } from "../../common/definitions/commands";
import { IErrors, IFileSystem } from "../../common/declarations";
import { injector } from "../../common/yok";
import { ITempService } from "../../definitions/temp-service";
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,
private $tempService: ITempService
) {
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"];
}
}
const tempAndroidProject = await this.$tempService.mkdirSync(
"android-project"
);
const options: IPluginBuildOptions = {
gradlePath: this.$options.gradlePath,
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);