Skip to content

Commit

Permalink
plugin: fix to support Cordova 9 cli
Browse files Browse the repository at this point in the history
The use of context.requireCordovaModule for non-cordova dependencies
has been removed use 'require' instead. Cordova dropped the use of
'Q' dependency to use native promises instead.
  • Loading branch information
hanieelr authored and jaimecbernardo committed Sep 17, 2019
1 parent 823fe00 commit 72ede37
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 54 deletions.
19 changes: 8 additions & 11 deletions install/hooks/android/after-prepare-build-node-assets-lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,13 @@ module.exports = function(context) {
return;
}

var Q = context.requireCordovaModule('q');
var deferral = new Q.defer();

createFileAndFolderLists(context, function(err) {
if (err) {
deferral.reject(err);
} else {
deferral.resolve();
}
return new Promise((resolve, reject) => {
createFileAndFolderLists(context, function(err) {
if (err) {
reject(err);
} else {
resolve();
}
});
});

return deferral.promise;
}
21 changes: 9 additions & 12 deletions install/hooks/android/before-plugin-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,19 @@ function unzipAll(callback) {
}

module.exports = function(context) {
var Q = context.requireCordovaModule('q');
var deferral = new Q.defer();

// Create the node project folder if it doesn't exist
if (!fs.existsSync(nodeProjectFolder)) {
fs.mkdirSync(nodeProjectFolder);
}

// Unzip the libnode.so files for each architecture
unzipAll(function(err) {
if (err) {
deferral.reject(err);
} else {
deferral.resolve();
}
return new Promise((resolve, reject) => {
// Unzip the libnode.so files for each architecture
unzipAll(function(err) {
if (err) {
reject(err);
} else {
resolve();
}
});
});

return deferral.promise;
}
2 changes: 1 addition & 1 deletion install/hooks/ios/after-plugin-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var path = require('path');
var fs = require('fs');

module.exports = function(context) {
var xcode = context.requireCordovaModule('xcode');
var xcode = require('xcode');

// Require the iOS platform Api to get the Xcode .pbxproj path.
var iosPlatformPath = path.join(context.opts.projectRoot, 'platforms', 'ios');
Expand Down
37 changes: 17 additions & 20 deletions install/hooks/ios/before-plugin-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,26 @@ const zipFileName = nodeMobileFileName + '.tar.zip';
const zipFilePath = nodeMobileFolderPath + zipFileName

module.exports = function(context) {
var Q = context.requireCordovaModule('q');
var deferral = new Q.defer();

// Create the node project folder if it doesn't exist
if (!fs.existsSync(nodeProjectFolder)) {
fs.mkdirSync(nodeProjectFolder);
}

// Unzip and untar the libnode.Framework
if (fs.existsSync(zipFilePath)) {
targz2().extract(zipFilePath, nodeMobileFolderPath, function(err) {
if (err) {
deferral.reject(err);
} else {
fs.unlinkSync(zipFilePath);
deferral.resolve();
}
});
} else if (!fs.existsSync(nodeMobileFilePath)) {
deferral.reject(new Error(nodeMobileFileName + ' is missing'));
} else {
deferral.resolve();
}

return deferral.promise;
return new Promise((resolve, reject) => {
// Unzip and untar the libnode.Framework
if (fs.existsSync(zipFilePath)) {
targz2().extract(zipFilePath, nodeMobileFolderPath, function(err) {
if (err) {
reject(err);
} else {
fs.unlinkSync(zipFilePath);
resolve();
}
});
} else if (!fs.existsSync(nodeMobileFilePath)) {
reject(new Error(nodeMobileFileName + ' is missing'));
} else {
resolve();
}
});
}
2 changes: 1 addition & 1 deletion install/hooks/ios/before-plugin-uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var path = require('path');
var fs = require('fs');

module.exports = function(context) {
var xcode = context.requireCordovaModule('xcode');
var xcode = require('xcode');

// Adds a custom function to remove script build phases, which is not supported on cordova's Xcode module yet.
xcode.project.prototype.myRemovePbxScriptBuildPhase = function (buildPhaseName, target) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"license": "MIT",
"dependencies": {
"nodejs-mobile-gyp": "^0.3.1",
"tar.gz2": "^1.0.0"
"tar.gz2": "^1.0.0",
"xcode": "^2.0.0"
},
"homepage": "https://code.janeasystems.com/nodejs-mobile",
"repository": {
Expand Down
13 changes: 5 additions & 8 deletions tests/hooks/both/install-nodejs-test-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ const path = require('path');

module.exports = function(context)
{
var Q = context.requireCordovaModule('q');
var deferral = new Q.defer();

var projectRoot = context.opts.projectRoot;
var pluginRoot = context.opts.plugin.dir;

fse.copy(path.join(pluginRoot,'nodejs-project'),path.join(projectRoot,'www','nodejs-project'))
.then( () => deferral.resolve() )
.catch ( err => deferral.reject(err) );

return deferral.promise;
return new Promise((resolve, reject) => {
fse.copy(path.join(pluginRoot,'nodejs-project'),path.join(projectRoot,'www','nodejs-project'))
.then( () => resolve() )
.catch ( err => reject(err) );
});
}

0 comments on commit 72ede37

Please sign in to comment.