make env source roots configurable in .re-natal file

this improves flexibility to have other projects coexist with thise generated by re-natal fixes #34
removed some old upgrade code
This commit is contained in:
Artur Girenko 2016-04-08 23:32:29 +02:00
parent 5a29e9383a
commit 952d0b8a4c
1 changed files with 31 additions and 34 deletions

View File

@ -60,6 +60,9 @@ interfaceConf =
sampleCommand: '(swap! app-state assoc :app/msg "Hello Native World!")' sampleCommand: '(swap! app-state assoc :app/msg "Hello Native World!")'
interfaceNames = Object.keys interfaceConf interfaceNames = Object.keys interfaceConf
defaultInterface = 'reagent' defaultInterface = 'reagent'
defaultEnvRoots =
dev: 'env/dev'
prod: 'env/prod'
log = (s, color = 'green') -> log = (s, color = 'green') ->
console.log chalk[color] s console.log chalk[color] s
@ -143,6 +146,7 @@ generateConfig = (interfaceName, projName) ->
interface: interfaceName interface: interfaceName
androidHost: "localhost" androidHost: "localhost"
iosHost: "localhost" iosHost: "localhost"
devRoots: defaultEnvRoots
modules: [] modules: []
imageDirs: ["images"] imageDirs: ["images"]
@ -239,15 +243,15 @@ configureDevHostForIosDevice = (deviceType) ->
catch {message} catch {message}
logErr message logErr message
copyDevEnvironmentFiles = (interfaceName, projNameHyph, projName, devHost) -> copyDevEnvironmentFiles = (interfaceName, projNameHyph, projName, devEnvRoot, devHost) ->
fs.mkdirpSync "env/dev/env/ios" fs.mkdirpSync "#{devEnvRoot}/env/ios"
fs.mkdirpSync "env/dev/env/android" fs.mkdirpSync "#{devEnvRoot}/env/android"
userNsPath = "env/dev/user.clj" userNsPath = "#{devEnvRoot}/user.clj"
fs.copySync("#{resources}/user.clj", userNsPath) fs.copySync("#{resources}/user.clj", userNsPath)
mainIosDevPath = "env/dev/env/ios/main.cljs" mainIosDevPath = "#{devEnvRoot}/env/ios/main.cljs"
mainAndroidDevPath = "env/dev/env/android/main.cljs" mainAndroidDevPath = "#{devEnvRoot}/env/android/main.cljs"
cljsDir = interfaceConf[interfaceName].cljsDir cljsDir = interfaceConf[interfaceName].cljsDir
fs.copySync("#{resources}/#{cljsDir}/main_dev.cljs", mainIosDevPath) fs.copySync("#{resources}/#{cljsDir}/main_dev.cljs", mainIosDevPath)
@ -255,12 +259,12 @@ copyDevEnvironmentFiles = (interfaceName, projNameHyph, projName, devHost) ->
fs.copySync("#{resources}/#{cljsDir}/main_dev.cljs", mainAndroidDevPath) fs.copySync("#{resources}/#{cljsDir}/main_dev.cljs", mainAndroidDevPath)
edit mainAndroidDevPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "android"], [devHostRx, devHost]] edit mainAndroidDevPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "android"], [devHostRx, devHost]]
copyProdEnvironmentFiles = (interfaceName, projNameHyph, projName) -> copyProdEnvironmentFiles = (interfaceName, projNameHyph, projName, prodEnvRoot) ->
fs.mkdirpSync "env/prod/env/ios" fs.mkdirpSync "#{prodEnvRoot}/env/ios"
fs.mkdirpSync "env/prod/env/android" fs.mkdirpSync "#{prodEnvRoot}/env/android"
mainIosProdPath = "env/prod/env/ios/main.cljs" mainIosProdPath = "#{prodEnvRoot}/env/ios/main.cljs"
mainAndroidProdPath = "env/prod/env/android/main.cljs" mainAndroidProdPath = "#{prodEnvRoot}/env/android/main.cljs"
cljsDir = interfaceConf[interfaceName].cljsDir cljsDir = interfaceConf[interfaceName].cljsDir
fs.copySync("#{resources}/#{cljsDir}/main_prod.cljs", mainIosProdPath) fs.copySync("#{resources}/#{cljsDir}/main_prod.cljs", mainIosProdPath)
@ -349,10 +353,8 @@ init = (interfaceName, projName) ->
copySrcFiles(interfaceName, projName, projNameUs, projNameHyph) copySrcFiles(interfaceName, projName, projNameUs, projNameHyph)
fs.mkdirSync "env" copyDevEnvironmentFiles(interfaceName, projNameHyph, projName, defaultEnvRoots.dev, "localhost")
copyProdEnvironmentFiles(interfaceName, projNameHyph, projName, defaultEnvRoots.prod)
copyDevEnvironmentFiles(interfaceName, projNameHyph, projName, "localhost")
copyProdEnvironmentFiles(interfaceName, projNameHyph, projName)
fs.copySync("#{resources}/images", "./images") fs.copySync("#{resources}/images", "./images")
@ -438,11 +440,11 @@ generateRequireModulesCode = (modules) ->
jsCode += "modules['#{m}']=require('#{m}');"; jsCode += "modules['#{m}']=require('#{m}');";
jsCode += '\n' jsCode += '\n'
updateFigwheelUrls = (androidHost, iosHost) -> updateFigwheelUrls = (devEnvRoot, androidHost, iosHost) ->
mainAndroidDevPath = "env/dev/env/android/main.cljs" mainAndroidDevPath = "#{devEnvRoot}/env/android/main.cljs"
edit mainAndroidDevPath, [[figwheelUrlRx, "ws://#{androidHost}:"]] edit mainAndroidDevPath, [[figwheelUrlRx, "ws://#{androidHost}:"]]
mainIosDevPath = "env/dev/env/ios/main.cljs" mainIosDevPath = "#{devEnvRoot}/env/ios/main.cljs"
edit mainIosDevPath, [[figwheelUrlRx, "ws://#{iosHost}:"]] edit mainIosDevPath, [[figwheelUrlRx, "ws://#{iosHost}:"]]
updateIosAppDelegate = (projName, iosHost) -> updateIosAppDelegate = (projName, iosHost) ->
@ -453,6 +455,7 @@ generateDevScripts = () ->
try try
config = readConfig() config = readConfig()
projName = config.name projName = config.name
devEnvRoot = config.envRoots.dev
depState = ckDeps.sync {install: false, verbose: false} depState = ckDeps.sync {install: false, verbose: false}
if (!depState.depsWereOk) if (!depState.depsWereOk)
@ -476,7 +479,7 @@ generateDevScripts = () ->
updateIosAppDelegate(projName, iosDevHost) updateIosAppDelegate(projName, iosDevHost)
log "AppDelegate.m was updated" log "AppDelegate.m was updated"
updateFigwheelUrls(androidDevHost, iosDevHost) updateFigwheelUrls(devEnvRoot, androidDevHost, iosDevHost)
log 'Dev server host for iOS: ' + iosDevHost log 'Dev server host for iOS: ' + iosDevHost
log 'Dev server host for Android: ' + androidDevHost log 'Dev server host for Android: ' + androidDevHost
@ -488,7 +491,7 @@ generateDevScripts = () ->
message message
doUpgrade = (config) -> doUpgrade = (config) ->
projName = config.name; projName = config.name
projNameHyph = projName.replace(camelRx, '$1-$2').toLowerCase() projNameHyph = projName.replace(camelRx, '$1-$2').toLowerCase()
projNameUs = toUnderscored projName projNameUs = toUnderscored projName
@ -507,28 +510,22 @@ doUpgrade = (config) ->
unless config.iosHost unless config.iosHost
config.iosHost = "localhost" config.iosHost = "localhost"
unless config.envRoots
config.envRoots = defaultEnvRoots
writeConfig(config) writeConfig(config)
log 'upgraded .re-natal' log 'upgraded .re-natal'
interfaceName = config.interface; interfaceName = config.interface
envRoots = config.envRoots
copyDevEnvironmentFiles(interfaceName, projNameHyph, projName, "localhost") copyDevEnvironmentFiles(interfaceName, projNameHyph, projName, envRoots.dev, "localhost")
copyProdEnvironmentFiles(interfaceName, projNameHyph, projName) copyProdEnvironmentFiles(interfaceName, projNameHyph, projName, envRoots.prod)
log 'upgraded files in env/' log "upgraded files in #{envRoots.dev} and #{envRoots.prod} "
copyFigwheelBridge(projNameUs) copyFigwheelBridge(projNameUs)
log 'upgraded figwheel-bridge.js' log 'upgraded figwheel-bridge.js'
edit "src/#{projNameUs}/ios/core.cljs", [[/\^:figwheel-load\s/g, ""]]
edit "src/#{projNameUs}/android/core.cljs", [[/\^:figwheel-load\s/g, ""]]
log 'upgraded core.cljs'
edit '.gitignore', [[/^\s*env\/dev\s*$/m, ""]]
gignore = readFile '.gitignore'
if (!gignore.match /^\s*target\/\s*$/m)
fs.appendFileSync(".gitignore", "\ntarget/\n")
log 'upgraded .gitignore'
useComponent = (name) -> useComponent = (name) ->
log "Component '#{name}' is now configured for figwheel, please re-run 'use-figwheel' command to take effect" log "Component '#{name}' is now configured for figwheel, please re-run 'use-figwheel' command to take effect"
try try