Merge pull request #21 from marxama/master

Added support for Windows
This commit is contained in:
Artūr Girenko 2016-02-01 19:33:15 +01:00
commit 006bc7d781
2 changed files with 27 additions and 17 deletions

View File

@ -9,6 +9,7 @@
"chalk": "^1.1.1", "chalk": "^1.1.1",
"coffee-script": "^1.9.3", "coffee-script": "^1.9.3",
"commander": "^2.8.1", "commander": "^2.8.1",
"fs-extra": "^0.26.5",
"semver": "^5.0.1", "semver": "^5.0.1",
"check-dependencies":"^0.11.0" "check-dependencies":"^0.11.0"
}, },

View File

@ -4,9 +4,10 @@
# http://oxism.com # http://oxism.com
# MIT License # MIT License
fs = require 'fs' fs = require 'fs-extra'
net = require 'net' net = require 'net'
http = require 'http' http = require 'http'
os = require 'os'
crypto = require 'crypto' crypto = require 'crypto'
child = require 'child_process' child = require 'child_process'
cli = require 'commander' cli = require 'commander'
@ -45,6 +46,14 @@ exec = (cmd, keepOutput) ->
else else
child.execSync cmd, stdio: 'ignore' child.execSync cmd, stdio: 'ignore'
ensureExecutableAvailable = (executable) ->
if os.platform() == 'win32'
try
exec "where #{executable}"
catch e
throw new Error("type: #{executable}: not found")
else
exec "type #{executable}"
readFile = (path) -> readFile = (path) ->
fs.readFileSync path, encoding: 'ascii' fs.readFileSync path, encoding: 'ascii'
@ -224,14 +233,14 @@ copyDevEnvironmentFiles = (projNameHyph, projName, devHost) ->
mkdirSync "env/dev/env/android" mkdirSync "env/dev/env/android"
userNsPath = "env/dev/user.clj" userNsPath = "env/dev/user.clj"
exec "cp #{resources}user.clj #{userNsPath}" fs.copySync("#{resources}user.clj", userNsPath)
mainIosDevPath = "env/dev/env/ios/main.cljs" mainIosDevPath = "env/dev/env/ios/main.cljs"
mainAndroidDevPath = "env/dev/env/android/main.cljs" mainAndroidDevPath = "env/dev/env/android/main.cljs"
exec "cp #{resources}cljs/main_dev.cljs #{mainIosDevPath}" fs.copySync("#{resources}cljs/main_dev.cljs", mainIosDevPath)
edit mainIosDevPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "ios"], [devHostRx, devHost] ] edit mainIosDevPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "ios"], [devHostRx, devHost] ]
exec "cp #{resources}cljs/main_dev.cljs #{mainAndroidDevPath}" fs.copySync("#{resources}cljs/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 = (projNameHyph, projName) -> copyProdEnvironmentFiles = (projNameHyph, projName) ->
@ -243,13 +252,13 @@ copyProdEnvironmentFiles = (projNameHyph, projName) ->
mainIosProdPath = "env/prod/env/ios/main.cljs" mainIosProdPath = "env/prod/env/ios/main.cljs"
mainAndroidProdPath = "env/prod/env/android/main.cljs" mainAndroidProdPath = "env/prod/env/android/main.cljs"
exec "cp #{resources}cljs/main_prod.cljs #{mainIosProdPath}" fs.copySync("#{resources}cljs/main_prod.cljs", mainIosProdPath)
edit mainIosProdPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "ios"]] edit mainIosProdPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "ios"]]
exec "cp #{resources}cljs/main_prod.cljs #{mainAndroidProdPath}" fs.copySync("#{resources}cljs/main_prod.cljs", mainAndroidProdPath)
edit mainAndroidProdPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "android"]] edit mainAndroidProdPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "android"]]
copyFigwheelBridge = (projNameUs) -> copyFigwheelBridge = (projNameUs) ->
exec "cp #{resources}figwheel-bridge.js ." fs.copySync("#{resources}figwheel-bridge.js", "./figwheel-bridge.js")
edit "figwheel-bridge.js", [[projNameUsRx, projNameUs]] edit "figwheel-bridge.js", [[projNameUsRx, projNameUs]]
updateGitIgnore = () -> updateGitIgnore = () ->
@ -275,21 +284,21 @@ init = (projName) ->
if fs.existsSync projNameHyph if fs.existsSync projNameHyph
throw new Error "Directory #{projNameHyph} already exists" throw new Error "Directory #{projNameHyph} already exists"
exec 'type lein' ensureExecutableAvailable 'lein'
log 'Creating Leiningen project' log 'Creating Leiningen project'
exec "lein new #{projNameHyph}" exec "lein new #{projNameHyph}"
log 'Updating Leiningen project' log 'Updating Leiningen project'
process.chdir projNameHyph process.chdir projNameHyph
exec "cp #{resources}project.clj project.clj" fs.copySync("#{resources}project.clj", "project.clj")
edit \ edit \
'project.clj', 'project.clj',
[ [
[projNameHyphRx, projNameHyph] [projNameHyphRx, projNameHyph]
] ]
exec "rm -rf resources" fs.removeSync "resources"
corePath = "src/#{projNameUs}/core.clj" corePath = "src/#{projNameUs}/core.clj"
fs.unlinkSync corePath fs.unlinkSync corePath
@ -297,16 +306,16 @@ init = (projName) ->
handlersPath = "src/#{projNameUs}/handlers.cljs" handlersPath = "src/#{projNameUs}/handlers.cljs"
subsPath = "src/#{projNameUs}/subs.cljs" subsPath = "src/#{projNameUs}/subs.cljs"
dbPath = "src/#{projNameUs}/db.cljs" dbPath = "src/#{projNameUs}/db.cljs"
exec "cp #{resources}cljs/handlers.cljs #{handlersPath}" fs.copySync("#{resources}cljs/handlers.cljs", handlersPath)
exec "cp #{resources}cljs/subs.cljs #{subsPath}" fs.copySync("#{resources}cljs/subs.cljs", subsPath)
exec "cp #{resources}cljs/db.cljs #{dbPath}" fs.copySync("#{resources}cljs/db.cljs", dbPath)
edit handlersPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName]] edit handlersPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName]]
edit subsPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName]] edit subsPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName]]
edit dbPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName]] edit dbPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName]]
fs.mkdirSync 'src/cljsjs' fs.mkdirSync 'src/cljsjs'
exec "echo '(ns cljsjs.react)' > src/cljsjs/react.cljs" fs.writeFileSync("src/cljsjs/react.cljs", "(ns cljsjs.react)")
fs.mkdirSync "src/#{projNameUs}/android" fs.mkdirSync "src/#{projNameUs}/android"
fs.mkdirSync "src/#{projNameUs}/ios" fs.mkdirSync "src/#{projNameUs}/ios"
@ -314,10 +323,10 @@ init = (projName) ->
coreAndroidPath = "src/#{projNameUs}/android/core.cljs" coreAndroidPath = "src/#{projNameUs}/android/core.cljs"
coreIosPath = "src/#{projNameUs}/ios/core.cljs" coreIosPath = "src/#{projNameUs}/ios/core.cljs"
exec "cp #{resources}cljs/core.cljs #{coreAndroidPath}" fs.copySync("#{resources}cljs/core.cljs", coreAndroidPath)
edit coreAndroidPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "android"]] edit coreAndroidPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "android"]]
exec "cp #{resources}cljs/core.cljs #{coreIosPath}" fs.copySync("#{resources}cljs/core.cljs", coreIosPath)
edit coreIosPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "ios"]] edit coreIosPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "ios"]]
fs.mkdirSync "env" fs.mkdirSync "env"
@ -325,7 +334,7 @@ init = (projName) ->
copyDevEnvironmentFiles(projNameHyph, projName, "localhost") copyDevEnvironmentFiles(projNameHyph, projName, "localhost")
copyProdEnvironmentFiles(projNameHyph, projName) copyProdEnvironmentFiles(projNameHyph, projName)
exec "cp -r #{resources}images ." fs.copySync("#{resources}images", "./images")
log 'Creating React Native skeleton. Relax, this takes a while...' log 'Creating React Native skeleton. Relax, this takes a while...'