mirror of
https://github.com/status-im/re-natal.git
synced 2025-02-21 08:48:09 +00:00
infer-components cli command added
klawSync dependency added for directory walking
This commit is contained in:
parent
d2d0e3e784
commit
5c40f8f118
@ -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'
|
||||||
@ -224,7 +225,7 @@ writeConfig = (config) ->
|
|||||||
message
|
message
|
||||||
|
|
||||||
verifyConfig = (config) ->
|
verifyConfig = (config) ->
|
||||||
if !config.platforms? || !config.modules? || !config.imageDirs? || !config.interface? || !config.envRoots?
|
if !config.modules? || !config.imageDirs? || !config.interface? || !config.envRoots?
|
||||||
throw new Error 're-natal project needs to be upgraded, please run: re-natal upgrade'
|
throw new Error 're-natal project needs to be upgraded, please run: re-natal upgrade'
|
||||||
|
|
||||||
config
|
config
|
||||||
@ -774,6 +775,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 +867,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…
x
Reference in New Issue
Block a user