Commit 0354e21c authored by ioedeveloper's avatar ioedeveloper

Trigger fileAdded, fileChanged and fileRemoved event

parent ec9c4748
...@@ -86,8 +86,9 @@ export class RemixdClient extends PluginClient { ...@@ -86,8 +86,9 @@ export class RemixdClient extends PluginClient {
if (this.readOnly) reject('Cannot write file: read-only mode selected') if (this.readOnly) reject('Cannot write file: read-only mode selected')
const isFolder = args.path.endsWith('/') const isFolder = args.path.endsWith('/')
const path = utils.absolutePath(args.path, this.currentSharedFolder) const path = utils.absolutePath(args.path, this.currentSharedFolder)
const exists = fs.existsSync(path)
if (fs.existsSync(path) && !isRealPath(path)) reject() if (exists && !isRealPath(path)) reject()
if (args.content === 'undefined') { // no !!!!! if (args.content === 'undefined') { // no !!!!!
console.log('trying to write "undefined" ! stopping.') console.log('trying to write "undefined" ! stopping.')
reject('trying to write "undefined" ! stopping.') reject('trying to write "undefined" ! stopping.')
...@@ -95,11 +96,12 @@ export class RemixdClient extends PluginClient { ...@@ -95,11 +96,12 @@ export class RemixdClient extends PluginClient {
this.trackDownStreamUpdate[path] = path this.trackDownStreamUpdate[path] = path
if (isFolder) { if (isFolder) {
fs.mkdirp(path).then(() => { fs.mkdirp(path).then(() => {
const splitPath = path.split('/') let splitPath = args.path.split('/')
splitPath.pop()
const parentDir = splitPath.join('/') + '/'
this.emit('folderAdded', parentDir) splitPath = splitPath.filter(dir => dir)
const dir = '/' + splitPath.join('/')
this.emit('folderAdded', dir)
resolve() resolve()
}).catch((e: Error) => reject(e)) }).catch((e: Error) => reject(e))
} else { } else {
...@@ -112,6 +114,11 @@ export class RemixdClient extends PluginClient { ...@@ -112,6 +114,11 @@ export class RemixdClient extends PluginClient {
resolve() resolve()
}) })
}).catch((e: Error) => reject(e)) }).catch((e: Error) => reject(e))
if (!exists) {
this.emit('fileAdded', args.path)
} else {
this.emit('fileChanged', args.path)
}
} }
}) })
} catch (error) { } catch (error) {
...@@ -157,6 +164,7 @@ export class RemixdClient extends PluginClient { ...@@ -157,6 +164,7 @@ export class RemixdClient extends PluginClient {
console.log(error) console.log(error)
reject('Failed to remove file/directory: ' + error) reject('Failed to remove file/directory: ' + error)
} }
this.emit('fileRemoved', args.path)
resolve(true) resolve(true)
}) })
}) })
......
...@@ -14,9 +14,7 @@ const pathModule = require('path') ...@@ -14,9 +14,7 @@ const pathModule = require('path')
*/ */
function absolutePath (path: string, sharedFolder:string): string { function absolutePath (path: string, sharedFolder:string): string {
path = normalizePath(path) path = normalizePath(path)
const exists = fs.existsSync('/' + path) if (path.indexOf(sharedFolder) !== 0) {
if (!exists && path.indexOf(sharedFolder) !== 0) {
path = pathModule.resolve(sharedFolder, path) path = pathModule.resolve(sharedFolder, path)
} }
return path return path
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment