parent
91c237ded3
commit
a36256382c
@ -1,74 +0,0 @@ |
|||||||
'use strict' |
|
||||||
var modalDialogCustom = require('../app/ui/modal-dialog-custom') |
|
||||||
var request = require('request') |
|
||||||
|
|
||||||
// Allowing window to be overriden for testing
|
|
||||||
function GistHandler (_window) { |
|
||||||
if (_window !== undefined) { |
|
||||||
modalDialogCustom = _window |
|
||||||
} |
|
||||||
|
|
||||||
this.handleLoad = function (params, cb) { |
|
||||||
if (!cb) cb = () => {} |
|
||||||
var loadingFromGist = false |
|
||||||
var gistId |
|
||||||
if (params.gist === '') { |
|
||||||
loadingFromGist = true |
|
||||||
modalDialogCustom.prompt('Load a Gist', 'Enter the ID of the Gist or URL you would like to load.', null, (target) => { |
|
||||||
if (target !== '') { |
|
||||||
gistId = getGistId(target) |
|
||||||
if (gistId) { |
|
||||||
cb(gistId) |
|
||||||
} else { |
|
||||||
modalDialogCustom.alert('Gist load error', 'Error while loading gist. Please provide a valid Gist ID or URL.') |
|
||||||
} |
|
||||||
} |
|
||||||
}) |
|
||||||
return loadingFromGist |
|
||||||
} else { |
|
||||||
gistId = params.gist |
|
||||||
loadingFromGist = !!gistId |
|
||||||
} |
|
||||||
if (loadingFromGist) { |
|
||||||
cb(gistId) |
|
||||||
} |
|
||||||
return loadingFromGist |
|
||||||
} |
|
||||||
|
|
||||||
function getGistId (str) { |
|
||||||
var idr = /[0-9A-Fa-f]{8,}/ |
|
||||||
var match = idr.exec(str) |
|
||||||
return match ? match[0] : null |
|
||||||
} |
|
||||||
|
|
||||||
this.loadFromGist = (params, fileManager) => { |
|
||||||
const self = this |
|
||||||
return self.handleLoad(params, function (gistId) { |
|
||||||
request.get({ |
|
||||||
url: `https://api.github.com/gists/${gistId}`, |
|
||||||
json: true |
|
||||||
}, async (error, response, data = {}) => { |
|
||||||
if (error || !data.files) { |
|
||||||
modalDialogCustom.alert('Gist load error', error || data.message) |
|
||||||
return |
|
||||||
} |
|
||||||
const obj = {} |
|
||||||
Object.keys(data.files).forEach((element) => { |
|
||||||
const path = element.replace(/\.\.\./g, '/') |
|
||||||
|
|
||||||
obj['/' + 'gist-' + gistId + '/' + path] = data.files[element] |
|
||||||
}) |
|
||||||
fileManager.setBatchFiles(obj, 'workspace', true, (errorLoadingFile) => { |
|
||||||
if (!errorLoadingFile) { |
|
||||||
const provider = fileManager.getProvider('workspace') |
|
||||||
provider.lastLoadedGistId = gistId |
|
||||||
} else { |
|
||||||
modalDialogCustom.alert('Gist load error', errorLoadingFile.message || errorLoadingFile) |
|
||||||
} |
|
||||||
}) |
|
||||||
}) |
|
||||||
}) |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
module.exports = GistHandler |
|
@ -1,16 +0,0 @@ |
|||||||
'use strict' |
|
||||||
|
|
||||||
var test = require('tape') |
|
||||||
|
|
||||||
var Compiler = require('@remix-project/remix-solidity').Compiler |
|
||||||
|
|
||||||
test('compiler.compile smoke', function (t) { |
|
||||||
t.plan(1) |
|
||||||
|
|
||||||
var noop = function () {} |
|
||||||
var fakeImport = function (url, cb) { cb('Not implemented') } |
|
||||||
var compiler = new Compiler(fakeImport) |
|
||||||
compiler.compileJSON = noop |
|
||||||
compiler.compile({ 'test': '' }, 'test') |
|
||||||
t.ok(compiler) |
|
||||||
}) |
|
@ -1,52 +0,0 @@ |
|||||||
'use strict' |
|
||||||
var modalDialogCustom |
|
||||||
if (typeof window !== 'undefined') { |
|
||||||
modalDialogCustom = require('../app/ui/modal-dialog-custom') |
|
||||||
} |
|
||||||
// ^ this class can be load in a non browser context when running node unit testing.
|
|
||||||
// should not load UI in that case
|
|
||||||
|
|
||||||
// Allowing window to be overriden for testing
|
|
||||||
function GistHandler (_window) { |
|
||||||
if (_window !== undefined) { |
|
||||||
modalDialogCustom = _window |
|
||||||
} |
|
||||||
|
|
||||||
this.handleLoad = function (params, cb) { |
|
||||||
if (!cb) cb = () => {} |
|
||||||
var loadingFromGist = false |
|
||||||
var gistId |
|
||||||
if (params['gist'] === '') { |
|
||||||
loadingFromGist = true |
|
||||||
modalDialogCustom.prompt( |
|
||||||
'Load a Gist', |
|
||||||
'Enter the URL or ID of the Gist you would like to load.', |
|
||||||
null, |
|
||||||
target => { |
|
||||||
if (target !== '') { |
|
||||||
gistId = getGistId(target) |
|
||||||
if (gistId) { |
|
||||||
cb(gistId) |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
) |
|
||||||
return loadingFromGist |
|
||||||
} else { |
|
||||||
gistId = params['gist'] |
|
||||||
loadingFromGist = !!gistId |
|
||||||
} |
|
||||||
if (loadingFromGist) { |
|
||||||
cb(gistId) |
|
||||||
} |
|
||||||
return loadingFromGist |
|
||||||
} |
|
||||||
|
|
||||||
function getGistId (str) { |
|
||||||
var idr = /[0-9A-Fa-f]{8,}/ |
|
||||||
var match = idr.exec(str) |
|
||||||
return match ? match[0] : null |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
module.exports = GistHandler |
|
@ -1,5 +0,0 @@ |
|||||||
'use strict' |
|
||||||
|
|
||||||
require('./compiler-test') |
|
||||||
require('./gist-handler-test') |
|
||||||
require('./query-params-test') |
|
@ -1,23 +0,0 @@ |
|||||||
'use strict' |
|
||||||
|
|
||||||
var test = require('tape') |
|
||||||
|
|
||||||
var QueryParams = require('../src/lib/query-params') |
|
||||||
|
|
||||||
test('queryParams.get', function (t) { |
|
||||||
t.plan(2) |
|
||||||
|
|
||||||
var fakeWindow = {location: {hash: '#wat=sup&foo=bar', search: ''}} |
|
||||||
var params = new QueryParams(fakeWindow).get() |
|
||||||
t.equal(params.wat, 'sup') |
|
||||||
t.equal(params.foo, 'bar') |
|
||||||
}) |
|
||||||
|
|
||||||
test('queryParams.update', function (t) { |
|
||||||
t.plan(1) |
|
||||||
|
|
||||||
var fakeWindow = {location: {hash: '#wat=sup', search: ''}} |
|
||||||
var qp = new QueryParams(fakeWindow) |
|
||||||
qp.update({foo: 'bar'}) |
|
||||||
t.equal(fakeWindow.location.hash, '#wat=sup&foo=bar') |
|
||||||
}) |
|
@ -0,0 +1,85 @@ |
|||||||
|
'use strict' |
||||||
|
import { Plugin } from '@remixproject/engine' |
||||||
|
|
||||||
|
interface StringByString { |
||||||
|
[key: string]: string; |
||||||
|
} |
||||||
|
|
||||||
|
const profile = { |
||||||
|
name: 'gistHandler', |
||||||
|
methods: ['load'], |
||||||
|
events: [], |
||||||
|
version: '0.0.1' |
||||||
|
} |
||||||
|
|
||||||
|
export class GistHandler extends Plugin { |
||||||
|
|
||||||
|
constructor () { |
||||||
|
super(profile) |
||||||
|
} |
||||||
|
|
||||||
|
async handleLoad (gistId: String | null, cb: Function) { |
||||||
|
if (!cb) cb = () => {} |
||||||
|
|
||||||
|
var loadingFromGist = false |
||||||
|
if (!gistId) { |
||||||
|
loadingFromGist = true |
||||||
|
let value: string = await this.call('modal', 'prompt-value', 'Load a Gist', 'Enter the ID of the Gist or URL you would like to load.', null) |
||||||
|
if (value !== '') { |
||||||
|
gistId = getGistId(value) |
||||||
|
if (gistId) { |
||||||
|
cb(gistId) |
||||||
|
} else { |
||||||
|
await this.call('modal', 'alert', 'Gist load error', 'Error while loading gist. Please provide a valid Gist ID or URL.') |
||||||
|
} |
||||||
|
} else { |
||||||
|
await this.call('modal', 'alert', 'Gist load error', 'Error while loading gist. Id cannot be empty.')
|
||||||
|
} |
||||||
|
return loadingFromGist |
||||||
|
} else { |
||||||
|
loadingFromGist = !!gistId |
||||||
|
} |
||||||
|
if (loadingFromGist) { |
||||||
|
cb(gistId) |
||||||
|
} |
||||||
|
return loadingFromGist |
||||||
|
}
|
||||||
|
|
||||||
|
load (gistId: String | null) { |
||||||
|
const self = this |
||||||
|
return self.handleLoad(gistId, async (gistId: String | null) => { |
||||||
|
let data: any |
||||||
|
try { |
||||||
|
data = (await fetch(`https://api.github.com/gists/${gistId}`)).json() as any |
||||||
|
if (!data.files) { |
||||||
|
this.call('model', 'alert', 'Gist load error', data.message) |
||||||
|
return |
||||||
|
} |
||||||
|
} catch (e: any) { |
||||||
|
this.call('model', 'alert', 'Gist load error', e.message) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
const obj: StringByString = {} |
||||||
|
Object.keys(data.files).forEach((element) => { |
||||||
|
const path = element.replace(/\.\.\./g, '/') |
||||||
|
obj['/' + 'gist-' + gistId + '/' + path] = data.files[element] |
||||||
|
}) |
||||||
|
this.call('fileManager', 'setBatchFiles', obj, 'workspace', true, async (errorSavingFiles: any) => { |
||||||
|
if (!errorSavingFiles) { |
||||||
|
const provider = await this.call('fileManager', 'getProviderByName', 'workspace') |
||||||
|
} else { |
||||||
|
this.call('model', 'alert', 'Gist load error', errorSavingFiles.message || errorSavingFiles) |
||||||
|
} |
||||||
|
}) |
||||||
|
|
||||||
|
|
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
const getGistId = (str) => { |
||||||
|
var idr = /[0-9A-Fa-f]{8,}/ |
||||||
|
var match = idr.exec(str) |
||||||
|
return match ? match[0] : null |
||||||
|
} |
Loading…
Reference in new issue