使用Ionic / Cordova / Android
。
我已按以下方式在文件before_plugin_install
上配置了挂钩:config.xml
:
<platform name="android">
...
<hook type="before_plugin_install" src="scripts/my_test_hook.js" />
...
</platform>
然后,文件:scripts/my_test_hook.js
具有以下内容:
module.exports = function(ctx) {
console.log('#########################################');
console.log(ctx);
};
然后,在控制台上,我得到:
Installing "cordova-plugin-console" for android
#########################################
Context {
hook: 'before_plugin_install',
opts:
{ cordova: { platforms: [Object], plugins: [Object], version: '6.4.0' },
plugin: undefined,
nohooks: undefined,
projectRoot: 'D:\\wamp64\\www\\ionic2\\tester-cordova-plugins\\01' },
cmdLine: 'C:\\Program Files\\nodejs\\node.exe C:\\Users\\David\\AppData\\Roaming\\npm\\node_modules\\cordova\\bin\\cordova platform add android',
cordova:
{ binname: [Getter/Setter],
on: [Function: on],
off: [Function: off],
removeListener: [Function: off],
removeAllListeners: [Function: removeAllListeners],
emit: [Function: emit],
trigger: [Function: emit],
raw: {},
findProjectRoot: [Function],
prepare: [Function],
build: [Function],
create: [Function],
emulate: [Function],
plugin: [Function],
plugins: [Function],
platform: [Function],
platforms: [Function],
compile: [Function],
run: [Function],
info: [Function],
targets: [Function],
requirements: [Function],
projectMetadata: [Function],
clean: [Function] },
scriptLocation: 'D:\\wamp64\\www\\ionic2\\tester-cordova-plugins\\01\\scripts\\my_test_hook.js' }
我的问题是:如何从文件中获取:scripts/my_test_hook.js
(要console.log(...)
}插件的名称,在上面的例子中:cordova-plugin-console
?