make sure workspace provider is removing the uneeded part of the paths

pull/982/head
yann300 4 years ago
parent f93f459cdb
commit 36de70d3f7
  1. 15
      apps/remix-ide/src/app/files/fileProvider.js
  2. 7
      apps/remix-ide/src/app/files/workspaceFileProvider.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} path is the folder to be copied over
* @param {string} destination is the destination folder * @param {string} destination is the destination folder
*/ */
copyFolderToJson (path) { _copyFolderToJsonInternal (path) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const json = {} const json = {}
path = this.removePrefix(path) path = this.removePrefix(path)
@ -212,7 +212,7 @@ class FileProvider {
const file = {} const file = {}
const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}` const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}`
if (window.remixFileSystem.statSync(curPath).isDirectory()) { if (window.remixFileSystem.statSync(curPath).isDirectory()) {
file.children = await this.copyFolderToJson(curPath) file.children = await this._copyFolderToJsonInternal(curPath)
} else { } else {
file.content = window.remixFileSystem.readFileSync(curPath, 'utf8') 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) { removeFile (path) {
path = this.removePrefix(path) path = this.removePrefix(path)
if (window.remixFileSystem.existsSync(path) && !window.remixFileSystem.statSync(path).isDirectory()) { if (window.remixFileSystem.existsSync(path) && !window.remixFileSystem.statSync(path).isDirectory()) {

@ -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) { _normalizePath (path) {
if (!this.workspace) throw new Error('No workspace has been opened.') if (!this.workspace) throw new Error('No workspace has been opened.')
return path.replace(this.workspacesPath + '/' + this.workspace + '/', '') return path.replace(this.workspacesPath + '/' + this.workspace + '/', '')

Loading…
Cancel
Save