From 8ff5fab4b3f2d436f4dd741188b2af1a2395411e Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Fri, 24 Sep 2021 17:42:12 +0200 Subject: [PATCH] gist fix --- apps/remix-ide/src/app/files/fileProvider.js | 48 +++++++++---------- .../file-explorer/src/lib/file-explorer.tsx | 6 +-- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/apps/remix-ide/src/app/files/fileProvider.js b/apps/remix-ide/src/app/files/fileProvider.js index 3b05ec0e9f..3a5f7754a8 100644 --- a/apps/remix-ide/src/app/files/fileProvider.js +++ b/apps/remix-ide/src/app/files/fileProvider.js @@ -91,6 +91,7 @@ class FileProvider { path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here var unprefixedpath = this.removePrefix(path) try { + console.log('getting', this.addSlash(unprefixedpath)) const content = await window.remixFileSystem.readFile(this.addSlash(unprefixedpath), 'utf8') if (cb) cb(null, content) return content @@ -207,35 +208,34 @@ class FileProvider { * @param {Function} visitFolder is a function called for each visited folders */ async _copyFolderToJsonInternal (path, visitFile, visitFolder) { - /* visitFile = visitFile || (() => { }) + visitFile = visitFile || (() => { }) visitFolder = visitFolder || (() => { }) - return new Promise((resolve, reject) => { - const json = {} - path = this.removePrefix(path) - if (window.remixFileSystem.exists(this.addSlash(path))) { - try { - const items = await window.remixFileSystem.readdir(this.addSlash(path)) - visitFolder({ path }) - if (items.length !== 0) { - for (const item of items) { - const file = {} - const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}` - if (await window.remixFileSystem.statExtended(curPath).isDirectory()) { - file.children = await this._copyFolderToJsonInternal(curPath, visitFile, visitFolder) - } else { - file.content = window.remixFileSystem.readFileSync(curPath, 'utf8') - visitFile({ path: curPath, content: file.content }) - } - json[curPath] = file + + const json = {} + path = this.removePrefix(path) + if (await window.remixFileSystem.exists(this.addSlash(path))) { + try { + const items = await window.remixFileSystem.readdir(this.addSlash(path)) + visitFolder({ path }) + if (items.length !== 0) { + for (const item of items) { + const file = {} + const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}` + if ((await window.remixFileSystem.statExtended(this.addSlash(curPath))).isDirectory()) { + file.children = await this._copyFolderToJsonInternal(curPath, visitFile, visitFolder) + } else { + file.content = await window.remixFileSystem.readFile(this.addSlash(curPath), 'utf8') + visitFile({ path: curPath, content: file.content }) } + json[curPath] = file } - } catch (e) { - console.log(e) - return reject(e) } + } catch (e) { + console.log(e) + throw new Error(e) } - return resolve(json) - }) */ + } + return json } /** diff --git a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx index 66d9886a48..531e0b7a0d 100644 --- a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx +++ b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx @@ -1060,13 +1060,13 @@ export const FileExplorer = (props: FileExplorerProps) => { export default FileExplorer async function packageFiles (filesProvider, directory, callback) { - const isFile = filesProvider.isFile(directory) + const isFile = await filesProvider.isFile(directory) const ret = {} - + console.log(isFile) if (isFile) { try { filesProvider.get(directory, (error, content) => { - if (error) throw new Error('An error ocurred while getting file content. ' + directory) + if (error) throw new Error('An error ocurred while getting file content. ' + error) if (/^\s+$/.test(content) || !content.length) { content = '// this line is added to create a gist. Empty file is not allowed.' }