|
|
@ -1,10 +1,13 @@ |
|
|
|
import { PluginClient } from "@remixproject/plugin"; |
|
|
|
import {PluginClient} from '@remixproject/plugin' |
|
|
|
import { Profile } from "@remixproject/plugin-utils"; |
|
|
|
import {Profile} from '@remixproject/plugin-utils' |
|
|
|
import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron" |
|
|
|
import { |
|
|
|
import path from "path"; |
|
|
|
ElectronBasePlugin, |
|
|
|
import { rgPath } from "@vscode/ripgrep"; |
|
|
|
ElectronBasePluginClient, |
|
|
|
import byline from "byline"; |
|
|
|
} from '@remixproject/plugin-electron' |
|
|
|
import { spawn } from "child_process"; |
|
|
|
import path from 'path' |
|
|
|
|
|
|
|
import {rgPath} from '@vscode/ripgrep' |
|
|
|
|
|
|
|
import byline from 'byline' |
|
|
|
|
|
|
|
import {spawn} from 'child_process' |
|
|
|
|
|
|
|
|
|
|
|
const profile: Profile = { |
|
|
|
const profile: Profile = { |
|
|
|
name: 'ripgrep', |
|
|
|
name: 'ripgrep', |
|
|
@ -16,7 +19,6 @@ const convertPathToPosix = (pathName: string): string => { |
|
|
|
return pathName.split(path.sep).join(path.posix.sep) |
|
|
|
return pathName.split(path.sep).join(path.posix.sep) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class RipgrepPlugin extends ElectronBasePlugin { |
|
|
|
export class RipgrepPlugin extends ElectronBasePlugin { |
|
|
|
clients: RipgrepPluginClient[] = [] |
|
|
|
clients: RipgrepPluginClient[] = [] |
|
|
|
constructor() { |
|
|
|
constructor() { |
|
|
@ -29,7 +31,7 @@ const clientProfile: Profile = { |
|
|
|
name: 'ripgrep', |
|
|
|
name: 'ripgrep', |
|
|
|
displayName: 'ripgrep', |
|
|
|
displayName: 'ripgrep', |
|
|
|
description: 'ripgrep plugin', |
|
|
|
description: 'ripgrep plugin', |
|
|
|
methods: ['glob'] |
|
|
|
methods: ['glob'], |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export class RipgrepPluginClient extends ElectronBasePluginClient { |
|
|
|
export class RipgrepPluginClient extends ElectronBasePluginClient { |
|
|
@ -42,7 +44,6 @@ export class RipgrepPluginClient extends ElectronBasePluginClient { |
|
|
|
this.workingDir = path |
|
|
|
this.workingDir = path |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async glob(path: string, pattern: string, options?: any) { |
|
|
|
async glob(path: string, pattern: string, options?: any) { |
|
|
@ -50,9 +51,11 @@ export class RipgrepPluginClient extends ElectronBasePluginClient { |
|
|
|
console.log('path', path, this.workingDir) |
|
|
|
console.log('path', path, this.workingDir) |
|
|
|
|
|
|
|
|
|
|
|
return new Promise((c, e) => { |
|
|
|
return new Promise((c, e) => { |
|
|
|
|
|
|
|
|
|
|
|
// replace packed app path with unpacked app path for release on windows
|
|
|
|
// replace packed app path with unpacked app path for release on windows
|
|
|
|
const customRgPath = rgPath.replace('/app.asar/', '/app.asar.unpacked/') |
|
|
|
|
|
|
|
|
|
|
|
const customRgPath = rgPath.includes('app.asar.unpacked') |
|
|
|
|
|
|
|
? rgPath |
|
|
|
|
|
|
|
: rgPath.replace('app.asar', 'app.asar.unpacked') |
|
|
|
const rg = spawn(customRgPath, ['.', '-l', path]) |
|
|
|
const rg = spawn(customRgPath, ['.', '-l', path]) |
|
|
|
|
|
|
|
|
|
|
|
const resultrg: any[] = [] |
|
|
|
const resultrg: any[] = [] |
|
|
@ -60,7 +63,10 @@ export class RipgrepPluginClient extends ElectronBasePluginClient { |
|
|
|
const stream = byline(rg.stdout.setEncoding('utf8')) |
|
|
|
const stream = byline(rg.stdout.setEncoding('utf8')) |
|
|
|
stream.on('data', (rgresult: string) => { |
|
|
|
stream.on('data', (rgresult: string) => { |
|
|
|
console.log('rgresult', rgresult) |
|
|
|
console.log('rgresult', rgresult) |
|
|
|
let pathWithoutWorkingDir = rgresult.replace(convertPathToPosix(this.workingDir), '') |
|
|
|
let pathWithoutWorkingDir = rgresult.replace( |
|
|
|
|
|
|
|
convertPathToPosix(this.workingDir), |
|
|
|
|
|
|
|
'' |
|
|
|
|
|
|
|
) |
|
|
|
if (pathWithoutWorkingDir.endsWith('/')) { |
|
|
|
if (pathWithoutWorkingDir.endsWith('/')) { |
|
|
|
pathWithoutWorkingDir = pathWithoutWorkingDir.slice(0, -1) |
|
|
|
pathWithoutWorkingDir = pathWithoutWorkingDir.slice(0, -1) |
|
|
|
} |
|
|
|
} |
|
|
@ -71,7 +77,7 @@ export class RipgrepPluginClient extends ElectronBasePluginClient { |
|
|
|
pathWithoutWorkingDir = pathWithoutWorkingDir.slice(1) |
|
|
|
pathWithoutWorkingDir = pathWithoutWorkingDir.slice(1) |
|
|
|
} |
|
|
|
} |
|
|
|
resultrg.push({ |
|
|
|
resultrg.push({ |
|
|
|
path:convertPathToPosix(pathWithoutWorkingDir), |
|
|
|
path: convertPathToPosix(pathWithoutWorkingDir), |
|
|
|
isDirectory: false, |
|
|
|
isDirectory: false, |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -79,7 +85,6 @@ export class RipgrepPluginClient extends ElectronBasePluginClient { |
|
|
|
c(resultrg) |
|
|
|
c(resultrg) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fixPath(path: string): string { |
|
|
|
fixPath(path: string): string { |
|
|
|