add a check for missing npm dependencies and validity of .re-natal config file #17

- using lib https://www.npmjs.com/package/check-dependencies
This commit is contained in:
Artur Girenko 2016-01-29 20:25:00 +01:00
parent eb969d8709
commit 33a38b7c73
2 changed files with 21 additions and 10 deletions

View File

@ -9,7 +9,8 @@
"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",
"semver": "^5.0.1" "semver": "^5.0.1",
"check-dependencies":"^0.11.0"
}, },
"engines": { "engines": {
"node": ">=4.0.0" "node": ">=4.0.0"

View File

@ -12,6 +12,7 @@ child = require 'child_process'
cli = require 'commander' cli = require 'commander'
chalk = require 'chalk' chalk = require 'chalk'
semver = require 'semver' semver = require 'semver'
ckDeps = require 'check-dependencies'
pkgJson = require __dirname + '/package.json' pkgJson = require __dirname + '/package.json'
nodeVersion = pkgJson.engines.node nodeVersion = pkgJson.engines.node
@ -26,7 +27,6 @@ devHostRx = /\$DEV_HOST\$/g
figwheelUrlRx = /ws:\/\/[0-9a-zA-Z\.]*:/g figwheelUrlRx = /ws:\/\/[0-9a-zA-Z\.]*:/g
rnVersion = '0.18.1' rnVersion = '0.18.1'
rnPackagerPort = 8081 rnPackagerPort = 8081
podMinVersion = '0.38.2'
process.title = 're-natal' process.title = 're-natal'
sampleCommand = '(dispatch [:set-greeting "Hello Native World!"])' sampleCommand = '(dispatch [:set-greeting "Hello Native World!"])'
@ -138,10 +138,18 @@ writeConfig = (config) ->
else else
message message
verifyConfig = (config) ->
if !config.androidHost? || !config.modules? || !config.imageDirs?
throw new Error 're-natal project needs to be upgraded, please run: re-natal upgrade'
config
readConfig = -> readConfig = (verify = true)->
try try
JSON.parse readFile '.re-natal' config = JSON.parse readFile '.re-natal'
if (verify)
verifyConfig(config)
else
config
catch {message} catch {message}
logErr \ logErr \
if message.match /ENOENT/i if message.match /ENOENT/i
@ -458,6 +466,10 @@ generateDevScripts = () ->
config = readConfig() config = readConfig()
projName = config.name projName = config.name
depState = ckDeps.sync {install: false, verbose: false}
if (!depState.depsWereOk)
throw new Error "Missing dependencies, please run: re-natal deps"
log 'Cleaning...' log 'Cleaning...'
exec 'lein clean' exec 'lein clean'
@ -488,6 +500,8 @@ doUpgrade = (config) ->
projNameHyph = projName.replace(camelRx, '$1-$2').toLowerCase() projNameHyph = projName.replace(camelRx, '$1-$2').toLowerCase()
projNameUs = toUnderscored projName projNameUs = toUnderscored projName
ckDeps.sync {install: true, verbose: false}
patchReactNativePackager() patchReactNativePackager()
copyDevEnvironmentFiles(projNameHyph, projName, "localhost") copyDevEnvironmentFiles(projNameHyph, projName, "localhost")
@ -546,7 +560,7 @@ cli.command 'launch'
cli.command 'upgrade' cli.command 'upgrade'
.description 'upgrades project files to current installed version of re-natal (the upgrade of re-natal itself is done via npm)' .description 'upgrades project files to current installed version of re-natal (the upgrade of re-natal itself is done via npm)'
.action -> .action ->
doUpgrade readConfig() doUpgrade readConfig(false)
cli.command 'listdevices' cli.command 'listdevices'
.description 'list available simulator devices by index' .description 'list available simulator devices by index'
@ -576,11 +590,7 @@ cli.command 'xcode'
cli.command 'deps' cli.command 'deps'
.description 'install all dependencies for the project' .description 'install all dependencies for the project'
.action -> .action ->
try ckDeps.sync {install: true, verbose: true}
log 'Installing npm packages'
exec 'npm i'
catch {message}
logErr message
cli.command 'use-figwheel' cli.command 'use-figwheel'
.description 'generate index.ios.js and index.android.js for development with figwheel' .description 'generate index.ios.js and index.android.js for development with figwheel'