Skip to content

Commit

Permalink
make init command run on Linux
Browse files Browse the repository at this point in the history
- xcode based commands now checks for xcode availability, updates config lazily
  • Loading branch information
drapanjanas committed Dec 9, 2015
1 parent 380c922 commit d100bed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Generated project works in iOS and Android devices.
- "Debug in Chrome" is not required anymore.
- 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
- Works on Linux (Android only)

## Usage

Expand Down Expand Up @@ -212,9 +213,8 @@ tools.
- [Node.js](https://nodejs.org) `>=4.0.0`
- [Leiningen](http://leiningen.org) `>=2.5.3`
- [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`
- [Watchman](https://facebook.github.io/watchman) `>=3.7.0`


## Aspirations
Expand Down
42 changes: 25 additions & 17 deletions re-natal.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,22 @@ ensureFreePort = (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) ->
log 'Creating Re-Natal config'
config =
name: name
device: getUuidForDevice 'iPhone 6'

writeConfig config
config
Expand Down Expand Up @@ -202,8 +212,6 @@ init = (projName) ->
throw new Error "Directory #{projNameHyph} already exists"

exec 'type lein'
exec 'type watchman'
exec 'type xcodebuild'

log 'Creating Leiningen project'
exec "lein new #{projNameHyph}"
Expand Down Expand Up @@ -315,10 +323,6 @@ init = (projName) ->
logErr \
if message.match /type.+lein/i
'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
"npm install failed. This may be a network issue. Check #{projNameHyph}/npm-debug.log for details."
else
Expand Down Expand Up @@ -437,7 +441,8 @@ cli.command 'init <name>'
cli.command 'launch'
.description 'compile project and run in iOS simulator'
.action ->
ensureFreePort -> launch readConfig()
ensureXcode ->
ensureFreePort -> launch readConfig()

cli.command 'upgrade'
.description 'upgrades project files to current installed version of re-natal (the upgrade of re-natal itself is done via npm)'
Expand All @@ -447,24 +452,27 @@ cli.command 'upgrade'
cli.command 'listdevices'
.description 'list available simulator devices by index'
.action ->
console.log (getDeviceList()
.map (line, i) -> "#{i}\t#{line.replace /\[.+\]/, ''}"
.join '\n')
ensureXcode ->
console.log (getDeviceList()
.map (line, i) -> "#{i}\t#{line.replace /\[.+\]/, ''}"
.join '\n')

cli.command 'setdevice <index>'
.description 'choose simulator device by index'
.action (index) ->
unless device = getDeviceList()[parseInt index, 10]
logErr 'Invalid device index. Run re-natal listdevices for valid indexes.'
ensureXcode ->
unless device = getDeviceList()[parseInt index, 10]
logErr 'Invalid device index. Run re-natal listdevices for valid indexes.'

config = readConfig()
config.device = pluckUuid device
writeConfig config
config = readConfig()
config.device = pluckUuid device
writeConfig config

cli.command 'xcode'
.description 'open Xcode project'
.action ->
openXcode readConfig().name
ensureXcode ->
openXcode readConfig().name

cli.command 'deps'
.description 'install all dependencies for the project'
Expand Down

0 comments on commit d100bed

Please sign in to comment.