From 0264ba6031260922bc10fe7b1c5d98bc85fe45c6 Mon Sep 17 00:00:00 2001 From: Jhen Date: Wed, 10 Aug 2016 13:07:46 +0800 Subject: [PATCH] Support new `react-native-macos` package name --- README.md | 2 +- bin/remotedev.js | 35 ++++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 48fdc32..90b4644 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Change `hostname` and `port` to the values you want. } ``` -The `injectserver` value can be `reactnative` or `desktop` ([react-native-desktop](https://github.com/ptmt/react-native-desktop)), it used `reactnative` by default. +The `injectserver` value can be `reactnative` or `macos` ([react-native-macos](https://github.com/ptmt/react-native-macos)), it used `reactnative` by default. Then, we can start React Native server and RemoteDev server with one command: diff --git a/bin/remotedev.js b/bin/remotedev.js index 1acb502..1604df9 100755 --- a/bin/remotedev.js +++ b/bin/remotedev.js @@ -23,6 +23,9 @@ function log(pass, msg) { function getModuleName(type) { switch (type) { + case 'macos': + return 'react-native-macos'; + // react-native-macos is renamed from react-native-desktop case 'desktop': return 'react-native-desktop'; case 'reactnative': @@ -35,28 +38,34 @@ function getModulePath(moduleName) { return path.join(process.cwd(), 'node_modules', moduleName); } +function getModule(type) { + var moduleName = getModuleName(type); + var modulePath = getModulePath(moduleName); + if (type === 'desktop' && !fs.existsSync(modulePath)) { + moduleName = getModuleName('macos'); + modulePath = getModulePath(moduleName); + } + return { + name: moduleName, + path: modulePath + }; +} + if (argv.revert) { - var moduleName = getModuleName(argv.revert); - var pass = injectServer.revert( - getModulePath(moduleName), - moduleName - ); + var module = getModule(argv.revert); + var pass = injectServer.revert(module.path, module.name); var msg = 'Revert injection of RemoteDev server from React Native local server'; - log(pass, msg + (!pass ? ', the file `' + injectServer.fullPath + '` not found.' : '.')); + log(pass, msg + (!pass ? ', the file `' + path.join(module.name, injectServer.fullPath) + '` not found.' : '.')); process.exit(pass ? 0 : 1); } if (argv.injectserver) { var options = getOptions(argv); - var moduleName = getModuleName(argv.injectserver) - var pass = injectServer.inject( - getModulePath(moduleName), - options, - moduleName - ); + var module = getModule(argv.injectserver); + var pass = injectServer.inject(module.path, options, module.name); var msg = 'Inject RemoteDev server into React Native local server'; - log(pass, msg + (pass ? '.' : ', the file `' + injectServer.fullPath + '` not found.')); + log(pass, msg + (pass ? '.' : ', the file `' + path.join(module.name, injectServer.fullPath) + '` not found.')); process.exit(pass ? 0 : 1); }