Skip to content

Plamen5kov/as compatible cli #3193

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

Merged
merged 6 commits into from
Nov 8, 2017
Merged

Conversation

Plamen5kov
Copy link
Contributor

@Plamen5kov Plamen5kov commented Nov 2, 2017

  • CLI is now compatible with Android Studio project templates.
  • CLI is backward compatible with previous version of the android runtime at least back to 3.0.0 [inclusive]

PR accommodates the new android runtime, project template: NativeScript/android#875
related PR: NativeScript/nativescript-dev-webpack#310

@@ -46,19 +48,41 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
if (!projectData && !this._platformData) {
throw new Error("First call of getPlatformData without providing projectData.");
}
if (projectData && projectData.platformsDir) {
const projectRoot = path.join(projectData.platformsDir, AndroidProjectService.ANDROID_PLATFORM_NAME);
if (this.isAndroidStudioCompattibleTemplate(projectData)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo
isAndroidStudioCompattibleTemplate -> isAndroidStudioCompatibleTemplate

@@ -38,6 +39,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
private $npm: INodePackageManager) {
super($fs, $projectDataService);
this._androidProjectPropertiesManagers = Object.create(null);
this.isASTemplate = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing we're talking about AndroidStudio template here - can we name the variable isAndroidStudioTemplate for example so that it's a bit clearer


const appDestinationDirectoryArr = ["src", "main", "assets"];
if (this.isASTemplate) {
appDestinationDirectoryArr.unshift("app");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use APP_FOLDER_NAME from constants here


const configurationsDirectoryArr = ["src", "main", "AndroidManifest.xml"];
if (this.isASTemplate) {
configurationsDirectoryArr.unshift("app");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use APP_FOLDER_NAME from constants here too


const deviceBuildOutputArr = ["build", "outputs", "apk"];
if (this.isASTemplate) {
deviceBuildOutputArr.unshift("app");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use APP_FOLDER_NAME here too

this.isASTemplate = true;
}

const appDestinationDirectoryArr = ["src", "main", "assets"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a suggestion for this code. Right now we start with 3 items in the array and later on we unshift one or two items to it. This seems a bit backwards to me.
Instead, we could start from the first item and work our way towards the end like so:

const appDestinationDirectoryArr = [projectRoot];
if (this.isAndroidStudioTemplate) {
    appDestinationDirectoryArr.push(APP_FOLDER_NAME);
}

appDestinationDirectoryArr.push("src", "main", "assets");

This way the logic will be start-to-end in contrast of end-to-start. In addition, push is very likely faster than unshift.
This can be done for all 3 occurrences of this type of code down below.

}
appDestinationDirectoryArr.unshift(projectRoot);

const configurationsDirectoryArr = ["src", "main", "AndroidManifest.xml"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can introduce constants for these hard-coded strings. I'm thinking something like:

export class AndroidSpecificFileNames {
    static SRC_DIR = "src";
    static MAIN_DIR = "main";
    static MANIFEST_FILE_NAME = "AndroidManifest.xml";
    static BUILD_DIR = "build";
    static OUTPUTS_DIR = "outputs";
    static APK_DIR = "apk";
    static ASSETS_DIR = "assets";
    static RES_DIR = "res";
}

for example. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add them to constants file since we already have an established commonplace for constants.

return path.join(this.getPlatformData(projectData).projectRoot, "src", "main", "res");
const resourcePath: string[] = ["src", "main", "res"];
if (this.isASTemplate) {
resourcePath.unshift("app");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the APP_FOLDER_NAME constant here too

resourcePath.unshift("app");
}

return path.join(this.getPlatformData(projectData).projectRoot, path.join(...resourcePath));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for the inner path.join statement - it could just be

return path.join(this.getPlatformData(projectData).projectRoot, ...resourcePath);

}
}

const asCompatibleTemplate = "3.4.0";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could name this androidStudioCompatibleTemplate

@Plamen5kov Plamen5kov requested a review from dtopuzov November 6, 2017 11:23
@Plamen5kov
Copy link
Contributor Author

ping @Mitko-Kerezov

@dtopuzov
Copy link
Contributor

dtopuzov commented Nov 7, 2017

run ci

1 similar comment
@dtopuzov
Copy link
Contributor

dtopuzov commented Nov 7, 2017

run ci

Copy link
Contributor

@Mitko-Kerezov Mitko-Kerezov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay to me

@Plamen5kov Plamen5kov merged commit 6522178 into master Nov 8, 2017
@Plamen5kov Plamen5kov deleted the plamen5kov/as-compatible-cli branch November 8, 2017 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants