Last active
July 27, 2018 08:50
-
-
Save noyobo/526e9efb39c4608441836026b5d9bbe4 to your computer and use it in GitHub Desktop.
open editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 打开默认编辑器 | |
const openEditor = (cwd, editor, basePath) => { | |
let editorPath = basePath; | |
if (editor === 'Sublime') { | |
if (isMac) { | |
editorPath = join(basePath, '/Contents/SharedSupport/bin/subl'); | |
} | |
if (isWin) { | |
editorPath = | |
basePath.indexOf('.exe') === -1 | |
? join(basePath, 'sublime_text.exe') | |
: basePath; | |
} | |
} else if (editor === 'VScode') { | |
if (isMac) { | |
editorPath = join(basePath, '/Contents/Resources/app/bin/code'); | |
} | |
if (isWin) { | |
editorPath = | |
basePath.indexOf('.exe') === -1 ? join(basePath, 'Code.exe') : basePath; | |
} | |
} else if (editor === 'WebStorm') { | |
if (isMac) { | |
editorPath = join(basePath, '/Contents/MacOS/webstorm'); | |
} | |
} | |
let term; | |
return new Promise((resolve) => { | |
try { | |
if (editor === 'WebStorm') { | |
term = exec(`${editorPath} ${cwd}`, { cwd }); | |
} else { | |
term = spawn(editorPath, ['./'], { cwd }); | |
} | |
term.on('exit', () => { | |
console.log('exit ediotr'); | |
resolve({ success: true }); | |
}); | |
} catch (e) { | |
resolve({ success: false }); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment