[add]添加cordova完整性检验

This commit is contained in:
林文杰
2020-12-31 16:38:20 +08:00
commit 0ea70324cb
21 changed files with 1259 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
module.exports = function (msg, exception) {
process.stdout.write('\n[完整性检验] ERROR! ' + msg + '\n');
throw new Error(exception);
};
+32
View File
@@ -0,0 +1,32 @@
var helpers = require('./');
module.exports = function (platform, fileName) {
var path = require('path');
var fs = require('fs');
var cordovaUtil = this.requireCordovaModule('cordova-lib/src/cordova/util');
var projectRoot = cordovaUtil.isCordova();
var platformPath = path.join(projectRoot, 'platforms', platform);
var sourceFile;
var content;
if (platform === 'android') {
var fileBasename = fileName;
var filePath = 'com/cescit/integrity/' + fileBasename + '.java';
try {
sourceFile = path.join(platformPath, 'app/src/main/java', filePath);
content = fs.readFileSync(sourceFile, 'utf-8');
} catch (_e) {
try {
sourceFile = path.join(platformPath, 'src', filePath);
content = fs.readFileSync(sourceFile, 'utf-8');
} catch (e) {
helpers.exit('Unable to read java class source at path ' + sourceFile, e);
}
}
}
return {
content: content,
path: sourceFile
};
};
+5
View File
@@ -0,0 +1,5 @@
module.exports = function () {
return (this.opts.platforms || this.opts.cordova.platforms || []).filter(function (platform) {
return this.opts.plugin.pluginInfo.getPlatformsArray().indexOf(platform) > -1;
}, this);
};
+26
View File
@@ -0,0 +1,26 @@
/**
* Exit script with custom error log.
* @param {string} msg - Error message.
* @param {Error} exception
*/
exports.exit = require('./error_exit');
/**
* Get the real list of platforms affected by a running plugin hook.
* @param {Object} context - Cordova context.
*/
exports.getPlatformsList = invokeHelper.bind(null, './get_platforms_list');
/**
* Detect if the context process is running with verbose option.
* @param {Object} context - Cordova context.
*/
exports.isVerbose = invokeHelper.bind(null, './is_verbose');
exports.getFileMapContent = invokeHelper.bind(null, './getFileMapContent');
function invokeHelper (path) {
var helper = require(path);
var context = arguments[1];
return helper.apply(context, Array.prototype.splice.call(arguments, 2));
}
+4
View File
@@ -0,0 +1,4 @@
module.exports = function () {
return this.opts && this.opts.options && this.opts.options.verbose ||
typeof this.cmdLine === 'string' && this.cmdLine.indexOf(' -verbose') > -1;
};