-
-
Notifications
You must be signed in to change notification settings - Fork 196
Plamen5kov/rebuild aar #3398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plamen5kov/rebuild aar #3398
Changes from all commits
6e3650a
c8d021d
f13f6f9
0b49a64
04f9737
180fe32
34323a3
2a15071
d9dd119
22743ef
1cda138
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<% if (isJekyll) { %>--- | ||
title: tns plugin build | ||
position: 8 | ||
---<% } %> | ||
# tns plugin build | ||
========== | ||
|
||
Usage | Synopsis | ||
------|------- | ||
General | `$ tns plugin build` | ||
|
||
<% if(isConsole) { %>Attempts to build the plugin's Android-specific project files located in `platforms/android`. Strips and removes `include.gradle` flavor declarations, if any are present. <% } %> | ||
<% if(isHtml) { %>Attempts to build the plugin's Android-specific project files located in `platforms/android`. The resulting Android Library (aar), and the generated Android Gradle project used to build the library can be found at `platforms/android`. Also strips and removes `include.gradle` flavor declarations, if any are present. For more information about working with plugins, see [NativeScript Plugins](https://github.com/NativeScript/nativescript-cli/blob/master/PLUGINS.md).<% } %> | ||
|
||
|
||
<% if(isHtml) { %> | ||
### Prerequisites | ||
|
||
* Verify that the command is being executed in the source directory of a plugin - e.g. `nativescript-barcodescanner/src` | ||
|
||
### Related Commands | ||
|
||
Command | Description | ||
----------|---------- | ||
[plugin](plugin.html) | Lets you manage the plugins for your project. | ||
[plugin install](plugin-install.html) | Installs the specified plugin and its dependencies. | ||
[plugin remove](plugin-remove.html) | Uninstalls the specified plugin and its dependencies. | ||
<% } %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { EOL } from "os"; | ||
import * as path from "path"; | ||
import * as constants from "../../constants"; | ||
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"]; | ||
} | ||
} | ||
|
||
const tempAndroidProject = path.join(platformsAndroidPath, "android-project"); | ||
|
||
const options: IBuildOptions = { | ||
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.failWithoutHelp("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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
interface IBuildOptions extends IAndroidBuildOptions{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This interface does not add anything to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In one of your previous comments, you mentioned the properties are android specific so I moved them to an android specific interface. |
||
} | ||
|
||
interface IAndroidBuildOptions { | ||
platformsAndroidDirPath: string, | ||
pluginName: string, | ||
aarOutputDir: string, | ||
tempPluginDirPath: string | ||
} | ||
|
||
interface IAndroidPluginBuildService { | ||
buildAar(options: IBuildOptions): Promise<boolean>; | ||
migrateIncludeGradle(options: IBuildOptions): boolean; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use short syntax here:
But this is just a preference, so definitely not a merge stopper