Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
cbf92d6b
Commit
cbf92d6b
authored
Jun 27, 2018
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commandInterpreter
parent
718fe2a9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
165 additions
and
137 deletions
+165
-137
app.js
src/app.js
+75
-135
cmdInterpreter.js
src/lib/cmdInterpreter.js
+5
-2
cmdInterpreterAPI.js
src/lib/cmdInterpreterAPI.js
+85
-0
No files found.
src/app.js
View file @
cbf92d6b
This diff is collapsed.
Click to expand it.
src/lib/cmdInterpreter.js
View file @
cbf92d6b
...
...
@@ -2,9 +2,12 @@
var
remixLib
=
require
(
'remix-lib'
)
var
EventManager
=
remixLib
.
EventManager
var
CommandInterpreterAPI
=
require
(
'./cmdInterpreterAPI'
)
class
CmdInterpreter
{
constructor
()
{
constructor
(
api
)
{
this
.
event
=
new
EventManager
()
this
.
api
=
new
CommandInterpreterAPI
(
this
)
}
interpret
(
cmd
,
cb
)
{
if
(
!
cmd
)
return
false
...
...
@@ -12,7 +15,7 @@ class CmdInterpreter {
if
(
accept
)
{
var
param
=
accept
[
2
]
if
(
param
)
param
=
param
.
trim
()
this
.
event
.
trigger
(
accept
[
1
],
[
param
,
cb
]
)
this
.
api
[
accept
[
1
]](
param
,
cb
)
return
accept
[
1
]
}
return
null
...
...
src/lib/cmdInterpreterAPI.js
0 → 100644
View file @
cbf92d6b
'use strict'
var
async
=
require
(
'async'
)
var
remixLib
=
require
(
'remix-lib'
)
var
EventManager
=
remixLib
.
EventManager
var
executionContext
=
require
(
'../execution-context'
)
var
toolTip
=
require
(
'../app/ui/tooltip'
)
var
globalRegistry
=
require
(
'../global/registry'
)
class
CmdInterpreterAPI
{
constructor
(
cmdInterpreter
,
localRegistry
)
{
const
self
=
this
self
.
event
=
new
EventManager
()
self
.
_components
=
{}
self
.
_components
.
registry
=
localRegistry
||
globalRegistry
self
.
_components
.
cmdInterpreter
=
cmdInterpreter
self
.
_deps
=
{
app
:
self
.
_components
.
registry
.
get
(
'app'
).
api
,
editor
:
self
.
_components
.
registry
.
get
(
'editor'
).
api
}
}
debug
(
hash
,
cb
)
{
const
self
=
this
self
.
_deps
.
app
.
startdebugging
(
hash
)
if
(
cb
)
cb
()
}
loadgist
(
id
,
cb
)
{
const
self
=
this
self
.
_deps
.
app
.
loadFromGist
({
gist
:
id
})
if
(
cb
)
cb
()
}
loadurl
(
url
,
cb
)
{
const
self
=
this
self
.
_deps
.
app
.
importExternal
(
url
,
(
err
,
content
)
=>
{
if
(
err
)
{
toolTip
(
`Unable to load
${
url
}
from swarm:
${
err
}
`
)
if
(
cb
)
cb
(
err
)
}
else
{
try
{
content
=
JSON
.
parse
(
content
)
async
.
eachOfSeries
(
content
.
sources
,
(
value
,
file
,
callbackSource
)
=>
{
var
url
=
value
.
urls
[
0
]
// @TODO retrieve all other contents ?
self
.
_deps
.
app
.
importExternal
(
url
,
(
error
,
content
)
=>
{
if
(
error
)
{
toolTip
(
`Cannot retrieve the content of
${
url
}
:
${
error
}
`
)
}
callbackSource
()
})
},
(
error
)
=>
{
if
(
cb
)
cb
(
error
)
})
}
catch
(
e
)
{}
if
(
cb
)
cb
()
}
})
}
setproviderurl
(
url
,
cb
)
{
executionContext
.
setProviderFromEndpoint
(
url
,
'web3'
,
(
error
)
=>
{
if
(
error
)
toolTip
(
error
)
if
(
cb
)
cb
()
})
}
batch
(
url
,
cb
)
{
const
self
=
this
var
content
=
self
.
_deps
.
editor
.
currentContent
()
if
(
!
content
)
{
toolTip
(
'no content to execute'
)
if
(
cb
)
cb
()
return
}
var
split
=
content
.
split
(
'
\
n'
)
async
.
eachSeries
(
split
,
(
value
,
cb
)
=>
{
if
(
!
self
.
_components
.
cmdInterpreter
.
interpret
(
value
,
(
error
)
=>
{
error
?
cb
(
`Cannot run
${
value
}
. stopping`
)
:
cb
()
}))
{
cb
(
`Cannot interpret
${
value
}
. stopping`
)
}
},
(
error
)
=>
{
if
(
error
)
toolTip
(
error
)
if
(
cb
)
cb
()
})
}
}
module
.
exports
=
CmdInterpreterAPI
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment