-
-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# react-native-debugger-patch | ||
|
||
> Replace `open debugger-ui with Chrome` to `open React Native Debugger` from react-native packager | ||
__*NOTE*__ This patch is only work with `react-native-debugger@^0.2.0`. | ||
|
||
## Installation | ||
|
||
First, install [React Native Debugger](https://github.com/jhen0409/react-native-debugger#usage). | ||
|
||
In your React Native project: | ||
|
||
```bash | ||
$ npm i --save-dev react-native-debugger-patch | ||
``` | ||
|
||
## Usage | ||
|
||
```bash | ||
$ rndebugger-patch --inject | ||
|
||
# If you want to revert injection | ||
$ rndebugger-patch --revert | ||
``` | ||
|
||
You can also use following command instead of this patch: | ||
|
||
```bash | ||
# OS X | ||
$ open rndebugger://set-debugger-loc?host=localhost&port=8082 | ||
``` | ||
|
||
## LICENSE | ||
|
||
[MIT](https://github.com/jhen0409/react-native-debugger/blob/master/LICENSE.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#! /usr/bin/env node | ||
|
||
const argv = require('minimist')(process.argv.slice(2), { | ||
boolean: ['inject', 'revert', 'desktop'], | ||
default: { | ||
inject: true, | ||
}, | ||
}); | ||
|
||
const result = require('../lib/main')(argv); | ||
if (!result) process.exit(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const name = 'react-native-debugger-patch'; | ||
const startFlag = `/* ${name} start */`; | ||
const endFlag = `/* ${name} end */`; | ||
const funcFlag = 'function launchChromeDevTools(port) {'; | ||
|
||
exports.dir = 'local-cli/server/middleware'; | ||
exports.file = 'getDevToolsMiddleware.js'; | ||
exports.fullPath = path.join(exports.dir, exports.file); | ||
|
||
exports.inject = modulePath => { | ||
const filePath = path.join(modulePath, exports.fullPath); | ||
if (!fs.existsSync(filePath)) return false; | ||
|
||
const code = [ | ||
startFlag, | ||
funcFlag, | ||
' if (process.platform === "darwin") {', | ||
' opn("rndebugger://set-debugger-loc?host=localhost&port=" + port);', | ||
' return;', | ||
' }', | ||
endFlag, | ||
].join('\n'); | ||
|
||
const middlewareCode = fs.readFileSync(filePath, 'utf-8'); | ||
let start = middlewareCode.indexOf(startFlag); // already injected ? | ||
let end = middlewareCode.indexOf(endFlag) + endFlag.length; | ||
if (start === -1) { | ||
start = middlewareCode.indexOf(funcFlag); | ||
end = start + funcFlag.length; | ||
} | ||
fs.writeFileSync( | ||
filePath, | ||
middlewareCode.substr(0, start) + code + middlewareCode.substr(end, middlewareCode.length) | ||
); | ||
return true; | ||
}; | ||
|
||
exports.revert = modulePath => { | ||
const filePath = path.join(modulePath, exports.fullPath); | ||
if (!fs.existsSync(filePath)) return false; | ||
|
||
const middlewareCode = fs.readFileSync(filePath, 'utf-8'); | ||
const start = middlewareCode.indexOf(startFlag); // already injected ? | ||
const end = middlewareCode.indexOf(endFlag) + endFlag.length; | ||
if (start !== -1) { | ||
fs.writeFileSync( | ||
filePath, | ||
middlewareCode.substr(0, start) + funcFlag + middlewareCode.substr(end, middlewareCode.length) | ||
); | ||
} | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const chalk = require('chalk'); | ||
const injectDevToolsMiddleware = require('./injectDevToolsMiddleware'); | ||
|
||
const name = 'react-native'; | ||
|
||
const getModulePath = moduleName => | ||
path.join(process.cwd(), 'node_modules', moduleName); | ||
|
||
const log = (pass, msg) => { | ||
const prefix = pass ? chalk.green.bgBlack('PASS') : chalk.red.bgBlack('FAIL'); | ||
const color = pass ? chalk.blue : chalk.red; | ||
console.log(prefix, color(msg)); | ||
}; | ||
|
||
const getFullPath = filePath => path.resolve(process.cwd(), filePath); | ||
|
||
module.exports = argv => { | ||
const modulePath = getModulePath(argv.desktop ? 'react-native-desktop' : name); | ||
|
||
// Revert injection | ||
if (argv.revert) { | ||
const passMiddleware = injectDevToolsMiddleware.revert(modulePath); | ||
const msg = 'Revert injection of React Native Debugger from React Native packager'; | ||
log(passMiddleware, msg + (!passMiddleware ? `, the file '${injectDevToolsMiddleware.path}' not found.` : '.')); | ||
return passMiddleware; | ||
} | ||
|
||
const pass = injectDevToolsMiddleware.inject(modulePath); | ||
const msg = 'Replace `open debugger-ui with Chrome` to `open React Native Debugger`'; | ||
log(pass, msg + (pass ? '.' : `, the file '${injectDevToolsMiddleware.path}' not found.`)); | ||
return pass; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "react-native-debugger-patch", | ||
"version": "0.2.0", | ||
"description": "Replace `open debugger-ui with Chrome` to `open React Native Debugger` from react-native packager", | ||
"bin": { | ||
"rndebugger-patch": "bin/rndebugger-patch.js" | ||
}, | ||
"scripts": {}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/jhen0409/react-native-debugger.git" | ||
}, | ||
"keywords": [ | ||
"react", | ||
"react-native", | ||
"debugger", | ||
"react-devtools", | ||
"redux-devtools", | ||
"electron" | ||
], | ||
"author": "Jhen <developer@jhen.me>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"chalk": "^1.1.3", | ||
"minimist": "^1.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters