added packager port checking function
This commit is contained in:
parent
498de825d2
commit
a0b98ef664
20
natal.coffee
20
natal.coffee
|
@ -5,6 +5,8 @@
|
||||||
# MIT License
|
# MIT License
|
||||||
|
|
||||||
fs = require 'fs'
|
fs = require 'fs'
|
||||||
|
net = require 'net'
|
||||||
|
http = require 'http'
|
||||||
crypto = require 'crypto'
|
crypto = require 'crypto'
|
||||||
child = require 'child_process'
|
child = require 'child_process'
|
||||||
cli = require 'commander'
|
cli = require 'commander'
|
||||||
|
@ -19,6 +21,7 @@ projNameRx = /\$PROJECT_NAME\$/g
|
||||||
projNameHyphRx = /\$PROJECT_NAME_HYPHENATED\$/g
|
projNameHyphRx = /\$PROJECT_NAME_HYPHENATED\$/g
|
||||||
projNameUnderRx = /\$PROJECT_NAME_UNDERSCORED\$/g
|
projNameUnderRx = /\$PROJECT_NAME_UNDERSCORED\$/g
|
||||||
rnVersion = '0.13.0-rc'
|
rnVersion = '0.13.0-rc'
|
||||||
|
rnPackagerPort = 8081
|
||||||
podMinVersion = '0.38.2'
|
podMinVersion = '0.38.2'
|
||||||
process.title = 'natal'
|
process.title = 'natal'
|
||||||
|
|
||||||
|
@ -57,6 +60,23 @@ toUnderscored = (s) ->
|
||||||
s.replace(camelRx, '$1_$2').toLowerCase()
|
s.replace(camelRx, '$1_$2').toLowerCase()
|
||||||
|
|
||||||
|
|
||||||
|
checkPort = (port, cb) ->
|
||||||
|
sock = net.connect {port}, ->
|
||||||
|
sock.end()
|
||||||
|
req = http.get "http://localhost:#{port}/status", (res) ->
|
||||||
|
data = ''
|
||||||
|
res.on 'data', (chunk) -> data += chunk
|
||||||
|
res.on 'end', ->
|
||||||
|
cb data.toString() isnt 'packager-status:running'
|
||||||
|
|
||||||
|
.on 'error', -> cb true
|
||||||
|
.setTimeout 3000
|
||||||
|
|
||||||
|
sock.on 'error', ->
|
||||||
|
sock.end()
|
||||||
|
cb false
|
||||||
|
|
||||||
|
|
||||||
writeConfig = (config) ->
|
writeConfig = (config) ->
|
||||||
try
|
try
|
||||||
fs.writeFileSync '.natal', JSON.stringify config, null, 2
|
fs.writeFileSync '.natal', JSON.stringify config, null, 2
|
||||||
|
|
Loading…
Reference in New Issue