Skip to content

Commit

Permalink
Use standard module resolution for scripts
Browse files Browse the repository at this point in the history
Cordova 9 removed support for built-in module
resolution in place of standard approach.
  • Loading branch information
Joel Skrepnek authored and nymerias committed Apr 24, 2019
1 parent 7c52fac commit 219739d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
30 changes: 14 additions & 16 deletions intercom-plugin/scripts/checkForUpdate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function fetchUpdateInfo(context, callback) {
var fs = context.requireCordovaModule('fs');
var fs = require('fs');

function fetchUpdateInfo(callback) {
var updateInfo = {
releaseDate: 0,
podUpdateDate: 0,
Expand All @@ -18,18 +18,16 @@ function fetchUpdateInfo(context, callback) {
});
}

function writeUpdateInfo(context, updateInfo, callback) {
var fs = context.requireCordovaModule('fs');
function writeUpdateInfo(updateInfo, callback) {
fs.writeFile('platforms/ios/.intercom_update', JSON.stringify(updateInfo), 'utf8', function (err,data) {
callback();
});
}

function updateIntercomIfNeeded(context, updateInfo, callback) {
var exec = context.requireCordovaModule('child_process').exec;

function updateIntercomIfNeeded(updateInfo, callback) {
var exec = require('child_process').exec;
var completion = function() {
writeUpdateInfo(context, updateInfo, function() {
writeUpdateInfo(updateInfo, function() {
callback();
});
};
Expand All @@ -48,8 +46,8 @@ function updateIntercomIfNeeded(context, updateInfo, callback) {
}
}

function fetchLatestRelease(context, callback) {
var https = context.requireCordovaModule('https');
function fetchLatestRelease(callback) {
var https = require('https');

var req = https.get({
headers: {
Expand Down Expand Up @@ -78,14 +76,14 @@ function fetchLatestRelease(context, callback) {
});
}

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

fetchUpdateInfo(context, function(updateInfo) {
fetchUpdateInfo(function(updateInfo) {
// Check at most once every 48 hours
if (Date.now() - updateInfo.lastCheckDate > 1000 * 60 * 60 * 48) {
fetchLatestRelease(context, function(releaseData) {
fetchLatestRelease(function(releaseData) {
updateInfo.lastCheckDate = Date.now();

if (releaseData != null) {
Expand All @@ -95,7 +93,7 @@ module.exports = function(context) {
updateInfo.releaseDate = Date.now();
}

updateIntercomIfNeeded(context, updateInfo, function() {
updateIntercomIfNeeded(updateInfo, function() {
deferral.resolve();
});
});
Expand Down
9 changes: 5 additions & 4 deletions intercom-plugin/scripts/prepareCocoaPods.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = function(context) {
var Q = context.requireCordovaModule('q');
var deferral = new Q.defer();
var exec = context.requireCordovaModule('child_process').exec;
module.exports = function() {
var q = require('q');
var exec = require('child_process').exec;

var deferral = new q.defer();

console.log('Updating CocoaPods specs repo');
exec('pod repo update master', function(error, stdout, stderr) {
Expand Down

0 comments on commit 219739d

Please sign in to comment.