2015-11-20 19:44:36 +00:00
|
|
|
# Re-Natal
|
2015-08-26 03:48:43 +00:00
|
|
|
# Bootstrap ClojureScript React Native apps
|
|
|
|
# Dan Motzenbecker
|
|
|
|
# http://oxism.com
|
|
|
|
# MIT License
|
|
|
|
|
2016-01-31 19:04:30 +00:00
|
|
|
fs = require 'fs-extra'
|
2016-02-07 12:48:00 +00:00
|
|
|
fpath = require 'path'
|
2015-10-17 19:10:31 +00:00
|
|
|
net = require 'net'
|
|
|
|
http = require 'http'
|
2016-02-01 18:26:41 +00:00
|
|
|
os = require 'os'
|
2015-10-04 22:53:54 +00:00
|
|
|
child = require 'child_process'
|
|
|
|
cli = require 'commander'
|
|
|
|
chalk = require 'chalk'
|
|
|
|
semver = require 'semver'
|
2016-01-29 19:25:00 +00:00
|
|
|
ckDeps = require 'check-dependencies'
|
2015-10-04 22:53:54 +00:00
|
|
|
pkgJson = require __dirname + '/package.json'
|
2015-08-22 03:45:42 +00:00
|
|
|
|
2015-10-03 19:36:24 +00:00
|
|
|
nodeVersion = pkgJson.engines.node
|
2016-02-07 12:48:00 +00:00
|
|
|
resources = __dirname + '/resources'
|
2015-11-12 04:12:04 +00:00
|
|
|
validNameRx = /^[A-Z][0-9A-Z]*$/i
|
2015-08-22 03:45:42 +00:00
|
|
|
camelRx = /([a-z])([A-Z])/g
|
|
|
|
projNameRx = /\$PROJECT_NAME\$/g
|
|
|
|
projNameHyphRx = /\$PROJECT_NAME_HYPHENATED\$/g
|
2015-11-27 22:57:14 +00:00
|
|
|
projNameUsRx = /\$PROJECT_NAME_UNDERSCORED\$/g
|
2016-02-07 12:48:00 +00:00
|
|
|
interfaceDepsRx = /\$INTERFACE_DEPS\$/g
|
2015-11-27 22:57:14 +00:00
|
|
|
platformRx = /\$PLATFORM\$/g
|
2017-04-13 09:04:31 +00:00
|
|
|
devProfilesRx = /#_\(\$DEV_PROFILES\$\)/g
|
|
|
|
devProfilesId = "#_($DEV_PROFILES$)"
|
|
|
|
prodProfilesRx = /#_\(\$PROD_PROFILES\$\)/g
|
|
|
|
prodProfilesId = "#_($PROD_PROFILES$)"
|
|
|
|
platformCleanRx = /#_\(\$PLATFORM_CLEAN\$\)/g
|
|
|
|
platformCleanId = "#_($PLATFORM_CLEAN$)"
|
2015-12-06 19:22:53 +00:00
|
|
|
devHostRx = /\$DEV_HOST\$/g
|
2016-03-06 08:59:59 +00:00
|
|
|
ipAddressRx = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/i
|
2016-01-24 10:21:14 +00:00
|
|
|
figwheelUrlRx = /ws:\/\/[0-9a-zA-Z\.]*:/g
|
2016-07-20 09:34:06 +00:00
|
|
|
appDelegateRx = /http:\/\/[^:]+/g
|
|
|
|
debugHostRx = /host\s+=\s+@".*";/g
|
2017-04-29 19:20:35 +00:00
|
|
|
rnVersion = '0.43.4'
|
2017-04-29 19:31:25 +00:00
|
|
|
rnWinVersion = '0.42.0'
|
2015-10-17 19:10:31 +00:00
|
|
|
rnPackagerPort = 8081
|
2015-11-20 19:44:36 +00:00
|
|
|
process.title = 're-natal'
|
2016-02-07 12:48:00 +00:00
|
|
|
interfaceConf =
|
|
|
|
'reagent':
|
|
|
|
cljsDir: "cljs-reagent"
|
|
|
|
sources:
|
|
|
|
common: ["handlers.cljs", "subs.cljs", "db.cljs"]
|
2016-02-10 21:14:05 +00:00
|
|
|
other: []
|
2016-02-07 12:48:00 +00:00
|
|
|
deps: ['[reagent "0.5.1" :exclusions [cljsjs/react]]'
|
2016-07-24 22:06:55 +00:00
|
|
|
'[re-frame "0.6.0"]']
|
2016-02-07 12:48:00 +00:00
|
|
|
shims: ["cljsjs.react"]
|
2016-02-11 12:11:56 +00:00
|
|
|
sampleCommandNs: '(in-ns \'$PROJECT_NAME_HYPHENATED$.ios.core)'
|
2016-02-07 12:48:00 +00:00
|
|
|
sampleCommand: '(dispatch [:set-greeting "Hello Native World!"])'
|
2016-02-25 20:05:46 +00:00
|
|
|
'reagent6':
|
|
|
|
cljsDir: "cljs-reagent6"
|
|
|
|
sources:
|
2016-08-07 12:01:34 +00:00
|
|
|
common: ["events.cljs", "subs.cljs", "db.cljs"]
|
2016-02-25 20:05:46 +00:00
|
|
|
other: [["reagent_dom.cljs","reagent/dom.cljs"], ["reagent_dom_server.cljs","reagent/dom/server.cljs"]]
|
2017-04-29 20:16:37 +00:00
|
|
|
deps: ['[reagent "0.6.1" :exclusions [cljsjs/react cljsjs/react-dom cljsjs/react-dom-server]]'
|
|
|
|
'[re-frame "0.9.2"]']
|
2016-02-25 20:05:46 +00:00
|
|
|
shims: ["cljsjs.react", "cljsjs.react.dom", "cljsjs.react.dom.server"]
|
|
|
|
sampleCommandNs: '(in-ns \'$PROJECT_NAME_HYPHENATED$.ios.core)'
|
|
|
|
sampleCommand: '(dispatch [:set-greeting "Hello Native World!"])'
|
2016-02-07 18:43:43 +00:00
|
|
|
'om-next':
|
|
|
|
cljsDir: "cljs-om-next"
|
|
|
|
sources:
|
2016-02-10 23:24:17 +00:00
|
|
|
common: ["state.cljs"]
|
2016-02-10 21:14:05 +00:00
|
|
|
other: [["support.cljs","re_natal/support.cljs"]]
|
2017-03-07 17:19:48 +00:00
|
|
|
deps: ['[org.omcljs/om "1.0.0-alpha48" :exclusions [cljsjs/react cljsjs/react-dom]]']
|
2016-02-07 18:43:43 +00:00
|
|
|
shims: ["cljsjs.react", "cljsjs.react.dom"]
|
2016-02-11 12:11:56 +00:00
|
|
|
sampleCommandNs: '(in-ns \'$PROJECT_NAME_HYPHENATED$.state)'
|
2016-02-10 21:14:05 +00:00
|
|
|
sampleCommand: '(swap! app-state assoc :app/msg "Hello Native World!")'
|
2016-04-27 03:12:01 +00:00
|
|
|
'rum':
|
|
|
|
cljsDir: "cljs-rum"
|
|
|
|
sources:
|
|
|
|
common: []
|
|
|
|
other: [["sablono_compiler.clj","sablono/compiler.clj"],["support.cljs","re_natal/support.cljs"]]
|
2017-03-07 17:18:37 +00:00
|
|
|
deps: ['[rum "0.10.8" :exclusions [cljsjs/react cljsjs/react-dom sablono]]']
|
2016-04-27 03:12:01 +00:00
|
|
|
shims: ["cljsjs.react", "cljsjs.react.dom", "sablono.core"]
|
|
|
|
sampleCommandNs: '(in-ns \'$PROJECT_NAME_HYPHENATED$.ios.core)'
|
|
|
|
sampleCommand: '(swap! app-state assoc :greeting "Hello Clojure in iOS and Android with Rum!")'
|
2016-02-11 20:44:45 +00:00
|
|
|
interfaceNames = Object.keys interfaceConf
|
2016-05-21 15:05:03 +00:00
|
|
|
defaultInterface = 'reagent6'
|
2016-04-08 21:32:29 +00:00
|
|
|
defaultEnvRoots =
|
|
|
|
dev: 'env/dev'
|
|
|
|
prod: 'env/prod'
|
2017-04-12 13:21:12 +00:00
|
|
|
platformMeta =
|
|
|
|
'ios':
|
|
|
|
name: "iOS"
|
|
|
|
sources: ["core.cljs"]
|
|
|
|
'android':
|
|
|
|
name: "Android"
|
|
|
|
sources: ["core.cljs"]
|
|
|
|
'windows':
|
|
|
|
name: "UWP"
|
|
|
|
sources: ["core.cljs"]
|
2017-04-12 13:47:59 +00:00
|
|
|
'wpf':
|
|
|
|
name: "WPF"
|
|
|
|
sources: ["core.cljs"]
|
2017-04-12 13:21:12 +00:00
|
|
|
platforms = []
|
2015-08-22 03:45:42 +00:00
|
|
|
|
2015-08-26 01:28:58 +00:00
|
|
|
log = (s, color = 'green') ->
|
|
|
|
console.log chalk[color] s
|
2015-08-22 03:45:42 +00:00
|
|
|
|
|
|
|
|
2015-08-26 01:28:58 +00:00
|
|
|
logErr = (err, color = 'red') ->
|
|
|
|
console.error chalk[color] err
|
2015-09-19 18:47:07 +00:00
|
|
|
process.exit 1
|
2015-08-22 03:45:42 +00:00
|
|
|
|
|
|
|
|
2015-10-04 19:32:23 +00:00
|
|
|
exec = (cmd, keepOutput) ->
|
|
|
|
if keepOutput
|
2015-10-04 22:53:54 +00:00
|
|
|
child.execSync cmd
|
2015-10-04 19:32:23 +00:00
|
|
|
else
|
2015-10-04 22:53:54 +00:00
|
|
|
child.execSync cmd, stdio: 'ignore'
|
2015-10-04 19:32:23 +00:00
|
|
|
|
2016-02-01 18:26:41 +00:00
|
|
|
ensureExecutableAvailable = (executable) ->
|
|
|
|
if os.platform() == 'win32'
|
|
|
|
try
|
|
|
|
exec "where #{executable}"
|
|
|
|
catch e
|
|
|
|
throw new Error("type: #{executable}: not found")
|
|
|
|
else
|
|
|
|
exec "type #{executable}"
|
2015-10-04 19:32:23 +00:00
|
|
|
|
2016-02-01 18:58:47 +00:00
|
|
|
ensureOSX = (cb) ->
|
|
|
|
if os.platform() == 'darwin'
|
|
|
|
cb()
|
|
|
|
else
|
|
|
|
logErr 'This command is only available on OSX'
|
|
|
|
|
2015-10-04 00:34:10 +00:00
|
|
|
readFile = (path) ->
|
|
|
|
fs.readFileSync path, encoding: 'ascii'
|
|
|
|
|
|
|
|
|
2015-10-04 19:33:20 +00:00
|
|
|
edit = (path, pairs) ->
|
2015-08-22 03:45:42 +00:00
|
|
|
fs.writeFileSync path, pairs.reduce (contents, [rx, replacement]) ->
|
|
|
|
contents.replace rx, replacement
|
2015-10-04 00:34:10 +00:00
|
|
|
, readFile path
|
2015-08-22 03:45:42 +00:00
|
|
|
|
2015-10-17 04:37:20 +00:00
|
|
|
toUnderscored = (s) ->
|
|
|
|
s.replace(camelRx, '$1_$2').toLowerCase()
|
|
|
|
|
2015-10-17 19:10:31 +00:00
|
|
|
checkPort = (port, cb) ->
|
|
|
|
sock = net.connect {port}, ->
|
|
|
|
sock.end()
|
2015-11-14 19:52:30 +00:00
|
|
|
http.get "http://localhost:#{port}/status", (res) ->
|
2015-10-17 19:10:31 +00:00
|
|
|
data = ''
|
|
|
|
res.on 'data', (chunk) -> data += chunk
|
|
|
|
res.on 'end', ->
|
|
|
|
cb data.toString() isnt 'packager-status:running'
|
|
|
|
|
|
|
|
.on 'error', -> cb true
|
|
|
|
.setTimeout 3000
|
|
|
|
|
|
|
|
sock.on 'error', ->
|
|
|
|
sock.end()
|
|
|
|
cb false
|
|
|
|
|
2015-10-17 19:20:02 +00:00
|
|
|
ensureFreePort = (cb) ->
|
|
|
|
checkPort rnPackagerPort, (inUse) ->
|
|
|
|
if inUse
|
|
|
|
logErr "
|
|
|
|
Port #{rnPackagerPort} is currently in use by another process
|
|
|
|
and is needed by the React Native packager.
|
|
|
|
"
|
|
|
|
cb()
|
|
|
|
|
2015-12-09 21:32:25 +00:00
|
|
|
ensureXcode = (cb) ->
|
|
|
|
try
|
2016-02-01 18:58:47 +00:00
|
|
|
ensureExecutableAvailable 'xcodebuild'
|
2015-12-09 21:32:25 +00:00
|
|
|
cb();
|
|
|
|
catch {message}
|
|
|
|
if message.match /type.+xcodebuild/i
|
|
|
|
logErr 'Xcode Command Line Tools are required'
|
2015-10-17 19:20:02 +00:00
|
|
|
|
2016-02-07 12:48:00 +00:00
|
|
|
generateConfig = (interfaceName, projName) ->
|
2015-11-20 19:44:36 +00:00
|
|
|
log 'Creating Re-Natal config'
|
2015-11-14 23:18:19 +00:00
|
|
|
config =
|
2016-02-07 12:48:00 +00:00
|
|
|
name: projName
|
|
|
|
interface: interfaceName
|
2016-04-08 23:09:45 +00:00
|
|
|
envRoots: defaultEnvRoots
|
2016-01-04 22:10:13 +00:00
|
|
|
modules: []
|
2016-01-17 12:32:42 +00:00
|
|
|
imageDirs: ["images"]
|
2017-04-12 13:21:12 +00:00
|
|
|
platforms: {}
|
2015-11-14 23:18:19 +00:00
|
|
|
|
2017-04-12 09:03:33 +00:00
|
|
|
for platform in platforms
|
2017-04-13 09:04:31 +00:00
|
|
|
config.platforms[platform] =
|
|
|
|
host: "localhost"
|
|
|
|
modules: []
|
2017-04-12 09:03:33 +00:00
|
|
|
|
2015-11-14 23:18:19 +00:00
|
|
|
writeConfig config
|
|
|
|
config
|
|
|
|
|
|
|
|
|
2015-09-19 18:02:28 +00:00
|
|
|
writeConfig = (config) ->
|
|
|
|
try
|
2015-11-20 19:44:36 +00:00
|
|
|
fs.writeFileSync '.re-natal', JSON.stringify config, null, 2
|
2015-09-19 18:02:28 +00:00
|
|
|
catch {message}
|
|
|
|
logErr \
|
|
|
|
if message.match /EACCES/i
|
2015-11-20 19:44:36 +00:00
|
|
|
'Invalid write permissions for creating .re-natal config file'
|
2015-09-19 18:02:28 +00:00
|
|
|
else
|
|
|
|
message
|
|
|
|
|
2016-01-29 19:25:00 +00:00
|
|
|
verifyConfig = (config) ->
|
2017-04-12 13:21:12 +00:00
|
|
|
if !config.platforms? || !config.modules? || !config.imageDirs? || !config.interface? || !config.envRoots?
|
|
|
|
throw new Error 're-natal project needs to be upgraded, please run: re-natal upgrade'
|
2017-04-12 09:03:33 +00:00
|
|
|
|
2016-01-29 19:25:00 +00:00
|
|
|
config
|
2015-09-19 18:02:28 +00:00
|
|
|
|
2016-01-29 19:25:00 +00:00
|
|
|
readConfig = (verify = true)->
|
2015-09-19 18:21:19 +00:00
|
|
|
try
|
2016-01-29 19:25:00 +00:00
|
|
|
config = JSON.parse readFile '.re-natal'
|
|
|
|
if (verify)
|
|
|
|
verifyConfig(config)
|
|
|
|
else
|
|
|
|
config
|
2015-09-19 18:21:19 +00:00
|
|
|
catch {message}
|
|
|
|
logErr \
|
|
|
|
if message.match /ENOENT/i
|
2015-11-20 19:44:36 +00:00
|
|
|
'No Re-Natal config was found in this directory (.re-natal)'
|
2015-09-19 18:21:19 +00:00
|
|
|
else if message.match /EACCES/i
|
2015-11-20 19:44:36 +00:00
|
|
|
'No read permissions for .re-natal'
|
2015-09-19 18:21:19 +00:00
|
|
|
else if message.match /Unexpected/i
|
2015-11-20 19:44:36 +00:00
|
|
|
'.re-natal contains malformed JSON'
|
2015-09-19 18:21:19 +00:00
|
|
|
else
|
|
|
|
message
|
|
|
|
|
2016-01-17 12:32:42 +00:00
|
|
|
scanImageDir = (dir) ->
|
|
|
|
fnames = fs.readdirSync(dir)
|
|
|
|
.map (fname) -> "#{dir}/#{fname}"
|
|
|
|
.filter (path) -> fs.statSync(path).isFile()
|
2016-05-11 19:00:02 +00:00
|
|
|
.filter (path) -> removeExcludeFiles(path)
|
2016-01-17 12:32:42 +00:00
|
|
|
.map (path) -> path.replace /@2x|@3x/i, ''
|
2017-04-12 09:03:33 +00:00
|
|
|
.map (path) -> path.replace new RegExp(".(#{platforms.join('|')})" + fpath.extname(path) + "$", "i"), fpath.extname(path)
|
2016-01-17 12:32:42 +00:00
|
|
|
.filter (v, idx, slf) -> slf.indexOf(v) == idx
|
|
|
|
|
|
|
|
dirs = fs.readdirSync(dir)
|
|
|
|
.map (fname) -> "#{dir}/#{fname}"
|
|
|
|
.filter (path) -> fs.statSync(path).isDirectory()
|
|
|
|
fnames.concat scanImages(dirs)
|
|
|
|
|
2016-05-11 19:00:02 +00:00
|
|
|
removeExcludeFiles = (file) ->
|
|
|
|
excludedFileNames = [".DS_Store"]
|
|
|
|
res = excludedFileNames.map (ex) -> (file.indexOf ex) == -1
|
|
|
|
true in res
|
|
|
|
|
2016-01-17 12:32:42 +00:00
|
|
|
scanImages = (dirs) ->
|
|
|
|
imgs = []
|
|
|
|
for dir in dirs
|
|
|
|
imgs = imgs.concat(scanImageDir(dir));
|
|
|
|
imgs
|
2015-10-04 00:35:46 +00:00
|
|
|
|
2016-09-24 11:51:05 +00:00
|
|
|
resolveAndroidDevHost = (deviceType) ->
|
|
|
|
allowedTypes = {'real': 'localhost', 'avd': '10.0.2.2', 'genymotion': '10.0.3.2'}
|
|
|
|
devHost = allowedTypes[deviceType]
|
|
|
|
if (devHost?)
|
|
|
|
log "Using '#{devHost}' for device type #{deviceType}"
|
|
|
|
devHost
|
|
|
|
else
|
|
|
|
deviceTypeIsIpAddress(deviceType, Object.keys(allowedTypes))
|
|
|
|
|
2016-01-24 12:46:34 +00:00
|
|
|
configureDevHostForAndroidDevice = (deviceType) ->
|
|
|
|
try
|
2016-09-24 11:51:05 +00:00
|
|
|
devHost = resolveAndroidDevHost(deviceType)
|
2016-01-24 12:46:34 +00:00
|
|
|
config = readConfig()
|
2017-04-26 19:42:28 +00:00
|
|
|
config.platforms.android.host = devHost
|
2016-01-24 12:46:34 +00:00
|
|
|
writeConfig(config)
|
2016-09-11 11:36:20 +00:00
|
|
|
log "Please run: re-natal use-figwheel to take effect."
|
2016-01-24 12:46:34 +00:00
|
|
|
catch {message}
|
|
|
|
logErr message
|
|
|
|
|
2016-03-06 08:59:59 +00:00
|
|
|
resolveIosDevHost = (deviceType) ->
|
|
|
|
if deviceType == 'simulator'
|
|
|
|
log "Using 'localhost' for iOS simulator"
|
|
|
|
'localhost'
|
|
|
|
else if deviceType == 'real'
|
|
|
|
en0Ip = exec('ipconfig getifaddr en0', true).toString().trim()
|
|
|
|
log "Using IP of interface en0:'#{en0Ip}' for real iOS device"
|
|
|
|
en0Ip
|
|
|
|
else
|
2016-09-24 11:51:05 +00:00
|
|
|
deviceTypeIsIpAddress(deviceType, ['simulator', 'real'])
|
2016-03-06 08:59:59 +00:00
|
|
|
|
2016-03-03 22:32:06 +00:00
|
|
|
configureDevHostForIosDevice = (deviceType) ->
|
|
|
|
try
|
2016-03-06 08:59:59 +00:00
|
|
|
devHost = resolveIosDevHost(deviceType)
|
2016-03-03 22:32:06 +00:00
|
|
|
config = readConfig()
|
2017-04-26 19:42:28 +00:00
|
|
|
config.platforms.ios.host = devHost
|
2016-03-03 22:32:06 +00:00
|
|
|
writeConfig(config)
|
2016-09-11 11:36:20 +00:00
|
|
|
log "Please run: re-natal use-figwheel to take effect."
|
2016-03-03 22:32:06 +00:00
|
|
|
catch {message}
|
|
|
|
logErr message
|
|
|
|
|
2016-09-24 11:51:05 +00:00
|
|
|
deviceTypeIsIpAddress = (deviceType, allowedTypes) ->
|
|
|
|
if deviceType.match(ipAddressRx)
|
|
|
|
log "Using development host IP: '#{deviceType}'"
|
|
|
|
deviceType
|
|
|
|
else
|
|
|
|
log("Value '#{deviceType}' is not a valid IP address, still configured it as development host. Did you mean one of: [#{allowedTypes}] ?", 'yellow')
|
|
|
|
deviceType
|
|
|
|
|
2017-04-13 09:04:31 +00:00
|
|
|
copyDevEnvironmentFilesForPlatform = (platform, interfaceName, projNameHyph, projName, devEnvRoot, devHost) ->
|
|
|
|
cljsDir = interfaceConf[interfaceName].cljsDir
|
|
|
|
fs.mkdirpSync "#{devEnvRoot}/env/#{platform}"
|
|
|
|
mainDevPath = "#{devEnvRoot}/env/#{platform}/main.cljs"
|
|
|
|
fs.copySync("#{resources}/#{cljsDir}/main_dev.cljs", mainDevPath)
|
|
|
|
edit mainDevPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, platform], [devHostRx, devHost]]
|
|
|
|
|
2016-04-08 21:32:29 +00:00
|
|
|
copyDevEnvironmentFiles = (interfaceName, projNameHyph, projName, devEnvRoot, devHost) ->
|
|
|
|
userNsPath = "#{devEnvRoot}/user.clj"
|
2016-02-07 12:48:00 +00:00
|
|
|
fs.copySync("#{resources}/user.clj", userNsPath)
|
2015-12-14 22:02:40 +00:00
|
|
|
|
2017-04-12 09:03:33 +00:00
|
|
|
for platform in platforms
|
2017-04-13 09:04:31 +00:00
|
|
|
copyDevEnvironmentFilesForPlatform platform, interfaceName, projNameHyph, projName, devEnvRoot, devHost
|
|
|
|
|
|
|
|
copyProdEnvironmentFilesForPlatform = (platform, interfaceName, projNameHyph, projName, prodEnvRoot) ->
|
2016-02-07 12:48:00 +00:00
|
|
|
cljsDir = interfaceConf[interfaceName].cljsDir
|
2017-04-13 09:04:31 +00:00
|
|
|
fs.mkdirpSync "#{prodEnvRoot}/env/#{platform}"
|
|
|
|
mainProdPath = "#{prodEnvRoot}/env/#{platform}/main.cljs"
|
|
|
|
fs.copySync("#{resources}/#{cljsDir}/main_prod.cljs", mainProdPath)
|
|
|
|
edit mainProdPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, platform]]
|
2017-04-12 09:03:33 +00:00
|
|
|
|
2017-04-13 09:04:31 +00:00
|
|
|
copyProdEnvironmentFiles = (interfaceName, projNameHyph, projName, prodEnvRoot) ->
|
2017-04-12 09:03:33 +00:00
|
|
|
for platform in platforms
|
2017-04-13 09:04:31 +00:00
|
|
|
copyProdEnvironmentFilesForPlatform platform, interfaceName, projNameHyph, projName, prodEnvRoot
|
2015-11-29 21:36:49 +00:00
|
|
|
|
|
|
|
copyFigwheelBridge = (projNameUs) ->
|
2016-02-07 12:48:00 +00:00
|
|
|
fs.copySync("#{resources}/figwheel-bridge.js", "./figwheel-bridge.js")
|
2015-11-29 21:36:49 +00:00
|
|
|
edit "figwheel-bridge.js", [[projNameUsRx, projNameUs]]
|
|
|
|
|
2015-12-31 17:57:50 +00:00
|
|
|
updateGitIgnore = () ->
|
2017-04-12 09:03:33 +00:00
|
|
|
fs.appendFileSync(".gitignore", "\n# Generated by re-natal\n#\n")
|
2017-04-13 09:04:31 +00:00
|
|
|
|
|
|
|
indexFiles = platforms.map (platform) -> "index.#{platform}.js"
|
|
|
|
fs.appendFileSync(".gitignore", indexFiles.join("\n"))
|
2017-04-13 09:27:05 +00:00
|
|
|
fs.appendFileSync(".gitignore", "\ntarget/\n")
|
2017-04-12 09:03:33 +00:00
|
|
|
|
2015-12-31 17:57:50 +00:00
|
|
|
fs.appendFileSync(".gitignore", "\n# Figwheel\n#\nfigwheel_server.log")
|
|
|
|
|
2016-01-20 23:14:35 +00:00
|
|
|
patchReactNativePackager = () ->
|
2016-02-06 15:00:09 +00:00
|
|
|
ckDeps.sync {install: true, verbose: false}
|
2016-01-20 23:14:35 +00:00
|
|
|
log "Patching react-native packager to serve *.map files"
|
2017-03-15 18:11:34 +00:00
|
|
|
edit "node_modules/react-native/packager/src/Server/index.js",
|
2016-01-21 21:27:36 +00:00
|
|
|
[[/match.*\.map\$\/\)/m, "match(/index\\..*\\.map$/)"]]
|
2016-01-20 23:14:35 +00:00
|
|
|
|
2016-02-07 12:48:00 +00:00
|
|
|
shimCljsNamespace = (ns) ->
|
|
|
|
filePath = "src/" + ns.replace(/\./g, "/") + ".cljs"
|
|
|
|
fs.mkdirpSync fpath.dirname(filePath)
|
|
|
|
fs.writeFileSync(filePath, "(ns #{ns})")
|
|
|
|
|
2017-04-13 09:04:31 +00:00
|
|
|
copySrcFilesForPlatform = (platform, interfaceName, projName, projNameUs, projNameHyph) ->
|
|
|
|
cljsDir = interfaceConf[interfaceName].cljsDir
|
|
|
|
fs.mkdirSync "src/#{projNameUs}/#{platform}"
|
|
|
|
fileNames = platformMeta[platform].sources
|
|
|
|
for fileName in fileNames
|
|
|
|
path = "src/#{projNameUs}/#{platform}/#{fileName}"
|
|
|
|
fs.copySync("#{resources}/#{cljsDir}/#{fileName}", path)
|
|
|
|
edit path, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, platform]]
|
|
|
|
|
2016-02-07 12:48:00 +00:00
|
|
|
copySrcFiles = (interfaceName, projName, projNameUs, projNameHyph) ->
|
|
|
|
cljsDir = interfaceConf[interfaceName].cljsDir
|
2016-02-10 21:14:05 +00:00
|
|
|
|
2016-02-07 12:48:00 +00:00
|
|
|
fileNames = interfaceConf[interfaceName].sources.common;
|
|
|
|
for fileName in fileNames
|
|
|
|
path = "src/#{projNameUs}/#{fileName}"
|
|
|
|
fs.copySync("#{resources}/#{cljsDir}/#{fileName}", path)
|
|
|
|
edit path, [[projNameHyphRx, projNameHyph], [projNameRx, projName]]
|
|
|
|
|
|
|
|
for platform in platforms
|
2017-04-13 09:04:31 +00:00
|
|
|
copySrcFilesForPlatform platform, interfaceName, projName, projNameUs, projNameHyph
|
2016-02-07 12:48:00 +00:00
|
|
|
|
2016-02-10 21:14:05 +00:00
|
|
|
otherFiles = interfaceConf[interfaceName].sources.other;
|
|
|
|
for cpFile in otherFiles
|
|
|
|
from = "#{resources}/#{cljsDir}/#{cpFile[0]}"
|
|
|
|
to = "src/#{cpFile[1]}"
|
|
|
|
fs.copySync(from, to)
|
|
|
|
|
2016-02-07 12:48:00 +00:00
|
|
|
shims = fileNames = interfaceConf[interfaceName].shims;
|
|
|
|
for namespace in shims
|
|
|
|
shimCljsNamespace(namespace)
|
|
|
|
|
|
|
|
copyProjectClj = (interfaceName, projNameHyph) ->
|
|
|
|
fs.copySync("#{resources}/project.clj", "project.clj")
|
|
|
|
deps = interfaceConf[interfaceName].deps.join("\n")
|
2017-04-13 09:04:31 +00:00
|
|
|
|
2017-04-12 11:17:22 +00:00
|
|
|
cleans = platforms.map (platform) -> "\"index.#{platform}.js\""
|
2017-04-13 09:04:31 +00:00
|
|
|
cleans.push platformCleanId
|
|
|
|
|
|
|
|
devProfileTemplate = readFile "#{resources}/dev.profile"
|
2017-04-13 06:25:38 +00:00
|
|
|
devProfiles = platforms.map (platform) -> devProfileTemplate.replace(platformRx, platform)
|
2017-04-13 09:04:31 +00:00
|
|
|
devProfiles.push devProfilesId
|
|
|
|
|
|
|
|
prodProfileTemplate = readFile "#{resources}/prod.profile"
|
2017-04-13 06:25:38 +00:00
|
|
|
prodProfiles = platforms.map (platform) -> prodProfileTemplate.replace(platformRx, platform)
|
2017-04-13 09:04:31 +00:00
|
|
|
prodProfiles.push prodProfilesId
|
|
|
|
|
2017-04-12 11:17:22 +00:00
|
|
|
edit 'project.clj', [[projNameHyphRx, projNameHyph], [interfaceDepsRx, deps], [platformCleanRx, cleans.join(' ')], [devProfilesRx, devProfiles.join("\n")], [prodProfilesRx, prodProfiles.join("\n")]]
|
2016-02-07 12:48:00 +00:00
|
|
|
|
2017-04-13 09:04:31 +00:00
|
|
|
updateProjectClj = (platform) ->
|
2017-04-29 19:03:36 +00:00
|
|
|
proj = readFile('project.clj')
|
|
|
|
|
2017-04-13 09:04:31 +00:00
|
|
|
cleans = []
|
|
|
|
cleans.push "\"index.#{platform}.js\""
|
|
|
|
cleans.push platformCleanId
|
|
|
|
|
2017-04-29 19:03:36 +00:00
|
|
|
if !proj.match(platformCleanRx)
|
|
|
|
log "Manual update of project.clj required: add clean targets:"
|
|
|
|
log "#{cleans.join(' ')}", "red"
|
|
|
|
|
2017-04-13 09:04:31 +00:00
|
|
|
devProfileTemplate = readFile "#{resources}/dev.profile"
|
|
|
|
devProfiles = []
|
|
|
|
devProfiles.push devProfileTemplate.replace(platformRx, platform)
|
|
|
|
devProfiles.push devProfilesId
|
|
|
|
|
2017-04-29 19:03:36 +00:00
|
|
|
if !proj.match(devProfilesRx)
|
|
|
|
log "Manual update of project.clj required: add new build to dev profile:"
|
|
|
|
log "#{devProfiles.join('\n')}", "red"
|
|
|
|
|
2017-04-13 09:04:31 +00:00
|
|
|
prodProfileTemplate = readFile "#{resources}/prod.profile"
|
|
|
|
prodProfiles = []
|
|
|
|
prodProfiles.push prodProfileTemplate.replace(platformRx, platform)
|
|
|
|
prodProfiles.push prodProfilesId
|
|
|
|
|
2017-04-29 19:03:36 +00:00
|
|
|
if !proj.match(prodProfilesRx)
|
|
|
|
log "Manual update of project.clj required: add new build to prod profile:"
|
|
|
|
log "#{prodProfiles.join('\n')}", "red"
|
|
|
|
|
2017-04-13 09:04:31 +00:00
|
|
|
edit 'project.clj', [[platformCleanRx, cleans.join(' ')], [devProfilesRx, devProfiles.join("\n")], [prodProfilesRx, prodProfiles.join("\n")]]
|
|
|
|
|
2016-02-07 12:48:00 +00:00
|
|
|
init = (interfaceName, projName) ->
|
2015-11-12 04:12:04 +00:00
|
|
|
if projName.toLowerCase() is 'react' or !projName.match validNameRx
|
|
|
|
logErr 'Invalid project name. Use an alphanumeric CamelCase name.'
|
|
|
|
|
2015-08-22 03:46:38 +00:00
|
|
|
projNameHyph = projName.replace(camelRx, '$1-$2').toLowerCase()
|
2015-10-17 04:37:20 +00:00
|
|
|
projNameUs = toUnderscored projName
|
2015-08-22 03:46:38 +00:00
|
|
|
|
|
|
|
try
|
2015-09-19 03:10:03 +00:00
|
|
|
log "Creating #{projName}", 'bgMagenta'
|
2016-09-11 12:50:57 +00:00
|
|
|
log '\u2615 Grab a coffee! Downloading deps might take a while...', 'yellow'
|
2015-08-26 01:44:11 +00:00
|
|
|
|
2015-08-22 17:45:37 +00:00
|
|
|
if fs.existsSync projNameHyph
|
2015-09-19 03:10:03 +00:00
|
|
|
throw new Error "Directory #{projNameHyph} already exists"
|
2015-08-22 17:45:37 +00:00
|
|
|
|
2016-02-01 18:26:41 +00:00
|
|
|
ensureExecutableAvailable 'lein'
|
2015-10-03 19:48:28 +00:00
|
|
|
|
2015-08-22 15:06:30 +00:00
|
|
|
log 'Creating Leiningen project'
|
2015-10-04 19:32:23 +00:00
|
|
|
exec "lein new #{projNameHyph}"
|
2015-08-22 15:06:30 +00:00
|
|
|
|
|
|
|
log 'Updating Leiningen project'
|
|
|
|
process.chdir projNameHyph
|
2016-01-31 19:04:30 +00:00
|
|
|
fs.removeSync "resources"
|
2015-09-19 03:10:03 +00:00
|
|
|
corePath = "src/#{projNameUs}/core.clj"
|
2015-08-22 15:06:30 +00:00
|
|
|
fs.unlinkSync corePath
|
2015-11-20 19:44:36 +00:00
|
|
|
|
2016-02-07 12:48:00 +00:00
|
|
|
copyProjectClj(interfaceName, projNameHyph)
|
2017-04-12 10:07:11 +00:00
|
|
|
|
2016-02-07 12:48:00 +00:00
|
|
|
copySrcFiles(interfaceName, projName, projNameUs, projNameHyph)
|
2015-11-27 22:57:14 +00:00
|
|
|
|
2016-04-08 21:32:29 +00:00
|
|
|
copyDevEnvironmentFiles(interfaceName, projNameHyph, projName, defaultEnvRoots.dev, "localhost")
|
|
|
|
copyProdEnvironmentFiles(interfaceName, projNameHyph, projName, defaultEnvRoots.prod)
|
2015-11-28 15:20:39 +00:00
|
|
|
|
2016-02-07 12:48:00 +00:00
|
|
|
fs.copySync("#{resources}/images", "./images")
|
2015-08-22 03:46:38 +00:00
|
|
|
|
2016-09-11 11:36:20 +00:00
|
|
|
log 'Creating React Native skeleton.'
|
2015-10-04 21:54:48 +00:00
|
|
|
|
2017-04-12 11:02:25 +00:00
|
|
|
pkg =
|
2015-11-22 09:57:51 +00:00
|
|
|
name: projName
|
|
|
|
version: '0.0.1'
|
|
|
|
private: true
|
|
|
|
scripts:
|
2016-03-21 21:50:54 +00:00
|
|
|
start: 'node_modules/react-native/packager/packager.sh --nonPersistent'
|
2015-11-22 09:57:51 +00:00
|
|
|
dependencies:
|
|
|
|
'react-native': rnVersion
|
2016-10-31 17:51:48 +00:00
|
|
|
# Fixes issue with packager 'TimeoutError: transforming ... took longer than 301 seconds.'
|
|
|
|
'babel-plugin-transform-es2015-block-scoping': '6.15.0'
|
2017-04-12 11:02:25 +00:00
|
|
|
|
2017-04-12 11:50:48 +00:00
|
|
|
if 'windows' in platforms || 'wpf' in platforms
|
2017-04-29 19:31:25 +00:00
|
|
|
pkg.dependencies['react-native-windows'] = rnWinVersion
|
2017-04-12 11:02:25 +00:00
|
|
|
|
|
|
|
fs.writeFileSync 'package.json', JSON.stringify pkg, null, 2
|
2015-11-22 09:57:51 +00:00
|
|
|
|
|
|
|
exec 'npm i'
|
2015-11-24 21:44:57 +00:00
|
|
|
|
|
|
|
fs.unlinkSync '.gitignore'
|
2015-12-13 21:49:54 +00:00
|
|
|
exec "node -e
|
2015-11-22 17:17:45 +00:00
|
|
|
\"require('react-native/local-cli/cli').init('.', '#{projName}')\"
|
2015-11-22 09:57:51 +00:00
|
|
|
"
|
2015-11-20 21:43:47 +00:00
|
|
|
|
2017-04-12 11:02:25 +00:00
|
|
|
if 'windows' in platforms
|
2017-04-13 09:04:31 +00:00
|
|
|
log 'Creating React Native UWP project.'
|
2017-04-12 11:02:25 +00:00
|
|
|
exec "node -e
|
|
|
|
\"require('react-native-windows/local-cli/generate-windows')('.', '#{projName}', '#{projName}')\"
|
|
|
|
"
|
|
|
|
|
2017-04-12 11:50:48 +00:00
|
|
|
if 'wpf' in platforms
|
2017-04-13 09:04:31 +00:00
|
|
|
log 'Creating React Native WPF project.'
|
2017-04-12 11:50:48 +00:00
|
|
|
exec "node -e
|
|
|
|
\"require('react-native-windows/local-cli/generate-wpf')('.', '#{projName}', '#{projName}')\"
|
|
|
|
"
|
|
|
|
|
2015-12-31 17:57:50 +00:00
|
|
|
updateGitIgnore()
|
|
|
|
|
2016-02-07 12:48:00 +00:00
|
|
|
generateConfig(interfaceName, projName)
|
2015-11-27 22:57:14 +00:00
|
|
|
|
2015-11-29 21:36:49 +00:00
|
|
|
copyFigwheelBridge(projNameUs)
|
2015-08-22 17:30:42 +00:00
|
|
|
|
2015-11-24 21:44:57 +00:00
|
|
|
log 'Compiling ClojureScript'
|
2015-11-27 22:57:14 +00:00
|
|
|
exec 'lein prod-build'
|
2015-10-04 19:11:54 +00:00
|
|
|
|
2015-10-04 23:05:04 +00:00
|
|
|
log ''
|
|
|
|
log 'To get started with your new app, first cd into its directory:', 'yellow'
|
2015-09-19 03:10:03 +00:00
|
|
|
log "cd #{projNameHyph}", 'inverse'
|
2015-10-04 23:05:04 +00:00
|
|
|
log ''
|
2016-09-11 12:50:57 +00:00
|
|
|
log 'Run iOS app:' , 'yellow'
|
2016-09-11 12:15:49 +00:00
|
|
|
log 'react-native run-ios > /dev/null', 'inverse'
|
2015-11-27 22:57:14 +00:00
|
|
|
log ''
|
2015-12-06 11:09:28 +00:00
|
|
|
log 'To use figwheel type:' , 'yellow'
|
2015-11-27 22:57:14 +00:00
|
|
|
log 're-natal use-figwheel', 'inverse'
|
|
|
|
log 'lein figwheel ios', 'inverse'
|
|
|
|
log ''
|
2016-09-11 12:50:57 +00:00
|
|
|
log 'Reload the app in simulator (\u2318 + R)'
|
2015-10-04 23:05:04 +00:00
|
|
|
log ''
|
2015-08-26 01:44:11 +00:00
|
|
|
log 'At the REPL prompt type this:', 'yellow'
|
2016-02-11 12:11:56 +00:00
|
|
|
log interfaceConf[interfaceName].sampleCommandNs.replace(projNameHyphRx, projNameHyph), 'inverse'
|
2015-10-04 23:05:04 +00:00
|
|
|
log ''
|
2015-08-26 01:44:11 +00:00
|
|
|
log 'Changes you make via the REPL or by changing your .cljs files should appear live.', 'yellow'
|
2015-10-04 23:05:04 +00:00
|
|
|
log ''
|
2015-08-26 01:44:11 +00:00
|
|
|
log 'Try this command as an example:', 'yellow'
|
2016-02-07 12:48:00 +00:00
|
|
|
log interfaceConf[interfaceName].sampleCommand, 'inverse'
|
2015-08-26 01:57:22 +00:00
|
|
|
log ''
|
2015-08-26 03:48:43 +00:00
|
|
|
log '✔ Done', 'bgMagenta'
|
|
|
|
log ''
|
2015-08-26 01:44:11 +00:00
|
|
|
|
2015-09-19 03:05:39 +00:00
|
|
|
catch {message}
|
|
|
|
logErr \
|
2016-02-01 18:26:41 +00:00
|
|
|
if message.match /type.+lein/i
|
|
|
|
'Leiningen is required (http://leiningen.org)'
|
|
|
|
else if message.match /npm/i
|
2015-11-27 22:57:14 +00:00
|
|
|
"npm install failed. This may be a network issue. Check #{projNameHyph}/npm-debug.log for details."
|
2015-09-19 03:05:39 +00:00
|
|
|
else
|
|
|
|
message
|
2015-08-22 03:46:38 +00:00
|
|
|
|
2017-04-13 09:04:31 +00:00
|
|
|
addPlatform = (platform) ->
|
2017-04-30 18:05:32 +00:00
|
|
|
try
|
|
|
|
if !(platform of platformMeta)
|
|
|
|
throw new Error "Unknown platform [#{platform}]"
|
2017-04-13 09:04:31 +00:00
|
|
|
|
2017-04-30 18:05:32 +00:00
|
|
|
config = readConfig()
|
|
|
|
platforms = Object.keys config.platforms
|
2017-04-13 09:04:31 +00:00
|
|
|
|
2017-04-30 18:05:32 +00:00
|
|
|
if platform in platforms
|
|
|
|
throw new Error "A project for a #{platformMeta[platform].name} app already exists"
|
|
|
|
else
|
|
|
|
interfaceName = config.interface
|
|
|
|
projName = config.name
|
|
|
|
projNameHyph = projName.replace(camelRx, '$1-$2').toLowerCase()
|
|
|
|
projNameUs = toUnderscored projName
|
2017-04-13 09:04:31 +00:00
|
|
|
|
2017-04-30 18:05:32 +00:00
|
|
|
log "Preparing for #{platformMeta[platform].name} app."
|
2017-04-13 09:04:31 +00:00
|
|
|
|
2017-04-30 18:05:32 +00:00
|
|
|
updateProjectClj(platform)
|
|
|
|
copySrcFilesForPlatform(platform, interfaceName, projName, projNameUs, projNameHyph)
|
|
|
|
copyDevEnvironmentFilesForPlatform(platform, interfaceName, projNameHyph, projName, defaultEnvRoots.dev, "localhost")
|
|
|
|
copyProdEnvironmentFilesForPlatform(platform, interfaceName, projNameHyph, projName, defaultEnvRoots.prod)
|
2017-04-13 09:04:31 +00:00
|
|
|
|
2017-04-30 18:05:32 +00:00
|
|
|
pkg = JSON.parse readFile 'package.json'
|
2017-04-13 09:04:31 +00:00
|
|
|
|
2017-04-30 18:05:32 +00:00
|
|
|
unless 'react-native-windows' in pkg.dependencies
|
|
|
|
pkg.dependencies['react-native-windows'] = rnWinVersion
|
|
|
|
fs.writeFileSync 'package.json', JSON.stringify pkg, null, 2
|
|
|
|
exec 'npm i'
|
2017-04-13 09:04:31 +00:00
|
|
|
|
2017-04-30 18:05:32 +00:00
|
|
|
if platform is 'windows'
|
|
|
|
log 'Creating React Native UWP project.'
|
|
|
|
exec "node -e
|
|
|
|
\"require('react-native-windows/local-cli/generate-windows')('.', '#{projName}', '#{projName}')\"
|
|
|
|
"
|
2017-04-13 09:04:31 +00:00
|
|
|
|
2017-04-30 18:05:32 +00:00
|
|
|
if platform is 'wpf'
|
|
|
|
log 'Creating React Native WPF project.'
|
|
|
|
exec "node -e
|
|
|
|
\"require('react-native-windows/local-cli/generate-wpf')('.', '#{projName}', '#{projName}')\"
|
|
|
|
"
|
2017-04-13 09:04:31 +00:00
|
|
|
|
2017-04-30 18:05:32 +00:00
|
|
|
fs.appendFileSync(".gitignore", "\n\nindex.#{platform}.js\n")
|
2017-04-13 09:04:31 +00:00
|
|
|
|
2017-04-30 18:05:32 +00:00
|
|
|
config.platforms[platform] =
|
|
|
|
host: "localhost"
|
|
|
|
modules: []
|
|
|
|
|
|
|
|
writeConfig(config)
|
|
|
|
|
|
|
|
log 'Compiling ClojureScript'
|
|
|
|
exec 'lein prod-build'
|
|
|
|
catch {message}
|
|
|
|
logErr message
|
2017-04-13 09:04:31 +00:00
|
|
|
|
2015-09-19 18:47:28 +00:00
|
|
|
openXcode = (name) ->
|
|
|
|
try
|
2015-11-27 22:57:14 +00:00
|
|
|
exec "open ios/#{name}.xcodeproj"
|
2015-09-19 18:47:28 +00:00
|
|
|
catch {message}
|
|
|
|
logErr \
|
|
|
|
if message.match /ENOENT/i
|
|
|
|
"""
|
2015-11-27 22:57:14 +00:00
|
|
|
Cannot find #{name}.xcodeproj in ios.
|
2015-09-19 18:47:28 +00:00
|
|
|
Run this command from your project's root directory.
|
|
|
|
"""
|
|
|
|
else if message.match /EACCES/i
|
2015-11-27 22:57:14 +00:00
|
|
|
"Invalid permissions for opening #{name}.xcodeproj in ios"
|
2015-09-19 18:47:28 +00:00
|
|
|
else
|
|
|
|
message
|
2015-08-26 03:48:43 +00:00
|
|
|
|
2016-01-04 22:10:13 +00:00
|
|
|
generateRequireModulesCode = (modules) ->
|
2016-02-25 20:05:46 +00:00
|
|
|
jsCode = "var modules={'react-native': require('react-native'), 'react': require('react')};"
|
2016-01-04 22:10:13 +00:00
|
|
|
for m in modules
|
|
|
|
jsCode += "modules['#{m}']=require('#{m}');";
|
|
|
|
jsCode += '\n'
|
|
|
|
|
2017-04-12 09:03:33 +00:00
|
|
|
updateFigwheelUrls = (devEnvRoot, devHost) ->
|
|
|
|
for platform in platforms
|
|
|
|
mainDevPath = "#{devEnvRoot}/env/#{platform}/main.cljs"
|
|
|
|
edit mainDevPath, [[figwheelUrlRx, "ws://#{devHost[platform]}:"]]
|
2016-03-03 22:32:06 +00:00
|
|
|
|
2016-07-20 09:34:06 +00:00
|
|
|
# Current RN version (0.29.2) has no host in AppDelegate.m maybe docs are outdated?
|
2016-03-03 22:32:06 +00:00
|
|
|
updateIosAppDelegate = (projName, iosHost) ->
|
|
|
|
appDelegatePath = "ios/#{projName}/AppDelegate.m"
|
2016-07-20 09:34:06 +00:00
|
|
|
edit appDelegatePath, [[appDelegateRx, "http://#{iosHost}"]]
|
2016-05-04 16:15:08 +00:00
|
|
|
|
2016-04-21 14:00:29 +00:00
|
|
|
updateIosRCTWebSocketExecutor = (iosHost) ->
|
|
|
|
RCTWebSocketExecutorPath = "node_modules/react-native/Libraries/WebSocket/RCTWebSocketExecutor.m"
|
2016-07-20 09:34:06 +00:00
|
|
|
edit RCTWebSocketExecutorPath, [[debugHostRx, "host = @\"#{iosHost}\";"]]
|
2016-01-24 10:21:14 +00:00
|
|
|
|
2016-11-21 18:48:48 +00:00
|
|
|
platformModulesAndImages = (config, platform) ->
|
|
|
|
images = scanImages(config.imageDirs).map (fname) -> './' + fname;
|
|
|
|
modulesAndImages = config.modules.concat images;
|
2017-04-12 14:38:48 +00:00
|
|
|
if typeof config.platforms[platform].modules is 'undefined'
|
2016-11-21 18:48:48 +00:00
|
|
|
modulesAndImages
|
|
|
|
else
|
2017-04-12 14:38:48 +00:00
|
|
|
modulesAndImages.concat(config.platforms[platform].modules)
|
2016-11-21 18:48:48 +00:00
|
|
|
|
2016-01-24 12:46:34 +00:00
|
|
|
generateDevScripts = () ->
|
2015-11-27 22:57:14 +00:00
|
|
|
try
|
2016-01-04 22:10:13 +00:00
|
|
|
config = readConfig()
|
2017-04-12 13:21:12 +00:00
|
|
|
platforms = Object.keys config.platforms
|
2016-01-04 22:10:13 +00:00
|
|
|
projName = config.name
|
2016-04-08 21:32:29 +00:00
|
|
|
devEnvRoot = config.envRoots.dev
|
2015-12-06 19:22:53 +00:00
|
|
|
|
2016-01-29 19:25:00 +00:00
|
|
|
depState = ckDeps.sync {install: false, verbose: false}
|
|
|
|
if (!depState.depsWereOk)
|
|
|
|
throw new Error "Missing dependencies, please run: re-natal deps"
|
|
|
|
|
2015-12-06 19:53:49 +00:00
|
|
|
log 'Cleaning...'
|
|
|
|
exec 'lein clean'
|
|
|
|
|
2017-04-12 09:03:33 +00:00
|
|
|
devHost = {}
|
|
|
|
for platform in platforms
|
2017-04-12 13:21:12 +00:00
|
|
|
devHost[platform] = config.platforms[platform].host
|
2016-01-24 12:46:34 +00:00
|
|
|
|
2016-11-21 18:48:48 +00:00
|
|
|
for platform in platforms
|
|
|
|
moduleMap = generateRequireModulesCode(platformModulesAndImages(config, platform))
|
|
|
|
fs.writeFileSync "index.#{platform}.js", "#{moduleMap}require('figwheel-bridge').withModules(modules).start('#{projName}','#{platform}','#{devHost[platform]}');"
|
|
|
|
log "index.#{platform}.js was regenerated"
|
2015-12-06 19:22:53 +00:00
|
|
|
|
2017-04-12 09:03:33 +00:00
|
|
|
#updateIosAppDelegate(projName, devHost.ios)
|
|
|
|
updateIosRCTWebSocketExecutor(devHost.ios)
|
2016-07-20 09:34:06 +00:00
|
|
|
log "Host in RCTWebSocketExecutor.m was updated"
|
2016-03-03 22:32:06 +00:00
|
|
|
|
2017-04-12 09:03:33 +00:00
|
|
|
updateFigwheelUrls(devEnvRoot, devHost)
|
|
|
|
for platform in platforms
|
2017-04-12 13:21:12 +00:00
|
|
|
log "Dev server host for #{platformMeta[platform].name}: #{devHost[platform]}"
|
2016-01-24 10:21:14 +00:00
|
|
|
|
2015-11-27 22:57:14 +00:00
|
|
|
catch {message}
|
|
|
|
logErr \
|
|
|
|
if message.match /EACCES/i
|
|
|
|
'Invalid write permissions for creating development scripts'
|
|
|
|
else
|
|
|
|
message
|
|
|
|
|
2015-11-29 21:36:49 +00:00
|
|
|
doUpgrade = (config) ->
|
2016-04-08 21:32:29 +00:00
|
|
|
projName = config.name
|
2015-11-29 21:36:49 +00:00
|
|
|
projNameHyph = projName.replace(camelRx, '$1-$2').toLowerCase()
|
|
|
|
projNameUs = toUnderscored projName
|
|
|
|
|
2016-02-11 20:44:45 +00:00
|
|
|
unless config.interface
|
|
|
|
config.interface = defaultInterface
|
2015-10-04 22:53:54 +00:00
|
|
|
|
2016-02-11 20:44:45 +00:00
|
|
|
unless config.modules
|
2016-01-05 18:41:32 +00:00
|
|
|
config.modules = []
|
|
|
|
|
2016-02-11 20:44:45 +00:00
|
|
|
unless config.imageDirs
|
2016-01-17 12:32:42 +00:00
|
|
|
config.imageDirs = ["images"]
|
|
|
|
|
2016-04-08 21:32:29 +00:00
|
|
|
unless config.envRoots
|
|
|
|
config.envRoots = defaultEnvRoots
|
|
|
|
|
2017-04-12 13:21:12 +00:00
|
|
|
unless config.platforms
|
2017-04-13 06:25:38 +00:00
|
|
|
config.platforms =
|
|
|
|
ios:
|
|
|
|
host: "localhost"
|
|
|
|
modules: []
|
|
|
|
android:
|
|
|
|
host: "localhost"
|
|
|
|
modules: []
|
2017-04-12 13:21:12 +00:00
|
|
|
|
|
|
|
if config.iosHost?
|
|
|
|
config.platforms.ios.host = config.iosHost
|
|
|
|
delete config.iosHost
|
|
|
|
|
|
|
|
if config.androidHost?
|
|
|
|
config.platforms.android.host = config.androidHost
|
|
|
|
delete config.androidHost
|
2017-04-12 09:03:33 +00:00
|
|
|
|
2017-04-13 06:25:38 +00:00
|
|
|
if config.modulesPlatform?
|
|
|
|
if config.modulesPlatform.ios?
|
|
|
|
config.platforms.ios.modules = config.platforms.ios.modules.concat(config.modulesPlatform.ios)
|
|
|
|
|
|
|
|
if config.modulesPlatform.android?
|
|
|
|
config.platforms.android.modules = config.platforms.android.modules.concat(config.modulesPlatform.android)
|
|
|
|
|
|
|
|
delete config.modulesPlatform
|
|
|
|
|
2016-01-05 18:41:32 +00:00
|
|
|
writeConfig(config)
|
|
|
|
log 'upgraded .re-natal'
|
|
|
|
|
2016-04-08 21:32:29 +00:00
|
|
|
interfaceName = config.interface
|
|
|
|
envRoots = config.envRoots
|
2016-02-11 20:44:45 +00:00
|
|
|
|
2016-04-08 21:32:29 +00:00
|
|
|
copyDevEnvironmentFiles(interfaceName, projNameHyph, projName, envRoots.dev, "localhost")
|
|
|
|
copyProdEnvironmentFiles(interfaceName, projNameHyph, projName, envRoots.prod)
|
|
|
|
log "upgraded files in #{envRoots.dev} and #{envRoots.prod} "
|
2016-02-11 20:44:45 +00:00
|
|
|
|
|
|
|
copyFigwheelBridge(projNameUs)
|
|
|
|
log 'upgraded figwheel-bridge.js'
|
2016-06-10 20:26:26 +00:00
|
|
|
log('To upgrade React Native version please follow the official guide in https://facebook.github.io/react-native/docs/upgrading.html', 'yellow')
|
2016-02-11 20:44:45 +00:00
|
|
|
|
2016-11-21 18:48:48 +00:00
|
|
|
useComponent = (name, platform) ->
|
2016-01-04 22:10:13 +00:00
|
|
|
try
|
|
|
|
config = readConfig()
|
2017-04-12 13:21:12 +00:00
|
|
|
platforms = Object.keys config.platforms
|
2016-11-21 18:48:48 +00:00
|
|
|
if typeof platform isnt 'string'
|
|
|
|
config.modules.push name
|
|
|
|
log "Component '#{name}' is now configured for figwheel, please re-run 'use-figwheel' command to take effect"
|
|
|
|
else if platforms.indexOf(platform) > -1
|
2017-04-12 14:38:48 +00:00
|
|
|
if typeof config.platforms[platform].modules is 'undefined'
|
|
|
|
config.platforms[platform].modules = []
|
|
|
|
config.platforms[platform].modules.push name
|
2016-11-21 18:48:48 +00:00
|
|
|
log "Component '#{name}' (#{platform}-only) is now configured for figwheel, please re-run 'use-figwheel' command to take effect"
|
|
|
|
else
|
|
|
|
throw new Error("unsupported platform: #{platform}")
|
2016-01-04 22:10:13 +00:00
|
|
|
writeConfig(config)
|
|
|
|
catch {message}
|
|
|
|
logErr message
|
|
|
|
|
2015-11-20 19:44:36 +00:00
|
|
|
cli._name = 're-natal'
|
2015-10-04 01:18:26 +00:00
|
|
|
cli.version pkgJson.version
|
2015-08-26 03:48:43 +00:00
|
|
|
|
2015-09-19 17:51:11 +00:00
|
|
|
cli.command 'init <name>'
|
2015-10-31 15:36:32 +00:00
|
|
|
.description 'create a new ClojureScript React Native project'
|
2016-02-11 20:44:45 +00:00
|
|
|
.option "-i, --interface [#{interfaceNames.join ' '}]", 'specify React interface', defaultInterface
|
2017-04-13 09:04:31 +00:00
|
|
|
.option '-u, --uwp', 'create project for UWP app'
|
|
|
|
.option '-w, --wpf', 'create project for WPF app'
|
2016-02-07 18:43:43 +00:00
|
|
|
.action (name, cmd) ->
|
2015-09-19 17:51:11 +00:00
|
|
|
if typeof name isnt 'string'
|
|
|
|
logErr '''
|
2015-11-20 19:44:36 +00:00
|
|
|
re-natal init requires a project name as the first argument.
|
2015-09-19 17:51:11 +00:00
|
|
|
e.g.
|
2015-11-20 19:44:36 +00:00
|
|
|
re-natal init HelloWorld
|
2015-09-19 17:51:11 +00:00
|
|
|
'''
|
2016-02-11 11:54:05 +00:00
|
|
|
unless interfaceConf[cmd.interface]
|
|
|
|
logErr "Unsupported React interface: #{cmd.interface}, one of [#{interfaceNames}] was expected."
|
2017-04-12 13:21:12 +00:00
|
|
|
platforms.push 'ios'
|
|
|
|
platforms.push 'android'
|
2017-04-12 11:02:25 +00:00
|
|
|
if cmd.uwp?
|
|
|
|
platforms.push 'windows'
|
2017-04-12 11:50:48 +00:00
|
|
|
if cmd.wpf?
|
|
|
|
platforms.push 'wpf'
|
2016-02-07 18:43:43 +00:00
|
|
|
ensureFreePort -> init(cmd.interface, name)
|
2015-09-19 17:51:11 +00:00
|
|
|
|
2015-11-29 21:36:49 +00:00
|
|
|
cli.command 'upgrade'
|
|
|
|
.description 'upgrades project files to current installed version of re-natal (the upgrade of re-natal itself is done via npm)'
|
|
|
|
.action ->
|
2016-01-29 19:25:00 +00:00
|
|
|
doUpgrade readConfig(false)
|
2015-11-29 21:36:49 +00:00
|
|
|
|
2017-04-30 18:05:32 +00:00
|
|
|
cli.command 'add-platform <platform>'
|
|
|
|
.description 'adds additional app platform: \'windows\' - UWP app, \'wpf\' - WPF app'
|
|
|
|
.action (platform) ->
|
|
|
|
addPlatform(platform)
|
2017-04-13 09:04:31 +00:00
|
|
|
|
2015-10-04 19:19:04 +00:00
|
|
|
cli.command 'xcode'
|
2015-10-30 03:57:09 +00:00
|
|
|
.description 'open Xcode project'
|
2015-10-04 19:19:04 +00:00
|
|
|
.action ->
|
2016-02-01 18:58:47 +00:00
|
|
|
ensureOSX ->
|
|
|
|
ensureXcode ->
|
|
|
|
openXcode readConfig().name
|
2015-10-04 19:19:04 +00:00
|
|
|
|
2015-11-14 23:21:39 +00:00
|
|
|
cli.command 'deps'
|
|
|
|
.description 'install all dependencies for the project'
|
|
|
|
.action ->
|
2016-01-29 19:25:00 +00:00
|
|
|
ckDeps.sync {install: true, verbose: true}
|
2015-11-14 23:21:39 +00:00
|
|
|
|
2015-11-27 22:57:14 +00:00
|
|
|
cli.command 'use-figwheel'
|
2017-04-12 09:03:33 +00:00
|
|
|
.description 'generate index.*.js for development with figwheel'
|
2016-01-24 12:46:34 +00:00
|
|
|
.action () ->
|
|
|
|
generateDevScripts()
|
|
|
|
|
|
|
|
cli.command 'use-android-device <type>'
|
2016-09-24 11:51:05 +00:00
|
|
|
.description 'sets up the host for android device type: \'real\' - localhost, \'avd\' - 10.0.2.2, \'genymotion\' - 10.0.3.2, IP'
|
2016-01-24 12:46:34 +00:00
|
|
|
.action (type) ->
|
|
|
|
configureDevHostForAndroidDevice type
|
2015-11-14 23:21:39 +00:00
|
|
|
|
2016-03-03 22:32:06 +00:00
|
|
|
cli.command 'use-ios-device <type>'
|
2016-05-15 00:09:41 +00:00
|
|
|
.description 'sets up the host for ios device type: \'simulator\' - localhost, \'real\' - auto detect IP on eth0, IP'
|
2016-03-03 22:32:06 +00:00
|
|
|
.action (type) ->
|
|
|
|
configureDevHostForIosDevice type
|
|
|
|
|
2016-11-21 18:48:48 +00:00
|
|
|
cli.command 'use-component <name> [<platform>]'
|
2016-01-04 22:10:13 +00:00
|
|
|
.description 'configures a custom component to work with figwheel. name is the value you pass to (js/require) function.'
|
2016-11-21 18:48:48 +00:00
|
|
|
.action (name, platform) ->
|
|
|
|
useComponent(name, platform)
|
2016-01-04 22:10:13 +00:00
|
|
|
|
2016-02-06 15:00:09 +00:00
|
|
|
cli.command 'enable-source-maps'
|
|
|
|
.description 'patches RN packager to server *.map files from filesystem, so that chrome can download them.'
|
|
|
|
.action () ->
|
|
|
|
patchReactNativePackager()
|
|
|
|
|
2016-02-05 16:52:12 +00:00
|
|
|
cli.command 'copy-figwheel-bridge'
|
|
|
|
.description 'copy figwheel-bridge.js into project'
|
|
|
|
.action () ->
|
|
|
|
copyFigwheelBridge(readConfig(false).name)
|
|
|
|
log "Copied figwheel-bridge.js"
|
|
|
|
|
2015-10-04 02:57:22 +00:00
|
|
|
cli.on '*', (command) ->
|
2015-11-20 19:44:36 +00:00
|
|
|
logErr "unknown command #{command[0]}. See re-natal --help for valid commands"
|
2015-10-04 02:57:22 +00:00
|
|
|
|
2015-09-19 17:51:11 +00:00
|
|
|
|
2015-10-03 19:36:24 +00:00
|
|
|
unless semver.satisfies process.version[1...], nodeVersion
|
|
|
|
logErr """
|
2015-11-20 19:44:36 +00:00
|
|
|
Re-Natal requires Node.js version #{nodeVersion}
|
2015-10-03 19:36:24 +00:00
|
|
|
You have #{process.version[1...]}
|
|
|
|
"""
|
|
|
|
|
2015-10-04 01:19:46 +00:00
|
|
|
if process.argv.length <= 2
|
|
|
|
cli.outputHelp()
|
|
|
|
else
|
|
|
|
cli.parse process.argv
|