CB-6481 Add unified hooks support for cordova app and plugins
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:rim="http://www.blackberry.com/ns/widgets" id="org.apache.cordova.debug.wp8" version="0.0.1-dev"> <name>WP8 Debugger</name> <description>Cordova WP8 Debugger Plugin</description> <license>Apache 2.0</license> <keywords>cordova,debug, wp8</keywords> <repo></repo> <issue></issue> </plugin>
<platform name="wp8"> <hook type="pre_package" src="scripts/injectDebugger.js" /> <hook type="after_run" src="scripts/startDebugServer.js" /> </platform>
module.exports = function(ctx) { if(ctx.cmdLine.indexOf('--debug') <= 0) { // debugger should run in debug mode only return; } console.log('WP8Debugger: preparing js files for debugging...'); var serverRoot = path.join(ctx.opts.plugin.dir, 'Aardwolf'); var serverWwwCopyDir = path.join(serverRoot, 'files/www'); var platformRoot = path.join(ctx.opts.projectRoot, 'platforms/wp8'); console.log('Copy original www content'); if (fs.existsSync(serverWwwCopyDir)) { shell.rm('-rf', serverWwwCopyDir) } shell.cp('-rf', path.join(platformRoot, 'www/*'), serverWwwCopyDir); console.log('Rewriting js files'); rewriteFilesInDir(platformRoot, path.join(platformRoot, 'www')); console.log('config: ' + JSON.stringify(config)); console.log('inject Aardwolf to cordova.js'); var content = 'window.AardwolfServerUrl = "http://' + config.serverHost + ':' + config.serverPort + '";'; content += fs.readFileSync(path.join(serverRoot, 'js/aardwolf.js')).toString(); content += fs.readFileSync(path.join(platformRoot, 'www/cordova.js')).toString(); fs.writeFileSync(path.join(platformRoot, 'www/cordova.js'), content); console.log('WP8Debugger: done!'); }
module.exports = function(ctx) { if(ctx.cmdLine.indexOf('--debug') <= 0) { // debugger should run in debug mode only return; } console.log('WP8Debugger: launching debug server...'); console.log('WP8Debugger: debug server host:' + config.serverHost); var serverRoot = path.join(ctx.opts.plugin.dir, 'Aardwolf'); shell.exec("explorer " + '"http://' + config.serverHost + ':' + config.serverPort + '"'); var cmdLine = 'node ' + path.join(serverRoot, 'app.js') + ' -h ' + config.serverHost; console.log(cmdLine); shell.exec(cmdLine); }
npm install -g cordova
cordova create testApp cd testApp
cordova plugin add location-of-cordova-debug-wp8
cordova run wp8 --debug
Source: https://habr.com/ru/post/241722/
All Articles