Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"use strict";
var path = require("path");
var fs = require("fs");
module.exports = function(ctx) {
var q = ctx.requireCordovaModule("q");
var deferreds = [];
//note: https://github.com/phonegap/phonegap-plugin-barcodescanner/issues/233
deferreds.push((function(deferred) {
ctx.requireCordovaModule("glob")("phonegap-plugin-barcodescanner/*.gradle",
{
cwd: path.join(ctx.opts.projectRoot, "platforms/android"),
realpath: true
},
function(errGlob, files) {
if (errGlob) {
return deferred.reject(errGlob);
}
return q.all(files.map(function(file) {
var fileDeferred = q.defer();
fs.readFile(file, "utf8", function(errRead, fileContent) {
if (errRead) {
return fileDeferred.reject(errRead);
}
var matchRegexp = /^ext\.cdvMinSdkVersion\s+=.*/mg;
if (!matchRegexp.test(fileContent)) {
return fileDeferred.resolve();
}
return fs.writeFile(file, fileContent.replace(matchRegexp, ""), "utf8", function(errWrite) {
if (errWrite) {
return fileDeferred.reject(errWrite);
}
return fileDeferred.resolve();
});
});
return fileDeferred.promise;
}))
.then(function() {
return deferred.resolve();
}, function(err) {
return deferred.reject(err);
});
});
return deferred.promise;
})(q.defer()));
return q.all(deferreds)
.then(function() {
return ctx;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.