Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes #33] Replaced "www/" Cordova paths by Capacitor's "public/" ones #35

Merged
merged 9 commits into from
Jul 8, 2021
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## TypeScript

All the JS code in this plugin is compiled from TypeScript sources. Please do not submit pull requests with direct changes to the JS files in `bin` directory.
Instead, modify the sources in the `www` folder and compile a new version of the plugin. Read on for more details.
Instead, modify the sources in the `src` folder and compile a new version of the plugin. Read on for more details.

## Building the plugin

Expand Down
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ Once your app has been configured and distributed to your users, and you've made
In it's the most basic form, this command only requires one parameter: your owner name + "/" + app name.

```shell
appcenter codepush release -a <ownerName>/<appName> -c www/
# Generic
appcenter codepush release -a <ownerName>/<appName> -c public/

appcenter codepush release -a <ownerName>/MyApp-ios -c www/
appcenter codepush release -a <ownerName>/MyApp-Android -c www/
# iOS
appcenter codepush release -a <ownerName>/MyApp-ios -c ios/App/App/public/

# Android
appcenter codepush release -a <ownerName>/MyApp-Android -c android/app/src/main/assets/public/
```

*NOTE: When releasing updates to CodePush, you do not need to bump your app's version in the `config.xml` file, since you aren't modifying the binary version at all. You only need to bump this version when you upgrade Capacitor and/or one of your plugins, at which point, you need to release an update to the native store(s). CodePush will automatically generate a "label" for each release you make (e.g. `v3`) in order to help identify it within your release history.*
Expand All @@ -135,28 +139,34 @@ The `release` command enables such a simple workflow because it understands the

```shell
# Release a mandatory update with a changelog
appcenter codepush release -a <ownerName>/MyApp-ios -c www/ -m --description "Modified the header color"
appcenter codepush release -a <ownerName>/MyApp-ios -c ios/App/App/public/ -m --description "Modified the header color"

# Release a dev Android build to just 1/4 of your end users
appcenter codepush release -a <ownerName>/MyApp-android -c www/ --rollout 25
appcenter codepush release -a <ownerName>/MyApp-android -c android/app/src/main/assets/public/ --rollout 25

# Release an update that targets users running any 1.1.* binary, as opposed to
# limiting the update to exact version name in the config.xml file
appcenter codepush release -a <ownerName>/MyApp-android -c www/ --target-binary-version "~1.1.0"
appcenter codepush release -a <ownerName>/MyApp-android -c android/app/src/main/assets/public/ --target-binary-version "~1.1.0"

# Release an update now but mark it as disabled
# so that no users can download it yet
appcenter codepush release -a <ownerName>/MyApp-ios -c www/ -x
appcenter codepush release -a <ownerName>/MyApp-ios -c ios/App/App/public/ -x

# Release an update signed by private key (public key should be configured for application)
appcenter codepush release -a <ownerName>/MyApp-android --private-key-path ~/rsa/private_key.pem
appcenter codepush release -a <ownerName>/MyApp-android -c android/app/src/main/assets/public/ --privateKeyPath ~/rsa/private_key.pem
```

*NOTE : The path you are to provide to the `-c` flag might vary depending on the platform or the framework. For example, with an Ionic Capacitor project :
- Android : `./android/app/src/main/assets/public/`
- iOS : `./ios/App/App/public/`

The CodePush client supports differential updates, so even though you are releasing your app code on every update, your end users will only actually download the files they need. The service handles this automatically so that you can focus on creating awesome apps and we can worry about optimizing end user downloads.

*NOTE: for **Ionic** apps you need to run `ionic build` before running `release` command in order to build web assets.*
*NOTE: for **Ionic** apps you need to run `ionic cap build` before running `release` command in order to build web assets.*

*NOTE: for Cordova, we used to use `appcenter codepush release-cordova`, but with Capacitor we must use `appcenter codepush release`.*

For more details about how the `release` command works, as well as the various parameters it exposes, refer to the [CLI docs](https://docs.microsoft.com/en-us/appcenter/distribution/codepush/cli#releasing-updates-general).
For more details about how the `release` command works, as well as the various parameters it exposes, refer to the [CLI docs](https://docs.microsoft.com/en-us/appcenter/distribution/codepush/cli#releasing-updates-general).

If you run into any issues, or have any questions/comments/feedback, you can open a new issue on this repo and we'll respond ASAP!

Expand Down
8 changes: 4 additions & 4 deletions android/src/main/java/com/microsoft/capacitor/CodePush.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CodePush extends Plugin {
private static final String DEPLOYMENT_KEY_PREFERENCE = "ANDROID_DEPLOY_KEY";
private static final String PUBLIC_KEY_PREFERENCE = "ANDROID_PUBLIC_KEY";
private static final String SERVER_URL_PREFERENCE = "SERVER_URL";
private static final String WWW_ASSET_PATH_PREFIX = "file:///android_asset/www/";
private static final String WWW_ASSET_PATH_PREFIX = "file:///android_asset/public/";
private static final String NEW_LINE = System.getProperty("line.separator");
private static boolean ShouldClearHistoryOnLoad = false;
private CodePushPackageManager codePushPackageManager;
Expand Down Expand Up @@ -189,7 +189,7 @@ public void getPackageHash(final PluginCall call) {
protected Void doInBackground(Void... params) {
try {
// TODO: fix client side
String binaryHash = UpdateHashUtils.getHashForPath(getActivity(), call.getString("path") + "/www");
String binaryHash = UpdateHashUtils.getHashForPath(getActivity(), call.getString("path") + "/public");
call.resolve(jsObjectValue(binaryHash));
} catch (Exception e) {
call.reject("An error occurred when trying to get the hash of the binary contents. " + e.getMessage());
Expand Down Expand Up @@ -509,7 +509,7 @@ public void run() {

private File getStartPageForPackage(String packageLocation) {
if (packageLocation != null) {
File startPage = new File(this.bridge.getContext().getFilesDir() + "/" + packageLocation, "www/index.html");
File startPage = new File(this.bridge.getContext().getFilesDir() + "/" + packageLocation, "public/index.html");
if (startPage.exists()) {
return startPage;
}
Expand All @@ -520,7 +520,7 @@ private File getStartPageForPackage(String packageLocation) {

private String getBasePathForPackage(String packageLocation) {
if (packageLocation != null) {
return new File(this.bridge.getContext().getFilesDir() + "/" + packageLocation, "www").toString();
return new File(this.bridge.getContext().getFilesDir() + "/" + packageLocation, "public").toString();
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public static String getBinaryHash(Activity activity) throws IOException, NoSuch
public static String getHashForPath(Activity activity, String path) throws IOException, NoSuchAlgorithmException, ClassNotFoundException {
ArrayList<String> manifestEntries = new ArrayList<String>();
if (path == null) {
addFolderEntriesToManifestFromAssets(manifestEntries, activity.getAssets(), "www");
addFolderEntriesToManifestFromAssets(manifestEntries, activity.getAssets(), "public");
} else {
File basePath = activity.getApplicationContext().getFilesDir();
File fullPath = new File(basePath, path);
addFolderEntriesToManifest(manifestEntries, "www", fullPath.getPath());
addFolderEntriesToManifest(manifestEntries, "public", fullPath.getPath());
}
Collections.sort(manifestEntries);
JSONArray manifestJSONArray = new JSONArray();
Expand Down
6 changes: 3 additions & 3 deletions dist/esm/localPackage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading