Skip to content

Add devDependencies when adding Android platform #1681

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 1 commit into from
Apr 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
}

public execute(args: string[]): IFuture<void> {
let config = this.$options.staticBindings ? { runSbGenerator: true } : undefined;
return this.executeCore([this.$platformsData.availablePlatforms.Android], config);
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
}

public allowedParameters: ICommandParameter[] = [];
Expand Down
3 changes: 1 addition & 2 deletions lib/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export class DeployOnDeviceCommand implements ICommand {
private $mobileHelper: Mobile.IMobileHelper) { }

execute(args: string[]): IFuture<void> {
let config = this.$options.staticBindings ? { runSbGenerator: true } : undefined;
return this.$platformService.deployOnDevice(args[0], config);
return this.$platformService.deployOnDevice(args[0]);
}

public canExecute(args: string[]): IFuture<boolean> {
Expand Down
3 changes: 1 addition & 2 deletions lib/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export class RunAndroidCommand extends RunCommandBase implements ICommand {
public allowedParameters: ICommandParameter[] = [];

public execute(args: string[]): IFuture<void> {
let config = this.$options.staticBindings ? { runSbGenerator: true } : undefined;
return this.executeCore([this.$platformsData.availablePlatforms.Android], config);
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
}

public canExecute(args: string[]): IFuture<boolean> {
Expand Down
1 change: 0 additions & 1 deletion lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ interface IOptions extends ICommonOptions {
port: Number;
production: boolean;
sdk: string;
staticBindings: boolean;
symlink: boolean;
tnsModulesVersion: string;
}
Expand Down
1 change: 0 additions & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ interface IPlatformProjectServiceBase {
}

interface IBuildConfig {
runSbGenerator?: boolean;
buildForDevice?: boolean;
architectures?: string[];
}
Expand Down
1 change: 0 additions & 1 deletion lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export class Options extends commonOptionsLibPath.OptionsBase {
keyStoreAliasPassword: { type: OptionType.String },
ignoreScripts: {type: OptionType.Boolean },
tnsModulesVersion: { type: OptionType.String },
staticBindings: {type: OptionType.Boolean},
compileSdk: {type: OptionType.Number },
port: { type: OptionType.Number },
copyTo: { type: OptionType.String },
Expand Down
41 changes: 36 additions & 5 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
private static VALUES_VERSION_DIRNAME_PREFIX = AndroidProjectService.VALUES_DIRNAME + "-v";
private static ANDROID_PLATFORM_NAME = "android";
private static MIN_RUNTIME_VERSION_WITH_GRADLE = "1.3.0";
private static MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS = "4.2.1";
private static REQUIRED_DEV_DEPENDENCIES = [
{ name: "babel-traverse", version: "^6.4.5"},
{ name: "babel-types", version: "^6.4.5"},
{ name: "babylon", version: "^6.4.5"},
{ name: "filewalker", version: "^0.1.2"},
{ name: "lazy", version: "^1.0.11"}
];

private get sysInfoData(): ISysInfoData {
return this.$sysInfo.getSysInfo(path.join(__dirname, "..", "..", "package.json")).wait();
}

private _androidProjectPropertiesManagers: IDictionary<IAndroidProjectPropertiesManager>;

Expand All @@ -36,7 +48,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
private $deviceAppDataFactory: Mobile.IDeviceAppDataFactory,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $projectTemplatesService: IProjectTemplatesService,
private $xmlValidator: IXmlValidator) {
private $xmlValidator: IXmlValidator,
private $npm: INodePackageManager) {
super($fs, $projectData, $projectDataService);
this._androidProjectPropertiesManagers = Object.create(null);
}
Expand Down Expand Up @@ -88,7 +101,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject

// this call will fail in case `android` is not set correctly.
this.$androidToolsInfo.getPathToAndroidExecutable({showWarningsAsErrors: true}).wait();
this.$androidToolsInfo.validateJavacVersion(this.$sysInfo.getSysInfo(path.join(__dirname, "..", "..", "package.json")).wait().javacVersion, {showWarningsAsErrors: true}).wait();
this.$androidToolsInfo.validateJavacVersion(this.sysInfoData.javacVersion, {showWarningsAsErrors: true}).wait();
}).future<void>()();
}

Expand Down Expand Up @@ -126,10 +139,28 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
}

this.cleanResValues(targetSdkVersion, frameworkVersion).wait();

if(this.canUseStaticBindingGenerator()) {
let npmConfig = {
"save": true,
"save-dev": true,
"save-exact": true,
"silent": true
};

_.each(AndroidProjectService.REQUIRED_DEV_DEPENDENCIES, (dependency: any) =>
this.$npm.install(`${dependency.name}@${dependency.version}`, this.$projectData.projectDir, npmConfig).wait()
);
} else {
this.$logger.printMarkdown(` As you are using Node.js \`${this.sysInfoData.nodeVer}\` Static Binding Generator will be turned off.` +
Copy link
Contributor

Choose a reason for hiding this comment

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

Static Binding Generator will be turned off because you are using Node.js ${this.sysInfoData.nodeVer} .

To use the Static Binding Generator, upgrade your Node.js to ${AndroidProjectService.MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS} or later.

`Upgrade your Node.js to ${AndroidProjectService.MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS} or later, so you can use this feature.`);
}
}).future<any>()();
}

private canUseStaticBindingGenerator(): boolean {
return semver.gte(this.sysInfoData.nodeVer, AndroidProjectService.MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS);
}

private useGradleWrapper(frameworkDir: string): boolean {
let gradlew = path.join(frameworkDir, "gradlew");
return this.$fs.exists(gradlew).wait();
Expand Down Expand Up @@ -231,8 +262,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
buildOptions.push(`-PksPassword=${this.$options.keyStorePassword}`);
}

if (buildConfig && buildConfig.runSbGenerator) {
buildOptions.push("-PrunSBGenerator");
if(!this.canUseStaticBindingGenerator()) {
buildOptions.push("-PdontRunSbg");
}

let gradleBin = this.useGradleWrapper(projectRoot) ? path.join(projectRoot, "gradlew") : "gradle";
Expand Down
10 changes: 4 additions & 6 deletions lib/services/project-data-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ export class ProjectDataService implements IProjectDataService {
return (() => {
assert.ok(this.projectFilePath, "Initialize method of projectDataService is not called.");

if(!this.projectData) {
if(!this.$fs.exists(this.projectFilePath).wait()) {
this.$fs.writeFile(this.projectFilePath, null).wait();
}

this.projectData = this.$fs.readJson(this.projectFilePath).wait() || Object.create(null);
if(!this.$fs.exists(this.projectFilePath).wait()) {
this.$fs.writeFile(this.projectFilePath, null).wait();
}

this.projectData = this.$fs.readJson(this.projectFilePath).wait() || Object.create(null);
}).future<void>()();
}
}
Expand Down