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

Commit 9b39465

Browse files
committed
Improving release-react
1 parent 4193e68 commit 9b39465

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

cli/script/command-executor.ts

Lines changed: 19 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,12 @@ 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+
// seperator character, but prescribe the use of a "-" when omitted.
882+
if (command.plistFilePrefix && /.+[^-.]$/.test(command.plistFilePrefix)) {
883+
command.plistFilePrefix += "-";
884+
}
885+
878886
const iOSDirectory: string = "ios";
879887
const plistFileName = `${command.plistFilePrefix || ""}Info.plist`;
880888

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

888896
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("\", \"")}".`);
897+
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.`);
890898
}
891899
}
892900

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

901909
if (parsedPlist && parsedPlist.CFBundleShortVersionString) {
902910
if (isValidVersion(parsedPlist.CFBundleShortVersionString)) {
911+
log(`Using the target binary version value "${parsedPlist.CFBundleShortVersionString}" from "${resolvedPlistFile}".\n`);
903912
return Q(parsedPlist.CFBundleShortVersionString);
904913
} 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".`);
914+
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).`);
906915
}
907916
} else {
908917
throw new Error(`The "CFBundleShortVersionString" key doesn't exist within the "${resolvedPlistFile}" file.`);
909918
}
910919
} else if (command.platform === "android") {
911920
const buildGradlePath: string = path.join("android", "app", "build.gradle");
912921
if (fileDoesNotExistOrIsDirectory(buildGradlePath)) {
913-
throw new Error("Unable to find or read \"build.gradle\" in the \"android/app\" folder.");
922+
throw new Error(`Unable to find the "build.gradle" file in your "android/app" directory.`);
914923
}
915924

916925
return g2js.parseFile(buildGradlePath)
917926
.catch(() => {
918-
throw new Error(`Unable to parse the "android/app/build.gradle" file. Please ensure it is a well-formed Gradle file.`);
927+
throw new Error(`Unable to parse the "${buildGradlePath}" file. Please ensure it is a well-formed Gradle file.`);
919928
})
920929
.then((buildGradle: any) => {
921930
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.`);
931+
throw new Error(`The "${buildGradlePath}" file doesn't specify a value for the "android.defaultConfig.versionName" property.`);
923932
}
924933

925934
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.`);
935+
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.`);
927936
}
928937

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

931940
if (isValidVersion(appVersion)) {
932941
// The versionName property is a valid semver string,
933942
// so we can safely use that and move on.
943+
log(`Using the target binary version value "${appVersion}" from "${buildGradlePath}".\n`);
934944
return appVersion;
935945
} else if (/^\d.*/.test(appVersion)) {
936946
// The versionName property isn't a valid semver string,
937947
// but it starts with a number, and therefore, it can't
938948
// 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).`);
949+
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).`);
940950
}
941951

942952
// The version property isn't a valid semver string
@@ -964,9 +974,10 @@ function getReactNativeProjectAppVersion(command: cli.IReleaseReactCommand, proj
964974
}
965975

966976
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).`);
977+
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).`);
968978
}
969979

980+
log(`Using the target binary version value "${appVersion}" from the "${propertyName}" key in the "${propertiesFile}" file.\n`);
970981
return appVersion.toString();
971982
});
972983
} else {

0 commit comments

Comments
 (0)