cordova-androidx-build
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "cordova-androidx-build", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "This plugin helps to build your app with AndroidX library. ", | ||
@@ -5,0 +5,0 @@ "cordova": { |
@@ -0,45 +1,98 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const CONFLICT_PLUGINS = [ | ||
'cordova-plugin-androidx-adapter' | ||
]; | ||
const TARGET_HOOKS = [ | ||
'before_platform_add', | ||
'before_platform_ls', | ||
'before_prepare', | ||
'before_compile', | ||
'before_plugin_add', | ||
'before_plugin_ls', | ||
'before_plugin_install', | ||
'after_platform_add', | ||
'after_platform_ls', | ||
'after_prepare', | ||
'after_compile', | ||
'after_plugin_add', | ||
'after_plugin_ls', | ||
'after_plugin_install' | ||
]; | ||
const DUMMY_SCRIPT_CODE = new Uint8Array(Buffer.from("/* This plugin is replaced by cordova-androidx-build */\nmodule.exports = function () {return Promise.resolve();};")); | ||
module.exports = function (ctx) { | ||
var targetPlugins = {}; | ||
CONFLICT_PLUGINS.forEach(function(pluginId) { | ||
targetPlugins[pluginId] = 1; | ||
}); | ||
var PluginInfoProvider = require('cordova-common').PluginInfoProvider; | ||
var projectRoot = ctx.opts.projectRoot; | ||
var pluginsDir = path.join(projectRoot, 'plugins'); | ||
var opts = { | ||
'projectRoot': projectRoot, | ||
'platforms': ['android'] | ||
}; | ||
var path = require('path'); | ||
// console.log(ctx.opts); | ||
var projectRoot = ctx.opts.projectRoot; | ||
return (new Promise(function (resolve, reject) { | ||
var pluginsDir = path.join(projectRoot, 'plugins'); | ||
return (new Promise(function (resolve) { | ||
var pluginInfoProvider = new PluginInfoProvider(); | ||
var plugins = pluginInfoProvider.getAllWithinSearchPath(pluginsDir); | ||
var pluginInfo; | ||
var needToUninstall = false; | ||
for (var i = 0; i < plugins.length; i++) { | ||
pluginInfo = plugins[i]; | ||
if (pluginInfo.id === 'cordova-plugin-androidx-adapter') { | ||
needToUninstall = true; | ||
break; | ||
plugins = plugins.filter(function(pluginInfo) { | ||
return (pluginInfo.id in targetPlugins); | ||
}); | ||
resolve(plugins); | ||
})) | ||
.then(function(plugins) { | ||
return (new Promise(function(resolve) { | ||
var hookScripts = []; | ||
plugins.forEach(function(pluginInfo) { | ||
TARGET_HOOKS.forEach(function(hook) { | ||
var scripts = pluginInfo.getHookScripts(hook, ['android']); | ||
scripts = scripts.map(function(element) { | ||
return path.join(pluginsDir, pluginInfo.id, element.attrib.src); | ||
}); | ||
hookScripts = hookScripts.concat(scripts); | ||
}) | ||
}); | ||
resolve(hookScripts); | ||
})); | ||
}) | ||
.then(function(hookScripts) { | ||
hookScripts = hookScripts.filter(function(srcFilePath) { | ||
var backUpFilePath = srcFilePath + '.bak'; | ||
try { | ||
fs.accessSync(backUpFilePath, fs.constants.R_OK); | ||
return false; | ||
} catch (err) { | ||
return true; | ||
} | ||
} | ||
}); | ||
if (needToUninstall) { | ||
console.info('--[cordova-androidx-build]------------------------'); | ||
console.info('Since cordova-plugin-androidx-adapter breaks cordova-androidx-build code,'); | ||
console.info('uninstall cordova-plugin-androidx-adapter automatically.'); | ||
console.info('-----------------------------------------------------'); | ||
var tasks = hookScripts.map(function(srcFilePath) { | ||
var backUpFilePath = srcFilePath + '.bak'; | ||
var exec = require('child_process').exec; | ||
exec('cordova plugin rm cordova-plugin-androidx-adapter 2>&1', function (err, stdout) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
console.log(stdout); | ||
exec('npm uninstall cordova-plugin-androidx-adapter --save 2>&1', function () { | ||
return (new Promise(function(resolve) { | ||
fs.copyFile(srcFilePath, backUpFilePath, function() { | ||
console.log(backUpFilePath); | ||
resolve(); | ||
}); | ||
})) | ||
.then(function() { | ||
return (new Promise(function(resolve) { | ||
fs.writeFile(srcFilePath, DUMMY_SCRIPT_CODE, function(err) { | ||
resolve(); | ||
}); | ||
} | ||
})); | ||
}); | ||
} else { | ||
resolve(); | ||
} | ||
})); | ||
}); | ||
return Promise.all(tasks); | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
292733
87
0
1