get rid of global mutable variable 'platforms'
This commit is contained in:
parent
05362a9ce8
commit
8d829e5cc9
|
@ -105,7 +105,6 @@ platformMeta =
|
|||
'wpf':
|
||||
name: "WPF"
|
||||
sources: ["core.cljs"]
|
||||
platforms = []
|
||||
|
||||
log = (s, color = 'green') ->
|
||||
console.log chalk[color] s
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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) ->
|
||||
|
@ -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)
|
||||
|
||||
|
@ -360,7 +359,7 @@ 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
|
||||
|
||||
|
@ -368,7 +367,7 @@ 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"
|
||||
|
@ -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;
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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.'
|
||||
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -818,10 +819,9 @@ doUpgrade = (config) ->
|
|||
|
||||
interfaceName = config.interface
|
||||
envRoots = config.envRoots
|
||||
platforms = Object.keys config.platforms ## hack!!! TDOD: remove global platforms
|
||||
|
||||
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} "
|
||||
|
||||
|
@ -900,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)'
|
||||
|
|
Loading…
Reference in New Issue