Skip to content

Commit

Permalink
Merge pull request #147 from drapanjanas/fix-bug-in-do-upgrade
Browse files Browse the repository at this point in the history
Fix bug in do upgrade
  • Loading branch information
drapanjanas authored Oct 8, 2017
2 parents e67e7ae + 8d829e5 commit b627749
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions re-natal.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ platformMeta =
'wpf':
name: "WPF"
sources: ["core.cljs"]
platforms = []

log = (s, color = 'green') ->
console.log chalk[color] s
Expand Down Expand Up @@ -202,7 +201,7 @@ ensureXcode = (cb) ->
if message.match /type.+xcodebuild/i
logErr 'Xcode Command Line Tools are required'

generateConfig = (interfaceName, projName) ->
generateConfig = (interfaceName, platforms, projName) ->
log 'Creating Re-Natal config'
config =
name: projName
Expand Down Expand Up @@ -262,7 +261,7 @@ readLocalConfig = () ->
local = readConfig '.re-natal.local', false
verifyConfig merge(global, local)

scanImageDir = (dir) ->
scanImageDir = (dir, platforms) ->
fnames = fs.readdirSync(dir)
.map (fname) -> "#{dir}/#{fname}"
.filter (path) -> fs.statSync(path).isFile()
Expand All @@ -281,10 +280,10 @@ removeExcludeFiles = (file) ->
res = excludedFileNames.map (ex) -> (file.indexOf ex) == -1
true in res

scanImages = (dirs) ->
scanImages = (dirs, platforms) ->
imgs = []
for dir in dirs
imgs = imgs.concat(scanImageDir(dir));
imgs = imgs.concat(scanImageDir(dir, platforms));
imgs

resolveAndroidDevHost = (deviceType) ->
Expand Down Expand Up @@ -346,7 +345,7 @@ generateConfigNs = (config) ->
template = hb.compile(readFile "#{resources}/config.cljs")
fs.writeFileSync("#{config.envRoots.dev}/env/config.cljs", template(config))

copyDevEnvironmentFiles = (interfaceName, projNameHyph, projName, devEnvRoot) ->
copyDevEnvironmentFiles = (interfaceName, platforms, projNameHyph, projName, devEnvRoot) ->
userNsPath = "#{devEnvRoot}/user.clj"
fs.copySync("#{resources}/user.clj", userNsPath)

Expand All @@ -360,15 +359,15 @@ copyProdEnvironmentFilesForPlatform = (platform, interfaceName, projNameHyph, pr
fs.copySync("#{resources}/#{cljsDir}/main_prod.cljs", mainProdPath)
edit mainProdPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, platform]]

copyProdEnvironmentFiles = (interfaceName, projNameHyph, projName, prodEnvRoot) ->
copyProdEnvironmentFiles = (interfaceName, platforms, projNameHyph, projName, prodEnvRoot) ->
for platform in platforms
copyProdEnvironmentFilesForPlatform platform, interfaceName, projNameHyph, projName, prodEnvRoot

copyFigwheelBridge = (projNameUs) ->
fs.copySync("#{resources}/figwheel-bridge.js", "./figwheel-bridge.js")
edit "figwheel-bridge.js", [[projNameUsRx, projNameUs]]

updateGitIgnore = () ->
updateGitIgnore = (platforms) ->
fs.appendFileSync(".gitignore", "\n# Generated by re-natal\n#\n")

indexFiles = platforms.map (platform) -> "index.#{platform}.js"
Expand Down Expand Up @@ -413,7 +412,7 @@ copySrcFilesForPlatform = (platform, interfaceName, projName, projNameUs, projNa
fs.copySync("#{resources}/#{cljsDir}/#{fileName}", path)
edit path, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, platform]]

copySrcFiles = (interfaceName, projName, projNameUs, projNameHyph) ->
copySrcFiles = (interfaceName, platforms, projName, projNameUs, projNameHyph) ->
cljsDir = interfaceConf[interfaceName].cljsDir

fileNames = interfaceConf[interfaceName].sources.common;
Expand Down Expand Up @@ -444,7 +443,7 @@ creteBuildConfigs = (profiles, platforms) ->
builds[profile] = configs.join("\n")
builds

copyProjectClj = (interfaceName, projNameHyph) ->
copyProjectClj = (interfaceName, platforms, projNameHyph) ->
fs.copySync("#{resources}/project.clj", "project.clj")
deps = interfaceConf[interfaceName].deps.join("\n")

Expand Down Expand Up @@ -487,7 +486,7 @@ updateProjectClj = (platform) ->
[buildProfiles.advanced.profilesRx, builds.advanced]
]

init = (interfaceName, projName) ->
init = (interfaceName, projName, platforms) ->
if projName.toLowerCase() is 'react' or !projName.match validNameRx
logErr 'Invalid project name. Use an alphanumeric CamelCase name.'

Expand Down Expand Up @@ -515,12 +514,12 @@ init = (interfaceName, projName) ->
corePath = "src/#{projNameUs}/core.clj"
fs.unlinkSync corePath

copyProjectClj(interfaceName, projNameHyph)
copyProjectClj(interfaceName, platforms, projNameHyph)

copySrcFiles(interfaceName, projName, projNameUs, projNameHyph)
copySrcFiles(interfaceName, platforms, projName, projNameUs, projNameHyph)

copyDevEnvironmentFiles(interfaceName, projNameHyph, projName, defaultEnvRoots.dev)
copyProdEnvironmentFiles(interfaceName, projNameHyph, projName, defaultEnvRoots.prod)
copyDevEnvironmentFiles(interfaceName, platforms, projNameHyph, projName, defaultEnvRoots.dev)
copyProdEnvironmentFiles(interfaceName, platforms, projNameHyph, projName, defaultEnvRoots.prod)

fs.copySync("#{resources}/images", "./images")

Expand Down Expand Up @@ -561,9 +560,9 @@ init = (interfaceName, projName) ->
\"require('react-native-windows/local-cli/generate-wpf')('.', '#{projName}', '#{projName}')\"
"

updateGitIgnore()
updateGitIgnore(platforms)

config = generateConfig(interfaceName, projName)
config = generateConfig(interfaceName, platforms, projName)
generateConfigNs(config);

copyFigwheelBridge(projNameUs)
Expand Down Expand Up @@ -725,7 +724,8 @@ platformModulesAndImages = (config, platform) ->
requires = buildRequireByPlatformMap()
requires.common.concat(requires[platform])
else
images = scanImages(config.imageDirs).map (fname) -> './' + fname;
platforms = Object.keys config.platforms
images = scanImages(config.imageDirs, platforms).map (fname) -> './' + fname;
modulesAndImages = config.modules.concat images;
if typeof config.platforms[platform].modules is 'undefined'
modulesAndImages
Expand Down Expand Up @@ -774,6 +774,7 @@ doUpgrade = (config) ->
projName = config.name
projNameHyph = projName.replace(camelRx, '$1-$2').toLowerCase()
projNameUs = toUnderscored projName
platforms = Object.keys config.platforms

unless config.interface
config.interface = defaultInterface
Expand Down Expand Up @@ -819,8 +820,8 @@ doUpgrade = (config) ->
interfaceName = config.interface
envRoots = config.envRoots

copyDevEnvironmentFiles(interfaceName, projNameHyph, projName, envRoots.dev)
copyProdEnvironmentFiles(interfaceName, projNameHyph, projName, envRoots.prod)
copyDevEnvironmentFiles(interfaceName, platforms, projNameHyph, projName, envRoots.dev)
copyProdEnvironmentFiles(interfaceName, platforms, projNameHyph, projName, envRoots.prod)
generateConfigNs(config);
log "upgraded files in #{envRoots.dev} and #{envRoots.prod} "

Expand Down Expand Up @@ -899,13 +900,12 @@ cli.command 'init <name>'
'''
unless interfaceConf[cmd.interface]
logErr "Unsupported React interface: #{cmd.interface}, one of [#{interfaceNames}] was expected."
platforms.push 'ios'
platforms.push 'android'
platforms = ['ios', 'android']
if cmd.uwp?
platforms.push 'windows'
if cmd.wpf?
platforms.push 'wpf'
ensureFreePort -> init(cmd.interface, name)
ensureFreePort -> init(cmd.interface, name, platforms)

cli.command 'upgrade'
.description 'upgrades project files to current installed version of re-natal (the upgrade of re-natal itself is done via npm)'
Expand Down

0 comments on commit b627749

Please sign in to comment.