Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Added post install script. (#345)
Browse files Browse the repository at this point in the history
* Added post install script.

Added post install script to resolve different versions of file and file transfer plugin for different cordova versions.

* Refactored a few lines.

* Replaced exec method with sync version and added more output to the script.

* Fixed logic: no need to install anything if plugin is present.

Fixed versions of compatible plugins.

* Fixed formatting.

* Added support for phonegap cli.

Wrapped some functions in try..catch blocks.

* Fixed formatting.

* Renamed folder.
  • Loading branch information
Anna Kocheshkova authored and sergey-akhalkov committed Jan 10, 2018
1 parent f66839f commit 131c19a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
47 changes: 47 additions & 0 deletions hooks/beforeInstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module.exports = function (ctx) {
var execSync = require('child_process').execSync;
var Q = ctx.requireCordovaModule('q');
var deferral = new Q.defer();

var cordovaCLI = "cordova";
try {
execSync(cordovaCLI);
} catch (e) {
try {
cordovaCLI = "phonegap";
execSync(cordovaCLI);
} catch (e) {
deferral.reject("An error occured. Please ensure that either the Cordova or PhoneGap CLI is installed.");
}
}

console.log("Detecting cordova version...");
var cordovaVersion = ctx.opts.cordova.version;
console.log("Cordova version is " + cordovaVersion);

var plugins = execSync(cordovaCLI + ' plugin ls');
if (!plugins.includes('cordova-plugin-file-transfer')) {
if (parseFloat(cordovaVersion) < 6.3) {
if (!plugins.includes('cordova-plugin-file')) {
console.log("Installing the compatible version of file plugin... ");
execSync(cordovaCLI + ' plugin add [email protected]');
}
console.log("Installing the compatible version of file transfer plugin... ");
execSync(cordovaCLI + ' plugin add [email protected]');
} else {
try {
console.log("Installing the latest version of file-transfer plugin... ");
execSync(cordovaCLI + ' plugin add cordova-plugin-file-transfer@latest');
} catch (e) {
console.log('The version of file plugin appears to be incompatible with the latest file transfer version. Installing compatible version of file transfer.... ');
execSync(cordovaCLI + ' plugin add [email protected]');
}
}
}
if (!plugins.includes('cordova-plugin-zip')) {
execSync(cordovaCLI + ' plugin add cordova-plugin-zip');
}
deferral.resolve();

return deferral.promise;
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"name": "cordova-plugin-code-push",
"version": "1.11.0",
"description": "CodePush Plugin for Apache Cordova",
Expand Down Expand Up @@ -52,4 +52,4 @@
"tslint": "^4.5.1",
"typescript": "^2.5.2"
}
}
}
5 changes: 2 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-code-push" version="1.11.0">
<name>CodePush</name>
<description>This plugin allows you to push code updates to your apps instantly using the CodePush service</description>
<license>MIT</license>
<keywords>cordova,code,push</keywords>
<repo>https://github.com/Microsoft/cordova-plugin-code-push.git</repo>

<hook type="before_plugin_install" src="scripts/beforeInstall.js" />
<dependency id="code-push" version="2.0.4" />
<dependency id="cordova-plugin-file-transfer" version="1.6.3" />
<dependency id="cordova-plugin-zip" version=">=3.0.0" />
<dependency id="cordova-plugin-dialogs" version=">=1.1.1" />
<dependency id="cordova-plugin-device" version=">=1.1.0" />

Expand Down

0 comments on commit 131c19a

Please sign in to comment.