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
bd15208c
Commit
bd15208c
authored
Jan 03, 2019
by
Omkara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use remix-plugin module API
parent
ce54f4b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
16 deletions
+117
-16
resolve.ts
remix-resolve/src/resolve.ts
+109
-7
test.ts
remix-resolve/tests/test.ts
+8
-9
No files found.
remix-resolve/src/resolve.ts
View file @
bd15208c
import
axios
from
'axios'
import
{
Api
,
PluginProfile
}
from
'remix-plugin'
import
{
Api
,
ModuleProfile
,
API
}
from
'remix-plugin'
export
interface
RemixResolve
extends
Api
{
type
:
'remix-resolve'
events
:
{}
resolve
:
any
resolve
:
Function
}
export
const
RemixResolveProfile
:
Plugin
Profile
<
RemixResolve
>
=
{
export
const
RemixResolveProfile
:
Module
Profile
<
RemixResolve
>
=
{
type
:
'remix-resolve'
,
methods
:
[
'resolve'
],
events
:
[],
notifications
:
[],
url
:
''
methods
:
[
'resolve'
]
}
...
...
@@ -33,6 +30,111 @@ interface Handler {
handle
(
match
:
any
):
any
;
}
export
class
RemixResolveApi
implements
API
<
RemixResolve
>
{
public
readonly
type
=
'remix-resolve'
previouslyHandled
:
PreviouslyHandledImports
constructor
()
{
this
.
previouslyHandled
=
{}
}
/**
* Handle an import statement based on github
* @params root The root of the github import statement
* @params filePath path of the file in github
*/
handleGithubCall
(
root
:
string
,
filePath
:
string
)
{
return
}
/**
* Handle an import statement based on http
* @params url The url of the import statement
* @params cleanURL
*/
handleHttp
(
url
:
string
,
cleanURL
:
string
)
{
return
}
/**
* Handle an import statement based on https
* @params url The url of the import statement
* @params cleanURL
*/
handleHttps
(
url
:
string
,
cleanURL
:
string
)
{
return
}
handleSwarm
(
url
:
string
,
cleanURL
:
string
)
{
return
}
/**
* Handle an import statement based on IPFS
* @params url The url of the IPFS import statement
*/
async
handleIPFS
(
url
:
string
)
{
// replace ipfs:// with /ipfs/
url
=
url
.
replace
(
/^ipfs:
\/\/?
/
,
'ipfs/'
)
try
{
const
req
=
'https://gateway.ipfs.io/'
+
url
// If you don't find greeter.sol on ipfs gateway use local
// const req = 'http://localhost:8080/' + url
const
response
=
await
axios
.
get
(
req
)
return
response
.
data
}
catch
(
e
)
{
throw
e
}
}
handleLocal
(
root
:
string
,
filePath
:
string
)
{
return
}
getHandlers
():
Handler
[]
{
return
[
{
type
:
'github'
,
match
:
(
url
)
=>
{
return
/^
(
https
?
:
\/\/)?(
www.
)?
github.com
\/([^/]
*
\/[^/]
*
)\/(
.*
)
/
.
exec
(
url
)
},
handle
:
(
match
)
=>
this
.
handleGithubCall
(
match
[
3
],
match
[
4
])
},
{
type
:
'http'
,
match
:
(
url
)
=>
{
return
/^
(
http
?
:
\/\/?(
.*
))
$/
.
exec
(
url
)
},
handle
:
(
match
)
=>
this
.
handleHttp
(
match
[
1
],
match
[
2
])
},
{
type
:
'https'
,
match
:
(
url
)
=>
{
return
/^
(
https
?
:
\/\/?(
.*
))
$/
.
exec
(
url
)
},
handle
:
(
match
)
=>
this
.
handleHttps
(
match
[
1
],
match
[
2
])
},
{
type
:
'swarm'
,
match
:
(
url
)
=>
{
return
/^
(
bzz-raw
?
:
\/\/?(
.*
))
$/
.
exec
(
url
)
},
handle
:
(
match
)
=>
this
.
handleSwarm
(
match
[
1
],
match
[
2
])
},
{
type
:
'ipfs'
,
match
:
(
url
)
=>
{
return
/^
(
ipfs:
\/\/?
.+
)
/
.
exec
(
url
)
},
handle
:
(
match
)
=>
this
.
handleIPFS
(
match
[
1
])
}
]
}
public
async
resolve
(
filePath
:
string
,
customHandlers
?:
Handler
[]):
Promise
<
Imported
>
{
var
imported
:
Imported
=
this
.
previouslyHandled
[
filePath
]
if
(
imported
)
{
return
imported
}
const
builtinHandlers
:
Handler
[]
=
this
.
getHandlers
()
const
handlers
:
Handler
[]
=
customHandlers
?
[...
builtinHandlers
,
...
customHandlers
]
:
[...
builtinHandlers
]
const
matchedHandler
=
handlers
.
filter
(
handler
=>
handler
.
match
(
filePath
))
const
handler
:
Handler
=
matchedHandler
[
0
]
const
match
=
handler
.
match
(
filePath
)
const
content
:
string
=
await
handler
.
handle
(
match
)
imported
=
{
content
,
cleanURL
:
filePath
,
type
:
handler
.
type
}
this
.
previouslyHandled
[
filePath
]
=
imported
return
imported
}
}
export
class
ImportResolver
{
previouslyHandled
:
PreviouslyHandledImports
constructor
()
{
...
...
remix-resolve/tests/test.ts
View file @
bd15208c
import
{
RemixResolve
,
ImportResolver
}
from
'../src'
import
{
RemixResolve
,
ImportResolver
,
RemixResolveApi
}
from
'../src'
import
*
as
fs
from
'fs'
import
*
as
path
from
'path'
import
*
as
assert
from
'assert'
...
...
@@ -10,10 +10,10 @@ const RemixResolveProfile: PluginProfile<RemixResolve> = {
url
:
''
}
interface
IAppManager
{
modules
:
{
},
plugins
:
{
'remix-resolve'
:
RemixResolve
}
modules
:
{
remixResolve
:
RemixResolve
},
plugins
:
{
}
}
describe
(
'testRunner'
,
()
=>
{
...
...
@@ -72,14 +72,13 @@ describe('testRunner', () => {
// AppManager tests
describe
(
'test with AppManager'
,
()
=>
{
let
app
:
AppManager
<
IAppManager
>
let
api
:
Plugin
<
RemixResolve
>
let
api
:
RemixResolveApi
before
(()
=>
{
api
=
new
Plugin
(
RemixResolveProfile
)
api
=
new
RemixResolveApi
(
)
app
=
new
AppManager
({
plugin
s
:
[{
json
:
RemixResolveProfile
,
api
}]
module
s
:
[{
json
:
RemixResolveProfile
,
api
}]
})
app
.
activate
(
api
.
type
)
})
it
(
'Plugin should be added to app'
,
()
=>
{
assert
.
equal
(
typeof
(
app
.
calls
[
api
.
type
].
resolve
),
'function'
)
...
...
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