Skip to content

Commit 3e8dcdc

Browse files
Add devDependencies when adding Android platform
In order to support Static Binding Generation, we have to add some dev Dependencies to the project when platform Android is added. As some of them do not work with Nodejs 0.x, we have to limit this functionality only to users who are using node 4.2.1 (the earliest version of 4.x that we support) or later. Show warning in case the user has older node version. Remove --staticBindings flag as it's turned on by default now.
1 parent 810edf3 commit 3e8dcdc

File tree

9 files changed

+49
-21
lines changed

9 files changed

+49
-21
lines changed

lib/commands/build.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
4040
}
4141

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

4746
public allowedParameters: ICommandParameter[] = [];

lib/commands/deploy.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export class DeployOnDeviceCommand implements ICommand {
99
private $mobileHelper: Mobile.IMobileHelper) { }
1010

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

1615
public canExecute(args: string[]): IFuture<boolean> {

lib/commands/run.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ export class RunAndroidCommand extends RunCommandBase implements ICommand {
3434
public allowedParameters: ICommandParameter[] = [];
3535

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

4140
public canExecute(args: string[]): IFuture<boolean> {

lib/declarations.ts

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ interface IOptions extends ICommonOptions {
8585
port: Number;
8686
production: boolean;
8787
sdk: string;
88-
staticBindings: boolean;
8988
symlink: boolean;
9089
tnsModulesVersion: string;
9190
}

lib/definitions/project.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ interface IPlatformProjectServiceBase {
4747
}
4848

4949
interface IBuildConfig {
50-
runSbGenerator?: boolean;
5150
buildForDevice?: boolean;
5251
architectures?: string[];
5352
}

lib/options.ts

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export class Options extends commonOptionsLibPath.OptionsBase {
3030
keyStoreAliasPassword: { type: OptionType.String },
3131
ignoreScripts: {type: OptionType.Boolean },
3232
tnsModulesVersion: { type: OptionType.String },
33-
staticBindings: {type: OptionType.Boolean},
3433
compileSdk: {type: OptionType.Number },
3534
port: { type: OptionType.Number },
3635
copyTo: { type: OptionType.String },

lib/services/android-project-service.ts

+41-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
1616
private static VALUES_VERSION_DIRNAME_PREFIX = AndroidProjectService.VALUES_DIRNAME + "-v";
1717
private static ANDROID_PLATFORM_NAME = "android";
1818
private static MIN_RUNTIME_VERSION_WITH_GRADLE = "1.3.0";
19+
private static MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS = "4.2.1";
20+
private static REQUIRED_DEV_DEPENDENCIES = [
21+
{ name: "babel-traverse", version: "^6.4.5"},
22+
{ name: "babel-types", version: "^6.4.5"},
23+
{ name: "babylon", version: "^6.4.5"},
24+
{ name: "filewalker", version: "^0.1.2"},
25+
{ name: "lazy", version: "^1.0.11"}
26+
];
27+
28+
private _sysInfoData: ISysInfoData;
29+
private get sysInfoData(): ISysInfoData {
30+
if(!this._sysInfoData) {
31+
this._sysInfoData = this.$sysInfo.getSysInfo(path.join(__dirname, "..", "..", "package.json")).wait();
32+
}
33+
34+
return this._sysInfoData;
35+
}
1936

2037
private _androidProjectPropertiesManagers: IDictionary<IAndroidProjectPropertiesManager>;
2138

@@ -36,7 +53,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
3653
private $deviceAppDataFactory: Mobile.IDeviceAppDataFactory,
3754
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
3855
private $projectTemplatesService: IProjectTemplatesService,
39-
private $xmlValidator: IXmlValidator) {
56+
private $xmlValidator: IXmlValidator,
57+
private $npm: INodePackageManager) {
4058
super($fs, $projectData, $projectDataService);
4159
this._androidProjectPropertiesManagers = Object.create(null);
4260
}
@@ -88,7 +106,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
88106

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

@@ -126,10 +144,28 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
126144
}
127145

128146
this.cleanResValues(targetSdkVersion, frameworkVersion).wait();
129-
147+
if(this.canUseStaticBindingGenerator()) {
148+
let npmConfig = {
149+
"save": true,
150+
"save-dev": true,
151+
"save-exact": true,
152+
"silent": true
153+
};
154+
155+
_.each(AndroidProjectService.REQUIRED_DEV_DEPENDENCIES, (dependency: any) =>
156+
this.$npm.install(`${dependency.name}@${dependency.version}`, this.$projectData.projectDir, npmConfig).wait()
157+
);
158+
} else {
159+
this.$logger.printMarkdown(`As you are using Node.js \`${this.sysInfoData.nodeVer}\` Static Binding Generator will be turned off.
160+
Upgrade your Node.js to ${AndroidProjectService.MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS} or later, so you can use this feature.`);
161+
}
130162
}).future<any>()();
131163
}
132164

165+
private canUseStaticBindingGenerator(): boolean {
166+
return semver.gte(this.sysInfoData.nodeVer, AndroidProjectService.MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS);
167+
}
168+
133169
private useGradleWrapper(frameworkDir: string): boolean {
134170
let gradlew = path.join(frameworkDir, "gradlew");
135171
return this.$fs.exists(gradlew).wait();
@@ -231,8 +267,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
231267
buildOptions.push(`-PksPassword=${this.$options.keyStorePassword}`);
232268
}
233269

234-
if (buildConfig && buildConfig.runSbGenerator) {
235-
buildOptions.push("-PrunSBGenerator");
270+
if(!this.canUseStaticBindingGenerator()) {
271+
buildOptions.push("-PdontRunSbg");
236272
}
237273

238274
let gradleBin = this.useGradleWrapper(projectRoot) ? path.join(projectRoot, "gradlew") : "gradle";

lib/services/project-data-service.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ export class ProjectDataService implements IProjectDataService {
6060
return (() => {
6161
assert.ok(this.projectFilePath, "Initialize method of projectDataService is not called.");
6262

63-
if(!this.projectData) {
64-
if(!this.$fs.exists(this.projectFilePath).wait()) {
65-
this.$fs.writeFile(this.projectFilePath, null).wait();
66-
}
67-
68-
this.projectData = this.$fs.readJson(this.projectFilePath).wait() || Object.create(null);
63+
if(!this.$fs.exists(this.projectFilePath).wait()) {
64+
this.$fs.writeFile(this.projectFilePath, null).wait();
6965
}
66+
67+
this.projectData = this.$fs.readJson(this.projectFilePath).wait() || Object.create(null);
7068
}).future<void>()();
7169
}
7270
}

0 commit comments

Comments
 (0)