From 19aecfd367cb4de1df5683fac5f177cf5116f095 Mon Sep 17 00:00:00 2001 From: Dirk Baeumer Date: Thu, 1 Jun 2017 11:12:01 +0200 Subject: [PATCH] Addresses #27672: Task Detection For Gulp --- extensions/grunt/src/main.ts | 19 +++++++++++++++---- extensions/gulp/src/main.ts | 20 ++++++++++++++++---- extensions/jake/src/main.ts | 18 +++++++++++++++--- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/extensions/grunt/src/main.ts b/extensions/grunt/src/main.ts index a90eff6c933..6af05a0d312 100644 --- a/extensions/grunt/src/main.ts +++ b/extensions/grunt/src/main.ts @@ -73,6 +73,14 @@ function exec(command: string, options: cp.ExecOptions): Promise<{ stdout: strin }); } +let _channel: vscode.OutputChannel; +function getOutputChannel(): vscode.OutputChannel { + if (!_channel) { + _channel = vscode.window.createOutputChannel('Grunt Auto Detection'); + } + return _channel; +} + async function getGruntTasks(): Promise { let workspaceRoot = vscode.workspace.rootPath; let emptyTasks: vscode.Task[] = []; @@ -95,12 +103,11 @@ async function getGruntTasks(): Promise { } let commandLine = `${command} --help --no-color`; - let channel = vscode.window.createOutputChannel('tasks'); try { let { stdout, stderr } = await exec(commandLine, { cwd: workspaceRoot }); if (stderr) { - channel.appendLine(stderr); - channel.show(true); + getOutputChannel().appendLine(stderr); + getOutputChannel().show(true); } let result: vscode.Task[] = []; if (stdout) { @@ -166,11 +173,15 @@ async function getGruntTasks(): Promise { } return result; } catch (err) { + let channel = getOutputChannel(); if (err.stderr) { channel.appendLine(err.stderr); - channel.show(true); + } + if (err.stdout) { + channel.appendLine(err.stdout); } channel.appendLine(localize('execFailed', 'Auto detecting Grunt failed with error: {0}', err.error ? err.error.toString() : 'unknown')); + channel.show(true); return emptyTasks; } } \ No newline at end of file diff --git a/extensions/gulp/src/main.ts b/extensions/gulp/src/main.ts index c75a8ce5d9c..1de05aa70d8 100644 --- a/extensions/gulp/src/main.ts +++ b/extensions/gulp/src/main.ts @@ -73,6 +73,14 @@ function exec(command: string, options: cp.ExecOptions): Promise<{ stdout: strin }); } +let _channel: vscode.OutputChannel; +function getOutputChannel(): vscode.OutputChannel { + if (!_channel) { + _channel = vscode.window.createOutputChannel('Gulp Auto Detection'); + } + return _channel; +} + async function getGulpTasks(): Promise { let workspaceRoot = vscode.workspace.rootPath; let emptyTasks: vscode.Task[] = []; @@ -98,12 +106,11 @@ async function getGulpTasks(): Promise { } let commandLine = `${gulpCommand} --tasks-simple --no-color`; - let channel = vscode.window.createOutputChannel('tasks'); try { let { stdout, stderr } = await exec(commandLine, { cwd: workspaceRoot }); - if (stderr) { - channel.appendLine(stderr); - channel.show(true); + if (stderr && stderr.length > 0) { + getOutputChannel().appendLine(stderr); + getOutputChannel().show(true); } let result: vscode.Task[] = []; if (stdout) { @@ -137,10 +144,15 @@ async function getGulpTasks(): Promise { } return result; } catch (err) { + let channel = getOutputChannel(); if (err.stderr) { channel.appendLine(err.stderr); } + if (err.stdout) { + channel.appendLine(err.stdout); + } channel.appendLine(localize('execFailed', 'Auto detecting gulp failed with error: {0}', err.error ? err.error.toString() : 'unknown')); + channel.show(true); return emptyTasks; } } \ No newline at end of file diff --git a/extensions/jake/src/main.ts b/extensions/jake/src/main.ts index 25d93a29780..eb87180ca78 100644 --- a/extensions/jake/src/main.ts +++ b/extensions/jake/src/main.ts @@ -73,6 +73,14 @@ function exec(command: string, options: cp.ExecOptions): Promise<{ stdout: strin }); } +let _channel: vscode.OutputChannel; +function getOutputChannel(): vscode.OutputChannel { + if (!_channel) { + _channel = vscode.window.createOutputChannel('Jake Auto Detection'); + } + return _channel; +} + async function getJakeTasks(): Promise { let workspaceRoot = vscode.workspace.rootPath; let emptyTasks: vscode.Task[] = []; @@ -98,12 +106,11 @@ async function getJakeTasks(): Promise { } let commandLine = `${jakeCommand} --tasks`; - let channel = vscode.window.createOutputChannel('tasks'); try { let { stdout, stderr } = await exec(commandLine, { cwd: workspaceRoot }); if (stderr) { - channel.appendLine(stderr); - channel.show(true); + getOutputChannel().appendLine(stderr); + getOutputChannel().show(true); } let result: vscode.Task[] = []; if (stdout) { @@ -142,10 +149,15 @@ async function getJakeTasks(): Promise { } return result; } catch (err) { + let channel = getOutputChannel(); if (err.stderr) { channel.appendLine(err.stderr); } + if (err.stdout) { + channel.appendLine(err.stdout); + } channel.appendLine(localize('execFailed', 'Auto detecting Jake failed with error: {0}', err.error ? err.error.toString() : 'unknown')); + channel.show(true); return emptyTasks; } } \ No newline at end of file