make init command run on Linux

- xcode based commands now checks for xcode availability, updates config lazily
This commit is contained in:
Artur Girenko 2015-12-09 22:32:25 +01:00
parent 380c922430
commit d100bed400
2 changed files with 27 additions and 19 deletions

View File

@ -29,6 +29,7 @@ Generated project works in iOS and Android devices.
- "Debug in Chrome" is not required anymore. - "Debug in Chrome" is not required anymore.
- Optimizations :simple is used to compile "production" index.ios.js and index.android.js - Optimizations :simple is used to compile "production" index.ios.js and index.android.js
- [Unified way of using static images of rn 0.14+](https://facebook.github.io/react-native/docs/images.html) works - [Unified way of using static images of rn 0.14+](https://facebook.github.io/react-native/docs/images.html) works
- Works on Linux (Android only)
## Usage ## Usage
@ -212,9 +213,8 @@ tools.
- [Node.js](https://nodejs.org) `>=4.0.0` - [Node.js](https://nodejs.org) `>=4.0.0`
- [Leiningen](http://leiningen.org) `>=2.5.3` - [Leiningen](http://leiningen.org) `>=2.5.3`
- [Java 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html) - [Java 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
- [Xcode](https://developer.apple.com/xcode) (+ Command Line Tools) `>=6.3` - [Xcode](https://developer.apple.com/xcode) (+ Command Line Tools) `>=6.3` (optional for Android)
- [OS X](http://www.apple.com/osx) `>=10.10` - [OS X](http://www.apple.com/osx) `>=10.10`
- [Watchman](https://facebook.github.io/watchman) `>=3.7.0`
## Aspirations ## Aspirations

View File

@ -97,12 +97,22 @@ ensureFreePort = (cb) ->
" "
cb() cb()
ensureXcode = (cb) ->
try
exec 'type xcodebuild'
config = readConfig()
unless config.device?
config.device = getUuidForDevice 'iPhone 6'
writeConfig config
cb();
catch {message}
if message.match /type.+xcodebuild/i
logErr 'Xcode Command Line Tools are required'
generateConfig = (name) -> generateConfig = (name) ->
log 'Creating Re-Natal config' log 'Creating Re-Natal config'
config = config =
name: name name: name
device: getUuidForDevice 'iPhone 6'
writeConfig config writeConfig config
config config
@ -202,8 +212,6 @@ init = (projName) ->
throw new Error "Directory #{projNameHyph} already exists" throw new Error "Directory #{projNameHyph} already exists"
exec 'type lein' exec 'type lein'
exec 'type watchman'
exec 'type xcodebuild'
log 'Creating Leiningen project' log 'Creating Leiningen project'
exec "lein new #{projNameHyph}" exec "lein new #{projNameHyph}"
@ -315,10 +323,6 @@ init = (projName) ->
logErr \ logErr \
if message.match /type.+lein/i if message.match /type.+lein/i
'Leiningen is required (http://leiningen.org)' 'Leiningen is required (http://leiningen.org)'
else if message.match /type.+watchman/i
'Watchman is required (https://facebook.github.io/watchman)'
else if message.match /type.+xcodebuild/i
'Xcode Command Line Tools are required'
else if message.match /npm/i else if message.match /npm/i
"npm install failed. This may be a network issue. Check #{projNameHyph}/npm-debug.log for details." "npm install failed. This may be a network issue. Check #{projNameHyph}/npm-debug.log for details."
else else
@ -437,7 +441,8 @@ cli.command 'init <name>'
cli.command 'launch' cli.command 'launch'
.description 'compile project and run in iOS simulator' .description 'compile project and run in iOS simulator'
.action -> .action ->
ensureFreePort -> launch readConfig() ensureXcode ->
ensureFreePort -> launch readConfig()
cli.command 'upgrade' cli.command 'upgrade'
.description 'upgrades project files to current installed version of re-natal (the upgrade of re-natal itself is done via npm)' .description 'upgrades project files to current installed version of re-natal (the upgrade of re-natal itself is done via npm)'
@ -447,24 +452,27 @@ cli.command 'upgrade'
cli.command 'listdevices' cli.command 'listdevices'
.description 'list available simulator devices by index' .description 'list available simulator devices by index'
.action -> .action ->
console.log (getDeviceList() ensureXcode ->
.map (line, i) -> "#{i}\t#{line.replace /\[.+\]/, ''}" console.log (getDeviceList()
.join '\n') .map (line, i) -> "#{i}\t#{line.replace /\[.+\]/, ''}"
.join '\n')
cli.command 'setdevice <index>' cli.command 'setdevice <index>'
.description 'choose simulator device by index' .description 'choose simulator device by index'
.action (index) -> .action (index) ->
unless device = getDeviceList()[parseInt index, 10] ensureXcode ->
logErr 'Invalid device index. Run re-natal listdevices for valid indexes.' unless device = getDeviceList()[parseInt index, 10]
logErr 'Invalid device index. Run re-natal listdevices for valid indexes.'
config = readConfig() config = readConfig()
config.device = pluckUuid device config.device = pluckUuid device
writeConfig config writeConfig config
cli.command 'xcode' cli.command 'xcode'
.description 'open Xcode project' .description 'open Xcode project'
.action -> .action ->
openXcode readConfig().name ensureXcode ->
openXcode readConfig().name
cli.command 'deps' cli.command 'deps'
.description 'install all dependencies for the project' .description 'install all dependencies for the project'