Skip to content

Commit 5a3266a

Browse files
committed
tns-android/ios are installed as dev dependencies
previously tns-android and tns-ios have been installed in nativescript key in the root package.json now both platforms are installed as a dev-dependencies cli will generate a productionDependencies.json that will be respected by gradle, so only the production dependencies are traversed, platform package is left installed as a dev dependency
1 parent 3596891 commit 5a3266a

13 files changed

+47
-29
lines changed

lib/commands/install.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { EOL } from "os";
2+
import * as constants from "../constants";
23

34
export class InstallCommand implements ICommand {
45
public enableHooks = false;
@@ -26,7 +27,7 @@ export class InstallCommand implements ICommand {
2627
this.$projectDataService.initialize(this.$projectData.projectDir);
2728
for (let platform of this.$platformsData.platformsNames) {
2829
let platformData = this.$platformsData.getPlatformData(platform);
29-
let frameworkPackageData = this.$projectDataService.getValue(platformData.frameworkPackageName);
30+
let frameworkPackageData = this.$projectDataService.getValue(platformData.frameworkPackageName, constants.DEV_DEPENDENCIES);
3031
if (frameworkPackageData && frameworkPackageData.version) {
3132
try {
3233
await this.$platformService.addPlatforms([`${platform}@${frameworkPackageData.version}`]);

lib/commands/update.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from "path";
22
import * as shelljs from "shelljs";
3+
import * as constants from "../constants";
34

45
export class UpdateCommand implements ICommand {
56
public allowedParameters: ICommandParameter[] = [];
@@ -13,7 +14,7 @@ export class UpdateCommand implements ICommand {
1314
private $logger: ILogger) { }
1415

1516
public async execute(args: string[]): Promise<void> {
16-
let folders = ["lib", "hooks", "platforms", "node_modules"];
17+
let folders = ["hooks", "platforms", "node_modules"];
1718
let tmpDir = path.join(this.$projectData.projectDir, ".tmp_backup");
1819

1920
try {
@@ -63,7 +64,7 @@ export class UpdateCommand implements ICommand {
6364
this.$projectDataService.initialize(this.$projectData.projectDir);
6465
for (let platform of availablePlatforms) {
6566
let platformData = this.$platformsData.getPlatformData(platform);
66-
let platformVersion = this.$projectDataService.getValue(platformData.frameworkPackageName);
67+
let platformVersion = this.$projectDataService.getValue(platformData.frameworkPackageName, constants.DEV_DEPENDENCIES);
6768
if (platformVersion) {
6869
packagePlatforms.push(platform);
6970
this.$projectDataService.removeProperty(platformData.frameworkPackageName);

lib/constants.ts

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export const TESTING_FRAMEWORKS = ['jasmine', 'mocha', 'qunit'];
1515
export const TEST_RUNNER_NAME = "nativescript-unit-test-runner";
1616
export const LIVESYNC_EXCLUDED_FILE_PATTERNS = ["**/*.js.map", "**/*.ts"];
1717
export const XML_FILE_EXTENSION = ".xml";
18+
export const DEV_DEPENDENCIES = "devDependencies";
19+
export const FRAMEWORK_TO_PACKAGE:IStringDictionary = {
20+
"android": TNS_ANDROID_RUNTIME_NAME,
21+
"ios": TNS_IOS_RUNTIME_NAME
22+
};
1823

1924
export class PackageVersion {
2025
static NEXT = "next";

lib/definitions/plugins.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ interface IPluginsService {
55
prepare(pluginData: IDependencyData, platform: string): Promise<void>;
66
getAllInstalledPlugins(): Promise<IPluginData[]>;
77
ensureAllDependenciesAreInstalled(): Promise<void>;
8+
getInstalledFrameworkVersion(platform: string): string;
89

910
/**
1011
* Returns all dependencies and devDependencies from pacakge.json file.

lib/definitions/project.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ interface IProjectDataService {
6767
* @param {string} propertyName The name of the property to be checked in `nativescript` key.
6868
* @returns {any} The value of the property.
6969
*/
70-
getValue(propertyName: string): any;
70+
getValue(propertyName: string, key?: string): any;
7171

7272
/**
7373
* Sets a value in the `nativescript` key in a project's package.json.

lib/services/android-project-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
417417
if (!this._canUseGradle) {
418418
if (!frameworkVersion) {
419419
this.$projectDataService.initialize(this.$projectData.projectDir);
420-
let frameworkInfoInProjectFile = this.$projectDataService.getValue(this.platformData.frameworkPackageName);
420+
let frameworkInfoInProjectFile = this.$projectDataService.getValue(this.platformData.frameworkPackageName, constants.DEV_DEPENDENCIES);
421421
frameworkVersion = frameworkInfoInProjectFile && frameworkInfoInProjectFile.version;
422422
}
423423

lib/services/livesync/livesync-service.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class LiveSyncService implements ILiveSyncService {
1414
private $platformsData: IPlatformsData,
1515
private $platformService: IPlatformService,
1616
private $projectData: IProjectData,
17-
private $projectDataService: IProjectDataService,
17+
private $pluginsService: IPluginsService,
1818
private $prompter: IPrompter,
1919
private $injector: IInjector,
2020
private $mobileHelper: Mobile.IMobileHelper,
@@ -26,8 +26,7 @@ class LiveSyncService implements ILiveSyncService {
2626
private $processService: IProcessService) { }
2727

2828
private async ensureAndroidFrameworkVersion(platformData: IPlatformData): Promise<void> { // TODO: this can be moved inside command or canExecute function
29-
this.$projectDataService.initialize(this.$projectData.projectDir);
30-
let frameworkVersion = this.$projectDataService.getValue(platformData.frameworkPackageName).version;
29+
let frameworkVersion = this.$pluginsService.getInstalledFrameworkVersion(platformData.normalizedPlatformName);
3130

3231
if (platformData.normalizedPlatformName.toLowerCase() === this.$devicePlatformsConstants.Android.toLowerCase()) {
3332
if (semver.lt(frameworkVersion, "1.2.1")) {
@@ -46,9 +45,9 @@ class LiveSyncService implements ILiveSyncService {
4645
}
4746

4847
public async liveSync(platform: string, applicationReloadAction?: (deviceAppData: Mobile.IDeviceAppData) => Promise<void>): Promise<void> {
49-
if (this.$options.justlaunch) {
50-
this.$options.watch = false;
51-
}
48+
if (this.$options.justlaunch) {
49+
this.$options.watch = false;
50+
}
5251
let liveSyncData: ILiveSyncData[] = [];
5352

5453
if (platform) {

lib/services/platform-project-service-base.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as constants from "../constants";
2+
13
export class PlatformProjectServiceBase implements IPlatformProjectServiceBase {
24
constructor(protected $fs: IFileSystem,
35
protected $projectData: IProjectData,
@@ -24,7 +26,7 @@ export class PlatformProjectServiceBase implements IPlatformProjectServiceBase {
2426

2527
protected getFrameworkVersion(runtimePackageName: string): string {
2628
this.$projectDataService.initialize(this.$projectData.projectDir);
27-
let frameworkVersion = this.$projectDataService.getValue(runtimePackageName).version;
29+
let frameworkVersion = this.$projectDataService.getValue(runtimePackageName, constants.DEV_DEPENDENCIES).version;
2830
return frameworkVersion;
2931
}
3032
}

lib/services/platform-service.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class PlatformService implements IPlatformService {
8282
let packageToInstall = "";
8383
let npmOptions: IStringDictionary = {
8484
pathToSave: path.join(this.$projectData.platformsDir, platform),
85-
dependencyType: "save"
85+
dependencyType: "save-dev"
8686
};
8787

8888
if (!this.$options.frameworkPath) {
@@ -97,8 +97,7 @@ export class PlatformService implements IPlatformService {
9797
let frameworkDir = path.join(downloadedPackagePath, constants.PROJECT_FRAMEWORK_FOLDER_NAME);
9898
frameworkDir = path.resolve(frameworkDir);
9999

100-
let coreModuleName = await this.addPlatformCore(platformData, frameworkDir);
101-
await this.$npm.uninstall(coreModuleName, { save: true }, this.$projectData.projectDir);
100+
await this.addPlatformCore(platformData, frameworkDir);
102101
} catch (err) {
103102
this.$fs.deleteDirectory(platformPath);
104103
throw err;
@@ -129,17 +128,15 @@ export class PlatformService implements IPlatformService {
129128
if (customTemplateOptions) {
130129
frameworkPackageNameData.template = customTemplateOptions.selectedTemplate;
131130
}
132-
this.$projectDataService.setValue(platformData.frameworkPackageName, frameworkPackageNameData);
133131

134132
return coreModuleName;
135-
136133
}
137134

138135
private async getPathToPlatformTemplate(selectedTemplate: string, frameworkPackageName: string): Promise<any> {
139136
if (!selectedTemplate) {
140137
// read data from package.json's nativescript key
141138
// check the nativescript.tns-<platform>.template value
142-
let nativescriptPlatformData = this.$projectDataService.getValue(frameworkPackageName);
139+
let nativescriptPlatformData = this.$projectDataService.getValue(frameworkPackageName, constants.DEV_DEPENDENCIES);
143140
selectedTemplate = nativescriptPlatformData && nativescriptPlatformData.template;
144141
}
145142

@@ -577,6 +574,7 @@ export class PlatformService implements IPlatformService {
577574
let platformDir = path.join(this.$projectData.platformsDir, platform);
578575
this.$fs.deleteDirectory(platformDir);
579576
this.$projectDataService.removeProperty(platformData.frameworkPackageName);
577+
this.$npm.uninstall(platformData.frameworkPackageName, {"save-dev": true});
580578

581579
this.$logger.out(`Platform ${platform} successfully removed.`);
582580
});
@@ -709,7 +707,7 @@ export class PlatformService implements IPlatformService {
709707
let platformData = this.$platformsData.getPlatformData(platform);
710708

711709
this.$projectDataService.initialize(this.$projectData.projectDir);
712-
let data = this.$projectDataService.getValue(platformData.frameworkPackageName);
710+
let data = this.$projectDataService.getValue(platformData.frameworkPackageName, constants.DEV_DEPENDENCIES);
713711
let currentVersion = data && data.version ? data.version : "0.2.0";
714712

715713
let newVersion = version === constants.PackageVersion.NEXT ?

lib/services/plugins-service.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,10 @@ export class PluginsService implements IPluginsService {
273273
};
274274
}
275275

276-
private getInstalledFrameworkVersion(platform: string): string {
277-
let platformData = this.$platformsData.getPlatformData(platform);
278-
this.$projectDataService.initialize(this.$projectData.projectDir);
279-
let frameworkData = this.$projectDataService.getValue(platformData.frameworkPackageName);
280-
return frameworkData.version;
276+
public getInstalledFrameworkVersion(platform: string): string {
277+
let pathToInstalledFrameworkPackageJson = path.join(this.$projectData.projectDir, constants.NODE_MODULES_FOLDER_NAME, constants.FRAMEWORK_TO_PACKAGE[platform.toLowerCase()], constants.PACKAGE_JSON_FILE_NAME);
278+
let jsonContent = this.$fs.readJson(pathToInstalledFrameworkPackageJson);
279+
return jsonContent.version;
281280
}
282281

283282
private isPluginDataValidForPlatform(pluginData: IPluginData, platform: string): boolean {

lib/services/project-data-service.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ export class ProjectDataService implements IProjectDataService {
1818
}
1919
}
2020

21-
public getValue(propertyName: string): any {
21+
public getValue(propertyName: string, key?: string): any {
2222
this.loadProjectFile();
23-
return this.projectData ? this.projectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE][propertyName] : null;
23+
let rootKey: string = this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE;
24+
if (key) {
25+
rootKey = key;
26+
}
27+
return this.projectData ? this.projectData[rootKey][propertyName] : null;
2428
}
2529

2630
public setValue(key: string, value: any): void {

lib/tools/node-modules/node-modules-builder.ts

+8
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ export class NodeModulesBuilder implements INodeModulesBuilder {
126126
let dependenciesBuilder = this.$injector.resolve(NodeModulesDependenciesBuilder, {});
127127
let productionDependencies = dependenciesBuilder.getProductionDependencies(this.$projectData.projectDir);
128128

129+
let prodDependenciesArr = [];
130+
for (let i in productionDependencies) {
131+
prodDependenciesArr.push(productionDependencies[i].name);
132+
}
133+
134+
let prodDependenciesFilePath = path.join(this.$projectData.projectDir, "platforms", "android", "productionDependencies.json");
135+
this.$fs.writeJson(prodDependenciesFilePath, prodDependenciesArr);
136+
129137
if (!this.$options.bundle) {
130138
const tnsModulesCopy = this.$injector.resolve(TnsModulesCopy, {
131139
outputRoot: absoluteOutputPath

test/plugins-service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ function createProjectFile(testInjector: IInjector): string {
112112
"version": "0.1.0",
113113
"nativescript": {
114114
"id": "org.nativescript.Test",
115-
"tns-android": {
116-
"version": "1.4.0"
117-
}
115+
},
116+
"devDependencies": {
117+
"tns-android": "1.4.0"
118118
}
119119
};
120120

0 commit comments

Comments
 (0)