support React Native 0.11

This commit is contained in:
Dan Motzenbecker 2015-10-04 17:54:48 -04:00
parent 6f07fa6db6
commit e353f75684
1 changed files with 22 additions and 17 deletions

View File

@ -10,16 +10,15 @@ crypto = require 'crypto'
cli = require 'commander' cli = require 'commander'
chalk = require 'chalk' chalk = require 'chalk'
semver = require 'semver' semver = require 'semver'
reactInit = require 'react-native/local-cli/init'
pkgJson = require __dirname + '/package.json' pkgJson = require __dirname + '/package.json'
nodeVersion = pkgJson.engines.node nodeVersion = pkgJson.engines.node
rnVersion = pkgJson.dependencies['react-native']
resources = __dirname + '/resources/' resources = __dirname + '/resources/'
camelRx = /([a-z])([A-Z])/g camelRx = /([a-z])([A-Z])/g
projNameRx = /\$PROJECT_NAME\$/g projNameRx = /\$PROJECT_NAME\$/g
projNameHyphRx = /\$PROJECT_NAME_HYPHENATED\$/g projNameHyphRx = /\$PROJECT_NAME_HYPHENATED\$/g
projNameUnderRx = /\$PROJECT_NAME_UNDERSCORED\$/g projNameUnderRx = /\$PROJECT_NAME_UNDERSCORED\$/g
rnVersion = '0.11.4'
podMinVersion = '0.38.2' podMinVersion = '0.38.2'
process.title = 'natal' process.title = 'natal'
@ -82,9 +81,9 @@ readConfig = ->
getBundleId = (name) -> getBundleId = (name) ->
try try
if line = readFile("iOS/iOS/#{name}.xcodeproj/project.pbxproj").match /PRODUCT_BUNDLE_IDENTIFIER = (.+);/ if line = readFile("native/ios/#{name}.xcodeproj/project.pbxproj").match /PRODUCT_BUNDLE_IDENTIFIER = (.+);/
line[1] line[1]
else if line = readFile("iOS/iOS/#{name}/Info.plist").match /\<key\>CFBundleIdentifier\<\/key\>\n?\s*\<string\>(.+)\<\/string\>/ else if line = readFile("native/ios/#{name}/Info.plist").match /\<key\>CFBundleIdentifier\<\/key\>\n?\s*\<string\>(.+)\<\/string\>/
rfcIdRx = /\$\(PRODUCT_NAME\:rfc1034identifier\)/ rfcIdRx = /\$\(PRODUCT_NAME\:rfc1034identifier\)/
if line[1].match rfcIdRx if line[1].match rfcIdRx
@ -140,12 +139,9 @@ init = (projName) ->
exec 'lein cljsbuild once dev' exec 'lein cljsbuild once dev'
log 'Creating React Native skeleton' log 'Creating React Native skeleton'
fs.mkdirSync 'iOS' fs.mkdirSync 'native'
process.chdir 'iOS' process.chdir 'native'
_log = console.log
global.console.log = ->
reactInit '.', projName
global.console.log = _log
fs.writeFileSync 'package.json', JSON.stringify fs.writeFileSync 'package.json', JSON.stringify
name: projName name: projName
version: '0.0.1' version: '0.0.1'
@ -155,10 +151,19 @@ init = (projName) ->
dependencies: dependencies:
'react-native': rnVersion 'react-native': rnVersion
, null, 2 , null, 2
exec 'npm i' exec 'npm i'
exec "
node -e
\"process.argv[3]='#{projName}';
require('react-native/local-cli/init')('.', '#{projName}')\"
"
exec 'rm -rf android'
fs.unlinkSync 'index.android.js'
log 'Installing Pod dependencies' log 'Installing Pod dependencies'
process.chdir 'iOS' process.chdir 'ios'
exec "cp #{resources}Podfile ." exec "cp #{resources}Podfile ."
exec 'pod install' exec 'pod install'
@ -194,7 +199,7 @@ init = (projName) ->
[ [
/\/\* End PBXFileReference section \*\// /\/\* End PBXFileReference section \*\//
"\t\t#{uuid1} /* out */ = {isa = PBXFileReference; lastKnownFileType "\t\t#{uuid1} /* out */ = {isa = PBXFileReference; lastKnownFileType
= folder; name = out; path = ../../../target/out; = folder; name = out; path = ../../target/out;
sourceTree = \"<group>\"; };\n/* End PBXFileReference section */" sourceTree = \"<group>\"; };\n/* End PBXFileReference section */"
] ]
[ [
@ -269,11 +274,11 @@ init = (projName) ->
launch = ({name, device}) -> launch = ({name, device}) ->
log 'Building Xcode project' log 'Compiling Xcode project'
try try
exec " exec "
xcodebuild xcodebuild
-workspace iOS/iOS/#{name}.xcworkspace -workspace native/ios/#{name}.xcworkspace
-scheme #{name} -scheme #{name}
-destination platform='iOS Simulator',OS=latest,id='#{device}' -destination platform='iOS Simulator',OS=latest,id='#{device}'
clean test clean test
@ -288,16 +293,16 @@ launch = ({name, device}) ->
openXcode = (name) -> openXcode = (name) ->
try try
exec "open iOS/iOS/#{name}.xcworkspace" exec "open native/ios/#{name}.xcworkspace"
catch {message} catch {message}
logErr \ logErr \
if message.match /ENOENT/i if message.match /ENOENT/i
""" """
Cannot find #{name}.xcworkspace in iOS/iOS. Cannot find #{name}.xcworkspace in native/ios.
Run this command from your project's root directory. Run this command from your project's root directory.
""" """
else if message.match /EACCES/i else if message.match /EACCES/i
"Invalid permissions for opening #{name}.xcworkspace in iOS/iOS" "Invalid permissions for opening #{name}.xcworkspace in native/ios"
else else
message message