Merge pull request #119 from carocad/infer
Infer components using a regex
This commit is contained in:
commit
7bfbcf832a
|
@ -7,11 +7,12 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^1.1.1",
|
"chalk": "^1.1.1",
|
||||||
|
"check-dependencies": "^1.0.1",
|
||||||
"coffee-script": "^1.9.3",
|
"coffee-script": "^1.9.3",
|
||||||
"commander": "^2.8.1",
|
"commander": "^2.8.1",
|
||||||
"fs-extra": "^0.26.5",
|
"fs-extra": "^0.26.5",
|
||||||
"semver": "^5.0.1",
|
"klaw-sync": "^2.1.0",
|
||||||
"check-dependencies":"^1.0.1"
|
"semver": "^5.0.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=4.0.0"
|
"node": ">=4.0.0"
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
# MIT License
|
# MIT License
|
||||||
|
|
||||||
fs = require 'fs-extra'
|
fs = require 'fs-extra'
|
||||||
|
klawSync = require 'klaw-sync'
|
||||||
fpath = require 'path'
|
fpath = require 'path'
|
||||||
net = require 'net'
|
net = require 'net'
|
||||||
http = require 'http'
|
http = require 'http'
|
||||||
|
@ -215,8 +216,9 @@ generateConfig = (interfaceName, projName) ->
|
||||||
|
|
||||||
writeConfig = (config) ->
|
writeConfig = (config) ->
|
||||||
try
|
try
|
||||||
fs.writeFileSync '.re-natal', JSON.stringify config, null, 2
|
fs.writeFileSync './.re-natal', JSON.stringify config, null, 2
|
||||||
catch {message}
|
catch {message}
|
||||||
|
logErr message
|
||||||
logErr \
|
logErr \
|
||||||
if message.match /EACCES/i
|
if message.match /EACCES/i
|
||||||
'Invalid write permissions for creating .re-natal config file'
|
'Invalid write permissions for creating .re-natal config file'
|
||||||
|
@ -774,6 +776,31 @@ useComponent = (name, platform) ->
|
||||||
catch {message}
|
catch {message}
|
||||||
logErr message
|
logErr message
|
||||||
|
|
||||||
|
inferComponents = () ->
|
||||||
|
onlyUserCljs = (item) -> fpath.extname(item.path) == '.cljs' and
|
||||||
|
item.path.indexOf('/target/') < 0 # ignore target dir
|
||||||
|
jsRequire = /js\/require \"(.+)\"/g
|
||||||
|
files = klawSync process.cwd(),
|
||||||
|
nodir: true
|
||||||
|
filter: onlyUserCljs
|
||||||
|
filenames = files.map((o) -> o.path)
|
||||||
|
contents = filenames.map((path) -> fs.readFileSync(path, encoding: 'utf8'))
|
||||||
|
|
||||||
|
config = readConfig() # re-natal file
|
||||||
|
requires = new Set()
|
||||||
|
contents.forEach((text) ->
|
||||||
|
while match = jsRequire.exec(text)
|
||||||
|
requires.add(match[1]) if match[1].indexOf(config.imageDirs) < 0)
|
||||||
|
|
||||||
|
modules = new Set(config.modules)
|
||||||
|
difference = new Set(Array.from(requires).filter((m) -> !modules.has(m)))
|
||||||
|
if(difference.size isnt 0)
|
||||||
|
log "new component import found #{Array.from(difference)}"
|
||||||
|
config.modules = Array.from(requires)
|
||||||
|
writeConfig(config)
|
||||||
|
else
|
||||||
|
log "no new component was imported, defaulting to #{Array.from(modules)}"
|
||||||
|
|
||||||
cli._name = 're-natal'
|
cli._name = 're-natal'
|
||||||
cli.version pkgJson.version
|
cli.version pkgJson.version
|
||||||
|
|
||||||
|
@ -841,6 +868,11 @@ cli.command 'use-component <name> [<platform>]'
|
||||||
.action (name, platform) ->
|
.action (name, platform) ->
|
||||||
useComponent(name, platform)
|
useComponent(name, platform)
|
||||||
|
|
||||||
|
cli.command 'infer-components'
|
||||||
|
.description 'parses all cljs files in this project, extracts all (js/require) components calls and uses them to populate the re-natal file'
|
||||||
|
.action () ->
|
||||||
|
inferComponents()
|
||||||
|
|
||||||
cli.command 'enable-source-maps'
|
cli.command 'enable-source-maps'
|
||||||
.description 'patches RN packager to server *.map files from filesystem, so that chrome can download them.'
|
.description 'patches RN packager to server *.map files from filesystem, so that chrome can download them.'
|
||||||
.action () ->
|
.action () ->
|
||||||
|
|
Loading…
Reference in New Issue