Add support for installing azdata on Windows (#11387)

* Add support for installing azdata on Windows

* Don't run startup code when in test context since it blocks on UI input

* restart checks

* Disable calls for now
This commit is contained in:
Charles Gagnon
2020-07-18 18:15:52 -07:00
committed by GitHub
parent 5613a97fae
commit 6f9991e22b
7 changed files with 652 additions and 3 deletions

View File

@@ -0,0 +1,34 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as cp from 'child_process';
import * as loc from '../localizedConstants';
/**
* Wrapper error for when an unexpected exit code was recieved
*/
export class ExitCodeError extends Error {
constructor(public code: number) {
super(`Unexpected exit code ${code}`);
}
}
/**
*
* @param command The command to execute
* @param args Optional args to pass, every arg and arg value must be a separate item in the array
* @param outputChannel Channel used to display diagnostic information
*/
export async function executeCommand(command: string, args?: string[], outputChannel?: vscode.OutputChannel): Promise<string> {
return new Promise((resolve, reject) => {
outputChannel?.appendLine(loc.executingCommand(command, args ?? []));
const buffers: Buffer[] = [];
const child = cp.spawn(command, args);
child.stdout.on('data', (b: Buffer) => buffers.push(b));
child.on('error', reject);
child.on('exit', code => code ? reject(new ExitCodeError(code)) : resolve(Buffer.concat(buffers).toString('utf8').trim()));
});
}