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
8829b480
Commit
8829b480
authored
Jan 03, 2019
by
Omkara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
access module through AppManager
parent
bd15208c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
128 deletions
+17
-128
resolve.ts
remix-resolve/src/resolve.ts
+1
-103
test.ts
remix-resolve/tests/test.ts
+16
-25
No files found.
remix-resolve/src/resolve.ts
View file @
8829b480
...
@@ -33,7 +33,7 @@ interface Handler {
...
@@ -33,7 +33,7 @@ interface Handler {
export
class
RemixResolveApi
implements
API
<
RemixResolve
>
{
export
class
RemixResolveApi
implements
API
<
RemixResolve
>
{
public
readonly
type
=
'remix-resolve'
public
readonly
type
=
'remix-resolve'
previouslyHandled
:
PreviouslyHandledImports
pr
ivate
pr
eviouslyHandled
:
PreviouslyHandledImports
constructor
()
{
constructor
()
{
this
.
previouslyHandled
=
{}
this
.
previouslyHandled
=
{}
}
}
...
@@ -134,105 +134,3 @@ export class RemixResolveApi implements API<RemixResolve> {
...
@@ -134,105 +134,3 @@ export class RemixResolveApi implements API<RemixResolve> {
return
imported
return
imported
}
}
}
}
export
class
ImportResolver
{
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
])
}
]
}
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
}
}
remix-resolve/tests/test.ts
View file @
8829b480
import
{
RemixResolve
,
ImportResolver
,
RemixResolveApi
}
from
'../src'
import
{
RemixResolve
,
RemixResolveApi
}
from
'../src'
import
*
as
fs
from
'fs'
import
*
as
fs
from
'fs'
import
*
as
path
from
'path'
import
*
as
path
from
'path'
import
*
as
assert
from
'assert'
import
*
as
assert
from
'assert'
import
{
Plugin
,
AppManager
,
PluginProfile
}
from
'remix-plugin'
import
{
AppManager
,
PluginProfile
}
from
'remix-plugin'
const
RemixResolveProfile
:
PluginProfile
<
RemixResolve
>
=
{
const
RemixResolveProfile
:
PluginProfile
<
RemixResolve
>
=
{
type
:
'remix-resolve'
,
type
:
'remix-resolve'
,
...
@@ -19,11 +19,19 @@ interface IAppManager {
...
@@ -19,11 +19,19 @@ interface IAppManager {
describe
(
'testRunner'
,
()
=>
{
describe
(
'testRunner'
,
()
=>
{
describe
(
'#resolve'
,
()
=>
{
describe
(
'#resolve'
,
()
=>
{
describe
(
'test example_1 [local imports]]'
,
()
=>
{
describe
(
'test example_1 [local imports]]'
,
()
=>
{
// AppManager tests
describe
(
'test with AppManager'
,
()
=>
{
let
app
:
AppManager
<
IAppManager
>
let
api
:
RemixResolveApi
const
fileName
=
'../remix-resolve/tests/example_1/greeter.sol'
const
fileName
=
'../remix-resolve/tests/example_1/greeter.sol'
let
results
=
{}
let
results
:
object
=
{}
before
(
done
=>
{
before
(
done
=>
{
let
resolver
:
ImportResolver
=
new
ImportResolver
()
api
=
new
RemixResolveApi
()
app
=
new
AppManager
({
modules
:
[{
json
:
RemixResolveProfile
,
api
}]
})
function
handleLocal
(
pathString
:
string
,
filePath
:
string
)
{
function
handleLocal
(
pathString
:
string
,
filePath
:
string
)
{
// if no relative/absolute path given then search in node_modules folder
// if no relative/absolute path given then search in node_modules folder
...
@@ -44,7 +52,8 @@ describe('testRunner', () => {
...
@@ -44,7 +52,8 @@ describe('testRunner', () => {
handle
:
(
match
:
Array
<
string
>
)
=>
{
return
handleLocal
(
match
[
2
],
match
[
3
])
}
handle
:
(
match
:
Array
<
string
>
)
=>
{
return
handleLocal
(
match
[
2
],
match
[
3
])
}
}
}
]
]
resolver
.
resolve
(
fileName
,
localFSHandler
)
//app.calls[api.type].resolve(fileName, localFSHandler)
api
.
resolve
(
fileName
,
localFSHandler
)
.
then
(
sources
=>
{
.
then
(
sources
=>
{
results
=
sources
results
=
sources
done
()
done
()
...
@@ -53,9 +62,8 @@ describe('testRunner', () => {
...
@@ -53,9 +62,8 @@ describe('testRunner', () => {
throw
e
throw
e
})
})
})
})
it
(
'Plugin should be added to app'
,
()
=>
{
it
(
'should have 3 items'
,
()
=>
{
assert
.
equal
(
typeof
(
app
.
calls
[
api
.
type
].
resolve
),
'function'
)
assert
.
equal
(
Object
.
keys
(
results
).
length
,
3
)
})
})
it
(
'should returns contract content of given local path'
,
()
=>
{
it
(
'should returns contract content of given local path'
,
()
=>
{
...
@@ -66,23 +74,6 @@ describe('testRunner', () => {
...
@@ -66,23 +74,6 @@ describe('testRunner', () => {
}
}
assert
.
deepEqual
(
results
,
expt
)
assert
.
deepEqual
(
results
,
expt
)
})
})
// test IPFShandle
// AppManager tests
describe
(
'test with AppManager'
,
()
=>
{
let
app
:
AppManager
<
IAppManager
>
let
api
:
RemixResolveApi
before
(()
=>
{
api
=
new
RemixResolveApi
()
app
=
new
AppManager
({
modules
:
[{
json
:
RemixResolveProfile
,
api
}]
})
})
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