Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 6994792

Browse files
Merge pull request #265 from Microsoft/plist_prefix
Improving release-react
2 parents 34a45b7 + 2dcb9b6 commit 6994792

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

cli/script/command-executor.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,8 @@ function getReactNativeProjectAppVersion(command: cli.IReleaseReactCommand, proj
866866

867867
const isValidVersion = (version: string): boolean => !!semver.valid(version) || /^\d+\.\d+$/.test(version);
868868

869+
log(chalk.cyan(`Detecting ${command.platform} app version:\n`));
870+
869871
if (command.platform === "ios") {
870872
let resolvedPlistFile: string = command.plistFile;
871873
if (resolvedPlistFile) {
@@ -875,6 +877,13 @@ function getReactNativeProjectAppVersion(command: cli.IReleaseReactCommand, proj
875877
throw new Error("The specified plist file doesn't exist. Please check that the provided path is correct.");
876878
}
877879
} else {
880+
// Allow the plist prefix to be specified with or without a trailing
881+
// separator character, but prescribe the use of a hyphen when omitted,
882+
// since this is the most commonly used convetion for plist files.
883+
if (command.plistFilePrefix && /.+[^-.]$/.test(command.plistFilePrefix)) {
884+
command.plistFilePrefix += "-";
885+
}
886+
878887
const iOSDirectory: string = "ios";
879888
const plistFileName = `${command.plistFilePrefix || ""}Info.plist`;
880889

@@ -886,7 +895,7 @@ function getReactNativeProjectAppVersion(command: cli.IReleaseReactCommand, proj
886895
resolvedPlistFile = (<any>knownLocations).find(fileExists);
887896

888897
if (!resolvedPlistFile) {
889-
throw new Error(`Unable to find either of the following plist files in order to infer your app's binary version: "${knownLocations.join("\", \"")}".`);
898+
throw new Error(`Unable to find either of the following plist files in order to infer your app's binary version: "${knownLocations.join("\", \"")}". If your plist has a different name, or is located in a different directory, consider using either the "--plistFile" or "--plistFilePrefix" parameters to help inform the CLI how to find it.`);
890899
}
891900
}
892901

@@ -900,43 +909,45 @@ function getReactNativeProjectAppVersion(command: cli.IReleaseReactCommand, proj
900909

901910
if (parsedPlist && parsedPlist.CFBundleShortVersionString) {
902911
if (isValidVersion(parsedPlist.CFBundleShortVersionString)) {
912+
log(`Using the target binary version value "${parsedPlist.CFBundleShortVersionString}" from "${resolvedPlistFile}".\n`);
903913
return Q(parsedPlist.CFBundleShortVersionString);
904914
} else {
905-
throw new Error(`The "CFBundleShortVersionString" key in the "${resolvedPlistFile}" needs to have at least a major and minor version, for example "2.0" or "1.0.3".`);
915+
throw new Error(`The "CFBundleShortVersionString" key in the "${resolvedPlistFile}" file needs to specify a valid semver string, containing both a major and minor version (e.g. 1.3.2, 1.1).`);
906916
}
907917
} else {
908918
throw new Error(`The "CFBundleShortVersionString" key doesn't exist within the "${resolvedPlistFile}" file.`);
909919
}
910920
} else if (command.platform === "android") {
911921
const buildGradlePath: string = path.join("android", "app", "build.gradle");
912922
if (fileDoesNotExistOrIsDirectory(buildGradlePath)) {
913-
throw new Error("Unable to find or read \"build.gradle\" in the \"android/app\" folder.");
923+
throw new Error(`Unable to find the "build.gradle" file in your "android/app" directory.`);
914924
}
915925

916926
return g2js.parseFile(buildGradlePath)
917927
.catch(() => {
918-
throw new Error(`Unable to parse the "android/app/build.gradle" file. Please ensure it is a well-formed Gradle file.`);
928+
throw new Error(`Unable to parse the "${buildGradlePath}" file. Please ensure it is a well-formed Gradle file.`);
919929
})
920930
.then((buildGradle: any) => {
921931
if (!buildGradle.android || !buildGradle.android.defaultConfig || !buildGradle.android.defaultConfig.versionName) {
922-
throw new Error(`The "android/app/build.gradle" file doesn't specify a value for the "android.defaultConfig.versionName" property.`);
932+
throw new Error(`The "${buildGradlePath}" file doesn't specify a value for the "android.defaultConfig.versionName" property.`);
923933
}
924934

925935
if (typeof buildGradle.android.defaultConfig.versionName !== "string") {
926-
throw new Error(`The "android.defaultConfig.versionName" property value in "android/app/build.gradle" is not a valid string. If this is expected, consider using the --targetBinaryVersion option to specify the value manually.`);
936+
throw new Error(`The "android.defaultConfig.versionName" property value in "${buildGradlePath}" is not a valid string. If this is expected, consider using the --targetBinaryVersion option to specify the value manually.`);
927937
}
928938

929939
let appVersion: string = buildGradle.android.defaultConfig.versionName.replace(/"/g, "").trim();
930940

931941
if (isValidVersion(appVersion)) {
932942
// The versionName property is a valid semver string,
933943
// so we can safely use that and move on.
944+
log(`Using the target binary version value "${appVersion}" from "${buildGradlePath}".\n`);
934945
return appVersion;
935946
} else if (/^\d.*/.test(appVersion)) {
936947
// The versionName property isn't a valid semver string,
937948
// but it starts with a number, and therefore, it can't
938949
// be a valid Gradle property reference.
939-
throw new Error(`The "android.defaultConfig.versionName" property in "android/app/build.gradle" needs to specify a valid semver string, containing both a major and minor version (e.g. 1.3.2, 1.1).`);
950+
throw new Error(`The "android.defaultConfig.versionName" property in the "${buildGradlePath}" file needs to specify a valid semver string, containing both a major and minor version (e.g. 1.3.2, 1.1).`);
940951
}
941952

942953
// The version property isn't a valid semver string
@@ -964,9 +975,10 @@ function getReactNativeProjectAppVersion(command: cli.IReleaseReactCommand, proj
964975
}
965976

966977
if (!isValidVersion(appVersion)) {
967-
throw new Error(`The "${propertyName}" property in "${propertiesFile}" needs to specify a valid semver string, containing both a major and minor version (e.g. 1.3.2, 1.1).`);
978+
throw new Error(`The "${propertyName}" property in the "${propertiesFile}" file needs to specify a valid semver string, containing both a major and minor version (e.g. 1.3.2, 1.1).`);
968979
}
969980

981+
log(`Using the target binary version value "${appVersion}" from the "${propertyName}" key in the "${propertiesFile}" file.\n`);
970982
return appVersion.toString();
971983
});
972984
} else {

0 commit comments

Comments
 (0)