Parameterized platforms in project.clj

This commit is contained in:
amorokh 2017-04-12 12:07:11 +02:00
parent 76c4bc78e4
commit a10bc8906b
4 changed files with 35 additions and 34 deletions

View File

@ -24,6 +24,8 @@ projNameRx = /\$PROJECT_NAME\$/g
projNameHyphRx = /\$PROJECT_NAME_HYPHENATED\$/g projNameHyphRx = /\$PROJECT_NAME_HYPHENATED\$/g
projNameUsRx = /\$PROJECT_NAME_UNDERSCORED\$/g projNameUsRx = /\$PROJECT_NAME_UNDERSCORED\$/g
interfaceDepsRx = /\$INTERFACE_DEPS\$/g interfaceDepsRx = /\$INTERFACE_DEPS\$/g
devProfilesRx = /\$DEV_PROFILES\$/g
prodProfilesRx = /\$PROD_PROFILES\$/g
platformRx = /\$PLATFORM\$/g platformRx = /\$PLATFORM\$/g
devHostRx = /\$DEV_HOST\$/g devHostRx = /\$DEV_HOST\$/g
ipAddressRx = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/i ipAddressRx = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/i
@ -364,9 +366,18 @@ copySrcFiles = (interfaceName, projName, projNameUs, projNameHyph) ->
shimCljsNamespace(namespace) shimCljsNamespace(namespace)
copyProjectClj = (interfaceName, projNameHyph) -> copyProjectClj = (interfaceName, projNameHyph) ->
devProfileTemplate = readFile "#{resources}/dev.profile"
prodProfileTemplate = readFile "#{resources}/prod.profile"
devProfiles = []
prodProfiles = []
for platform in platforms
devProfiles.push devProfileTemplate.replace(platformRx, platform)
prodProfiles.push prodProfileTemplate.replace(platformRx, platform)
fs.copySync("#{resources}/project.clj", "project.clj") fs.copySync("#{resources}/project.clj", "project.clj")
deps = interfaceConf[interfaceName].deps.join("\n") deps = interfaceConf[interfaceName].deps.join("\n")
edit 'project.clj', [[projNameHyphRx, projNameHyph], [interfaceDepsRx, deps]] edit 'project.clj', [[projNameHyphRx, projNameHyph], [interfaceDepsRx, deps], [devProfilesRx, devProfiles.join("\n")], [prodProfilesRx, prodProfiles.join("\n")]]
init = (interfaceName, projName) -> init = (interfaceName, projName) ->
if projName.toLowerCase() is 'react' or !projName.match validNameRx if projName.toLowerCase() is 'react' or !projName.match validNameRx

7
resources/dev.profile Normal file
View File

@ -0,0 +1,7 @@
{:id "$PLATFORM$"
:source-paths ["src" "env/dev"]
:figwheel true
:compiler {:output-to "target/$PLATFORM$/not-used.js"
:main "env.$PLATFORM$.main"
:output-dir "target/$PLATFORM$"
:optimizations :none}}

9
resources/prod.profile Normal file
View File

@ -0,0 +1,9 @@
{:id "$PLATFORM$"
:source-paths ["src" "env/prod"]
:compiler {:output-to "index.$PLATFORM$.js"
:main "env.$PLATFORM$.main"
:output-dir "target/$PLATFORM$"
:static-fns true
:optimize-constants true
:optimizations :simple
:closure-defines {"goog.DEBUG" false}}}

View File

@ -15,36 +15,10 @@
:profiles {:dev {:dependencies [[figwheel-sidecar "0.5.8"] :profiles {:dev {:dependencies [[figwheel-sidecar "0.5.8"]
[com.cemerick/piggieback "0.2.1"]] [com.cemerick/piggieback "0.2.1"]]
:source-paths ["src" "env/dev"] :source-paths ["src" "env/dev"]
:cljsbuild {:builds [{:id "ios" :cljsbuild {:builds [
:source-paths ["src" "env/dev"] $DEV_PROFILES$]}
:figwheel true
:compiler {:output-to "target/ios/not-used.js"
:main "env.ios.main"
:output-dir "target/ios"
:optimizations :none}}
{:id "android"
:source-paths ["src" "env/dev"]
:figwheel true
:compiler {:output-to "target/android/not-used.js"
:main "env.android.main"
:output-dir "target/android"
:optimizations :none}}]}
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}} :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}}
:prod {:cljsbuild {:builds [{:id "ios" :prod {:cljsbuild {:builds [
:source-paths ["src" "env/prod"] $PROD_PROFILES$]}}})
:compiler {:output-to "index.ios.js"
:main "env.ios.main"
:output-dir "target/ios"
:static-fns true
:optimize-constants true
:optimizations :simple
:closure-defines {"goog.DEBUG" false}}}
{:id "android"
:source-paths ["src" "env/prod"]
:compiler {:output-to "index.android.js"
:main "env.android.main"
:output-dir "target/android"
:static-fns true
:optimize-constants true
:optimizations :simple
:closure-defines {"goog.DEBUG" false}}}]}}})