diff --git a/apps/remix-ide/src/app/files/fileProvider.js b/apps/remix-ide/src/app/files/fileProvider.js index adc5840dfd..70dbdc7aca 100644 --- a/apps/remix-ide/src/app/files/fileProvider.js +++ b/apps/remix-ide/src/app/files/fileProvider.js @@ -196,11 +196,11 @@ class FileProvider { } /** - * copy the folder recursively + * copy the folder recursively (internal use) * @param {string} path is the folder to be copied over * @param {string} destination is the destination folder */ - copyFolderToJson (path) { + _copyFolderToJsonInternal (path) { return new Promise((resolve, reject) => { const json = {} path = this.removePrefix(path) @@ -212,7 +212,7 @@ class FileProvider { const file = {} const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}` if (window.remixFileSystem.statSync(curPath).isDirectory()) { - file.children = await this.copyFolderToJson(curPath) + file.children = await this._copyFolderToJsonInternal(curPath) } else { file.content = window.remixFileSystem.readFileSync(curPath, 'utf8') } @@ -228,6 +228,15 @@ class FileProvider { }) } + /** + * copy the folder recursively + * @param {string} path is the folder to be copied over + * @param {string} destination is the destination folder + */ + copyFolderToJson (path) { + return this._copyFolderToJsonInternal(path) + } + removeFile (path) { path = this.removePrefix(path) if (window.remixFileSystem.existsSync(path) && !window.remixFileSystem.statSync(path).isDirectory()) { diff --git a/apps/remix-ide/src/app/files/workspaceFileProvider.js b/apps/remix-ide/src/app/files/workspaceFileProvider.js index 8522f5ff4c..91f3227fbd 100644 --- a/apps/remix-ide/src/app/files/workspaceFileProvider.js +++ b/apps/remix-ide/src/app/files/workspaceFileProvider.js @@ -48,6 +48,13 @@ class WorkspaceFileProvider extends FileProvider { }) } + async copyFolderToJson (directory) { + let json = await super._copyFolderToJsonInternal(directory) + const regex = new RegExp(`.workspaces/${this.workspace}/`, 'g'); + json = JSON.stringify(json).replace(regex, '') + return JSON.parse(json) + } + _normalizePath (path) { if (!this.workspace) throw new Error('No workspace has been opened.') return path.replace(this.workspacesPath + '/' + this.workspace + '/', '')