Skip to content

Commit 3eb4f87

Browse files
Merge pull request #3480 from NativeScript/vladimirov/merge-rel-master
chore: Merge release in master
2 parents 2d96010 + 299feb2 commit 3eb4f87

28 files changed

+359
-246
lines changed

lib/constants.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ export const SRC_DIR = "src";
2424
export const MAIN_DIR = "main";
2525
export const ASSETS_DIR = "assets";
2626
export const MANIFEST_FILE_NAME = "AndroidManifest.xml";
27+
export const APP_GRADLE_FILE_NAME = "app.gradle";
28+
export const INFO_PLIST_FILE_NAME = "Info.plist";
2729
export const INCLUDE_GRADLE_NAME = "include.gradle";
30+
export const BUILD_XCCONFIG_FILE_NAME = "build.xcconfig";
2831
export const BUILD_DIR = "build";
2932
export const OUTPUTS_DIR = "outputs";
3033
export const APK_DIR = "apk";
@@ -33,6 +36,7 @@ export const CONFIG_NS_FILE_NAME = "nsconfig.json";
3336
export const CONFIG_NS_APP_RESOURCES_ENTRY = "appResourcesPath";
3437
export const CONFIG_NS_APP_ENTRY = "appPath";
3538
export const DEPENDENCIES_JSON_NAME = "dependencies.json";
39+
export const APK_EXTENSION_NAME = ".apk";
3640

3741
export class PackageVersion {
3842
static NEXT = "next";
@@ -139,3 +143,8 @@ export const enum BuildStates {
139143
}
140144

141145
export const NATIVESCRIPT_CLOUD_EXTENSION_NAME = "nativescript-cloud";
146+
147+
/**
148+
* Used in ProjectDataService to concatenate the names of the properties inside nativescript key of package.json.
149+
*/
150+
export const NATIVESCRIPT_PROPS_INTERNAL_DELIMITER = "**|__**";

lib/declarations.d.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -698,23 +698,17 @@ interface IVersionsService {
698698
*/
699699
getRuntimesVersions(): Promise<IVersionInformation[]>;
700700

701-
/**
702-
* Checks version information about the nativescript components and prints available updates if any.
703-
*/
704-
checkComponentsForUpdate(): Promise<void>;
705-
706701
/**
707702
* Gets versions information about all nativescript components.
708703
* @return {Promise<IVersionInformation[]>} The version information.
709704
*/
710705
getAllComponentsVersions(): Promise<IVersionInformation[]>;
711706

712707
/**
713-
* Creates table with versions information.
714-
* @param {IVersionInformation[]} The versions information to push in the table.
715-
* @return {any} The created table.
708+
* Checks version information about the nativescript components and prints versions information.
709+
* @return {Promise<void>}
716710
*/
717-
createTableWithVersionsInformation(versionsInformation: IVersionInformation[]): any;
711+
printVersionsInformation(): Promise<void>;
718712
}
719713

720714
/**

lib/definitions/platform.d.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ interface IPlatformData {
260260
projectRoot: string;
261261
normalizedPlatformName: string;
262262
appDestinationDirectoryPath: string;
263-
getDeviceBuildOutputPath(options: IRelease): string;
263+
deviceBuildOutputPath: string;
264264
emulatorBuildOutputPath?: string;
265-
getValidPackageNames(buildOptions: { isReleaseBuild?: boolean, isForDevice?: boolean }): string[];
265+
getValidBuildOutputData(buildOptions: IBuildOutputOptions): IValidBuildOutputData;
266266
frameworkFilesExtensions: string[];
267267
frameworkDirectoriesExtensions?: string[];
268268
frameworkDirectoriesNames?: string[];
@@ -273,6 +273,16 @@ interface IPlatformData {
273273
fastLivesyncFileExtensions: string[];
274274
}
275275

276+
interface IValidBuildOutputData {
277+
packageNames: string[];
278+
regexes?: RegExp[];
279+
}
280+
281+
interface IBuildOutputOptions {
282+
isReleaseBuild?: boolean;
283+
isForDevice?: boolean;
284+
}
285+
276286
interface IPlatformsData {
277287
availablePlatforms: any;
278288
platformsNames: string[];

lib/definitions/project.d.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ interface IProjectData extends IProjectDir {
6969
appResourcesDirectoryPath: string;
7070
projectType: string;
7171
nsConfig: INsConfig;
72+
androidManifestPath: string;
73+
appGradlePath: string;
74+
gradleFilesDirectoryPath: string;
75+
infoPlistPath: string;
76+
buildXcconfigPath: string;
77+
7278
/**
7379
* Initializes project data with the given project directory. If none supplied defaults to --path option or cwd.
7480
* @param {string} projectDir Project root directory.
@@ -142,10 +148,6 @@ interface IBuildForDevice {
142148
buildForDevice: boolean;
143149
}
144150

145-
interface IShouldInstall extends IBuildForDevice, IRelease {
146-
147-
}
148-
149151
interface INativePrepare {
150152
skipNativePrepare: boolean;
151153
}

lib/project-data.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,20 @@ export class ProjectData implements IProjectData {
4343
public dependencies: any;
4444
public devDependencies: IStringDictionary;
4545
public projectType: string;
46+
public androidManifestPath: string;
47+
public infoPlistPath: string;
48+
public appGradlePath: string;
49+
public gradleFilesDirectoryPath: string;
50+
public buildXcconfigPath: string;
4651

4752
constructor(private $fs: IFileSystem,
4853
private $errors: IErrors,
4954
private $projectHelper: IProjectHelper,
5055
private $staticConfig: IStaticConfig,
5156
private $options: IOptions,
52-
private $logger: ILogger) { }
57+
private $logger: ILogger,
58+
private $androidResourcesMigrationService: IAndroidResourcesMigrationService,
59+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) { }
5360

5461
public initializeProjectData(projectDir?: string): void {
5562
projectDir = projectDir || this.$projectHelper.projectDir;
@@ -108,13 +115,27 @@ export class ProjectData implements IProjectData {
108115
this.nsConfig = nsConfig;
109116
this.appDirectoryPath = this.getAppDirectoryPath();
110117
this.appResourcesDirectoryPath = this.getAppResourcesDirectoryPath();
118+
this.androidManifestPath = this.getPathToAndroidManifest(this.appResourcesDirectoryPath);
119+
this.gradleFilesDirectoryPath = path.join(this.appResourcesDirectoryPath, this.$devicePlatformsConstants.Android);
120+
this.appGradlePath = path.join(this.gradleFilesDirectoryPath, constants.APP_GRADLE_FILE_NAME);
121+
this.infoPlistPath = path.join(this.appResourcesDirectoryPath, this.$devicePlatformsConstants.iOS, constants.INFO_PLIST_FILE_NAME);
122+
this.buildXcconfigPath = path.join(this.appResourcesDirectoryPath, this.$devicePlatformsConstants.iOS, constants.BUILD_XCCONFIG_FILE_NAME);
111123

112124
return;
113125
}
114126

115127
this.errorInvalidProject(projectDir);
116128
}
117129

130+
private getPathToAndroidManifest(appResourcesDir: string): string {
131+
const androidDirPath = path.join(appResourcesDir, this.$devicePlatformsConstants.Android);
132+
const androidManifestDir = this.$androidResourcesMigrationService.hasMigrated(appResourcesDir) ?
133+
path.join(androidDirPath, constants.SRC_DIR, constants.MAIN_DIR) :
134+
androidDirPath;
135+
136+
return path.join(androidManifestDir, constants.MANIFEST_FILE_NAME);
137+
}
138+
118139
private errorInvalidProject(projectDir: string): void {
119140
const currentDir = path.resolve(".");
120141
this.$logger.trace(`Unable to find project. projectDir: ${projectDir}, options.path: ${this.$options.path}, ${currentDir}`);

lib/services/android-project-service.ts

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,19 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
8383
platformProjectService: this,
8484
emulatorServices: this.$androidEmulatorServices,
8585
projectRoot: projectRoot,
86-
getDeviceBuildOutputPath: (options: IRelease): string => {
87-
return this.getDeviceBuildOutputPath(path.join(...deviceBuildOutputArr), projectData, options);
88-
},
89-
getValidPackageNames: (buildOptions: { isReleaseBuild?: boolean, isForDevice?: boolean }): string[] => {
86+
deviceBuildOutputPath: path.join(...deviceBuildOutputArr),
87+
getValidBuildOutputData: (buildOptions: IBuildOutputOptions): IValidBuildOutputData => {
9088
const buildMode = buildOptions.isReleaseBuild ? Configurations.Release.toLowerCase() : Configurations.Debug.toLowerCase();
9189

92-
return [
93-
`${packageName}-${buildMode}.apk`,
94-
`${projectData.projectName}-${buildMode}.apk`,
95-
`${projectData.projectName}.apk`,
96-
`app-${buildMode}.apk`
97-
];
90+
return {
91+
packageNames: [
92+
`${packageName}-${buildMode}${constants.APK_EXTENSION_NAME}`,
93+
`${projectData.projectName}-${buildMode}${constants.APK_EXTENSION_NAME}`,
94+
`${projectData.projectName}${constants.APK_EXTENSION_NAME}`,
95+
`${constants.APP_FOLDER_NAME}-${buildMode}${constants.APK_EXTENSION_NAME}`
96+
],
97+
regexes: [new RegExp(`${constants.APP_FOLDER_NAME}-.*-(${Configurations.Debug}|${Configurations.Release})${constants.APK_EXTENSION_NAME}`, "i"), new RegExp(`${packageName}-.*-(${Configurations.Debug}|${Configurations.Release})${constants.APK_EXTENSION_NAME}`, "i")]
98+
};
9899
},
99100
frameworkFilesExtensions: [".jar", ".dat", ".so"],
100101
configurationFileName: constants.MANIFEST_FILE_NAME,
@@ -108,23 +109,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
108109
return this._platformData;
109110
}
110111

111-
private getDeviceBuildOutputPath(currentPath: string, projectData: IProjectData, options: IRelease): string {
112-
const currentPlatformData: IDictionary<any> = this.$projectDataService.getNSValue(projectData.projectDir, constants.TNS_ANDROID_RUNTIME_NAME);
113-
const platformVersion = currentPlatformData && currentPlatformData[constants.VERSION_STRING];
114-
const buildType = options.release === true ? "release" : "debug";
115-
const normalizedPath = path.join(currentPath, buildType);
116-
117-
if (semver.valid(platformVersion)) {
118-
const gradleAndroidPluginVersion3xx = "4.0.0";
119-
const normalizedPlatformVersion = `${semver.major(platformVersion)}.${semver.minor(platformVersion)}.0`;
120-
if (semver.lt(normalizedPlatformVersion, gradleAndroidPluginVersion3xx)) {
121-
return currentPath;
122-
}
123-
}
124-
125-
return normalizedPath;
126-
}
127-
128112
// TODO: Remove prior to the 4.0 CLI release @Pip3r4o @PanayotCankov
129113
// Similar to the private method of the same name in platform-service.
130114
private getCurrentPlatformVersion(platformData: IPlatformData, projectData: IProjectData): string {
@@ -272,11 +256,9 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
272256
const gradleSettingsFilePath = path.join(this.getPlatformData(projectData).projectRoot, "settings.gradle");
273257
shell.sed('-i', /__PROJECT_NAME__/, this.getProjectNameFromId(projectData), gradleSettingsFilePath);
274258

275-
// will replace applicationId in app/App_Resources/Android/app.gradle if it has not been edited by the user
276-
const userAppGradleFilePath = path.join(projectData.appResourcesDirectoryPath, this.$devicePlatformsConstants.Android, "app.gradle");
277-
278259
try {
279-
shell.sed('-i', /__PACKAGE__/, projectData.projectId, userAppGradleFilePath);
260+
// will replace applicationId in app/App_Resources/Android/app.gradle if it has not been edited by the user
261+
shell.sed('-i', /__PACKAGE__/, projectData.projectId, projectData.appGradlePath);
280262
} catch (e) {
281263
this.$logger.warn(`\n${e}.\nCheck if you're using an outdated template and update it.`);
282264
}
@@ -536,7 +518,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
536518
}
537519

538520
// Copy include.gradle file
539-
const includeGradleFilePath = path.join(pluginPlatformsFolderPath, "include.gradle");
521+
const includeGradleFilePath = path.join(pluginPlatformsFolderPath, constants.INCLUDE_GRADLE_NAME);
540522
if (this.$fs.exists(includeGradleFilePath)) {
541523
shell.cp("-f", includeGradleFilePath, pluginConfigurationDirectoryPath);
542524
}

lib/services/android-resources-migration-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class AndroidResourcesMigrationService implements IAndroidResourcesMigrat
3737
const getDirectories = (files: string[]) => files.filter(isDirectory);
3838
const getFiles = (files: string[]) => files.filter((file: string) => !isDirectory(file));
3939

40-
this.$fs.copyFile(path.join(originalAppResources, "app.gradle"), path.join(appResourcesDestination, "app.gradle"));
40+
this.$fs.copyFile(path.join(originalAppResources, constants.APP_GRADLE_FILE_NAME), path.join(appResourcesDestination, constants.APP_GRADLE_FILE_NAME));
4141

4242
const appResourcesFiles = getAllFiles(originalAppResources);
4343
const resourceDirectories = getDirectories(appResourcesFiles);

lib/services/doctor-service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class DoctorService implements IDoctorService {
4747
}
4848

4949
try {
50-
await this.$versionsService.checkComponentsForUpdate();
50+
await this.$versionsService.printVersionsInformation();
5151
} catch (err) {
5252
this.$logger.error("Cannot get the latest versions information from npm. Please try again later.");
5353
}
@@ -71,7 +71,6 @@ class DoctorService implements IDoctorService {
7171

7272
public async canExecuteLocalBuild(platform?: string): Promise<boolean> {
7373
const infos = await doctor.getInfos({ platform });
74-
this.printInfosCore(infos);
7574

7675
const warnings = this.filterInfosByType(infos, constants.WARNING_TYPE_NAME);
7776
if (warnings.length > 0) {

lib/services/info-service.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
export class InfoService implements IInfoService {
2-
constructor(private $versionsService: IVersionsService,
3-
private $logger: ILogger) { }
2+
constructor(private $versionsService: IVersionsService) { }
43

5-
public async printComponentsInfo(): Promise<void> {
6-
const allComponentsInfo = await this.$versionsService.getAllComponentsVersions();
7-
8-
const table: any = this.$versionsService.createTableWithVersionsInformation(allComponentsInfo);
9-
10-
this.$logger.out("All NativeScript components versions information");
11-
this.$logger.out(table.toString());
4+
public printComponentsInfo(): Promise<void> {
5+
return this.$versionsService.printVersionsInformation();
126
}
137
}
148

0 commit comments

Comments
 (0)