Skip to content

Commit 98fcf34

Browse files
committed
Add windows support
1 parent c88c176 commit 98fcf34

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

code-replacer-0.0.1.vsix

61 Bytes
Binary file not shown.

extension.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const vscode = require('vscode')
33
const path = require('path')
44
const findFiles = require('./findFiles')
55
const fs = require('fs')
6-
const { getProperties, getInput, getQuickPick } = require('./util')
6+
const { getProperties, getInput, getQuickPick, replaceAll } = require('./util')
77
const { UIString } = require('./constant')
88
// fetch setting value from vscode's settings
99
// See package.json's contributes's configuration
@@ -106,13 +106,16 @@ const activate = (context) => {
106106
const currentlyOpenTabfilePath =
107107
vscode.window.activeTextEditor.document.fileName
108108
const currentlyOpenTabfileName = path.basename(currentlyOpenTabfilePath)
109-
const pathSep = process.platform === 'win32' ? `${path.sep}${path.sep}` : `${path.sep}`
110-
const codeReplacerPath = `${__dirname}${pathSep}node_modules${pathSep}code-replacer${pathSep}dist`
111-
const binPath = path.resolve(`${codeReplacerPath}${pathSep}index.js`)
112-
const envPath = path.resolve(`${codeReplacerPath}${pathSep}${'.env'}`)
113-
const usageLogPath = path.resolve(
114-
`${codeReplacerPath}${pathSep}usageLog.json`
115-
)
109+
const pathSep =
110+
process.platform === 'win32' ? path.sep + path.sep : path.sep
111+
const dirName =
112+
process.platform === 'win32'
113+
? replaceAll(__dirname, '\\', '\\\\')
114+
: __dirname
115+
const codeReplacerPath = `${dirName}${pathSep}node_modules${pathSep}code-replacer${pathSep}dist`
116+
const binPath = `${codeReplacerPath}${pathSep}index.js`
117+
const envPath = `${codeReplacerPath}${pathSep}${'.env'}`
118+
const usageLogPath = `${codeReplacerPath}${pathSep}usageLog.json`
116119
const workspaceName = vscode.workspace.name
117120
const workspacePath = vscode.workspace.rootPath
118121
const csvFiles = await findFiles({

util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,9 @@ module.exports = {
3939
resolve(selection)
4040
})
4141
})
42+
},
43+
44+
replaceAll (str, searchStr, replaceStr) {
45+
return str.split(searchStr).join(replaceStr)
4246
}
4347
}

0 commit comments

Comments
 (0)