Skip to content

Commit 3865b9b

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 3865b9b

File tree

9 files changed

+44
-21
lines changed

9 files changed

+44
-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

+36-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ 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 get sysInfoData(): ISysInfoData {
29+
return this.$sysInfo.getSysInfo(path.join(__dirname, "..", "..", "package.json")).wait();
30+
}
1931

2032
private _androidProjectPropertiesManagers: IDictionary<IAndroidProjectPropertiesManager>;
2133

@@ -36,7 +48,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
3648
private $deviceAppDataFactory: Mobile.IDeviceAppDataFactory,
3749
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
3850
private $projectTemplatesService: IProjectTemplatesService,
39-
private $xmlValidator: IXmlValidator) {
51+
private $xmlValidator: IXmlValidator,
52+
private $npm: INodePackageManager) {
4053
super($fs, $projectData, $projectDataService);
4154
this._androidProjectPropertiesManagers = Object.create(null);
4255
}
@@ -88,7 +101,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
88101

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

@@ -126,10 +139,28 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
126139
}
127140

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

160+
private canUseStaticBindingGenerator(): boolean {
161+
return semver.gte(this.sysInfoData.nodeVer, AndroidProjectService.MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS);
162+
}
163+
133164
private useGradleWrapper(frameworkDir: string): boolean {
134165
let gradlew = path.join(frameworkDir, "gradlew");
135166
return this.$fs.exists(gradlew).wait();
@@ -231,8 +262,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
231262
buildOptions.push(`-PksPassword=${this.$options.keyStorePassword}`);
232263
}
233264

234-
if (buildConfig && buildConfig.runSbGenerator) {
235-
buildOptions.push("-PrunSBGenerator");
265+
if(!this.canUseStaticBindingGenerator()) {
266+
buildOptions.push("-PdontRunSbg");
236267
}
237268

238269
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)