diff --git a/re-natal.coffee b/re-natal.coffee index 5babd9f..8c24ac7 100644 --- a/re-natal.coffee +++ b/re-natal.coffee @@ -77,7 +77,6 @@ getUuidForDevice = (deviceName) -> toUnderscored = (s) -> s.replace(camelRx, '$1_$2').toLowerCase() - checkPort = (port, cb) -> sock = net.connect {port}, -> sock.end() @@ -121,6 +120,7 @@ generateConfig = (name) -> config = name: name modules: [] + imageDirs: ["images"] writeConfig config config @@ -175,6 +175,24 @@ getBundleId = (name) -> catch {message} logErr message +scanImageDir = (dir) -> + fnames = fs.readdirSync(dir) + .map (fname) -> "#{dir}/#{fname}" + .filter (path) -> fs.statSync(path).isFile() + .map (path) -> path.replace /@2x|@3x/i, '' + .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) + +scanImages = (dirs) -> + imgs = [] + for dir in dirs + imgs = imgs.concat(scanImageDir(dir)); + imgs copyDevEnvironmentFiles = (projNameHyph, projName, devHost) -> mkdirSync "env/dev" @@ -193,10 +211,6 @@ copyDevEnvironmentFiles = (projNameHyph, projName, devHost) -> exec "cp #{resources}cljs/main_dev.cljs #{mainAndroidDevPath}" edit mainAndroidDevPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "android"], [devHostRx, devHost]] - requestImgMacroDevPath = "env/dev/env/require_img.clj" - exec "cp #{resources}require_img_dev.clj #{requestImgMacroDevPath}" - edit requestImgMacroDevPath, [[devHostRx, devHost]] - copyProdEnvironmentFiles = (projNameHyph, projName) -> mkdirSync "env/prod" mkdirSync "env/prod/env" @@ -211,9 +225,6 @@ copyProdEnvironmentFiles = (projNameHyph, projName) -> exec "cp #{resources}cljs/main_prod.cljs #{mainAndroidProdPath}" edit mainAndroidProdPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "android"]] - requestImgMacroProdPath = "env/prod/env/require_img.clj" - exec "cp #{resources}require_img_prod.clj #{requestImgMacroProdPath}" - copyFigwheelBridge = (projNameUs) -> exec "cp #{resources}figwheel-bridge.js ." edit "figwheel-bridge.js", [[projNameUsRx, projNameUs]] @@ -424,7 +435,9 @@ generateDevScripts = (devHost) -> log 'Cleaning...' exec 'lein clean' - moduleMap = generateRequireModulesCode config.modules + images = scanImages(config.imageDirs).map (fname) -> './' + fname; + modulesAndImages = config.modules.concat images; + moduleMap = generateRequireModulesCode modulesAndImages fs.writeFileSync 'index.ios.js', "#{moduleMap}require('figwheel-bridge').withModules(modules).start('#{projName}','ios','#{devHost}');" log 'index.ios.js was regenerated' @@ -455,6 +468,9 @@ doUpgrade = (config) -> if (!config.modules) config.modules = [] + if (!config.imageDirs) + config.imageDirs = ["images"] + writeConfig(config) log 'upgraded .re-natal' diff --git a/resources/cljs/core.cljs b/resources/cljs/core.cljs index ce446f4..3c2eb25 100644 --- a/resources/cljs/core.cljs +++ b/resources/cljs/core.cljs @@ -1,5 +1,4 @@ (ns ^:figwheel-load $PROJECT_NAME_HYPHENATED$.$PLATFORM$.core - (:require-macros [env.require-img :refer [require-img]]) (:require [reagent.core :as r :refer [atom]] [re-frame.core :refer [subscribe dispatch dispatch-sync]] [$PROJECT_NAME_HYPHENATED$.handlers] @@ -13,7 +12,7 @@ (def image (r/adapt-react-class (.-Image js/React))) (def touchable-highlight (r/adapt-react-class (.-TouchableHighlight js/React))) -(def logo-img (require-img "./images/cljs.png")) +(def logo-img (js/require "./images/cljs.png")) (defn alert [title] (.alert (.-Alert js/React) title)) diff --git a/resources/images/cljs.png b/resources/images/cljs.png index 7468cab..a7eca5d 100644 Binary files a/resources/images/cljs.png and b/resources/images/cljs.png differ diff --git a/resources/images/cljs@2x.png b/resources/images/cljs@2x.png new file mode 100644 index 0000000..79af2b6 Binary files /dev/null and b/resources/images/cljs@2x.png differ diff --git a/resources/images/cljs@3x.png b/resources/images/cljs@3x.png new file mode 100644 index 0000000..685d699 Binary files /dev/null and b/resources/images/cljs@3x.png differ diff --git a/resources/require_img_dev.clj b/resources/require_img_dev.clj deleted file mode 100644 index 99e92d8..0000000 --- a/resources/require_img_dev.clj +++ /dev/null @@ -1,6 +0,0 @@ -(ns env.require-img) - -(defmacro require-img - "Load image from local packager service" - [src] - {:uri (str "http://$DEV_HOST$:8081/" src)}) diff --git a/resources/require_img_prod.clj b/resources/require_img_prod.clj deleted file mode 100644 index ceedc8a..0000000 --- a/resources/require_img_prod.clj +++ /dev/null @@ -1,6 +0,0 @@ -(ns env.require-img) - -(defmacro require-img - "Creates 'require' statements for images" - [src] - (list 'js/require src))