Skip to content

Instantly share code, notes, and snippets.

@noyobo
Last active July 27, 2018 08:50
Show Gist options
  • Save noyobo/526e9efb39c4608441836026b5d9bbe4 to your computer and use it in GitHub Desktop.
Save noyobo/526e9efb39c4608441836026b5d9bbe4 to your computer and use it in GitHub Desktop.
open editor
// 打开默认编辑器
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