Prep task provider for muiltiroot

This commit is contained in:
Matt Bierner
2017-07-14 16:39:54 -07:00
parent 06de342f80
commit b83d2ea286

View File

@@ -43,16 +43,17 @@ class TscTaskProvider implements vscode.TaskProvider {
}
public async provideTasks(token: vscode.CancellationToken): Promise<vscode.Task[]> {
const rootPath = vscode.workspace.rootPath;
if (!rootPath) {
const folders = vscode.workspace.workspaceFolders;
if (!folders || !folders.length) {
return [];
}
const command = await this.getCommand();
const rootPath = folders[0].uri;
const command = await this.getCommand(rootPath);
const projects = await this.getAllTsConfigs(token);
return projects.map(configFile => {
const configFileName = path.relative(rootPath, configFile);
const configFileName = path.relative(rootPath.fsPath, configFile);
const identifier: TypeScriptTaskDefinition = { type: 'typescript', tsconfig: configFileName };
const buildTask = new vscode.Task(identifier, `build ${configFileName}`, 'tsc', new vscode.ShellExecution(`${command} -p "${configFile}"`), '$tsc');
buildTask.group = vscode.TaskGroup.Build;
@@ -108,11 +109,11 @@ class TscTaskProvider implements vscode.TaskProvider {
return Array.from(await this.tsconfigProvider.getConfigsForWorkspace());
}
private async getCommand(): Promise<string> {
private async getCommand(root: vscode.Uri): Promise<string> {
const platform = process.platform;
if (platform === 'win32' && await exists(path.join(vscode.workspace.rootPath!, 'node_modules', '.bin', 'tsc.cmd'))) {
if (platform === 'win32' && await exists(path.join(root.fsPath, 'node_modules', '.bin', 'tsc.cmd'))) {
return path.join('.', 'node_modules', '.bin', 'tsc.cmd');
} else if ((platform === 'linux' || platform === 'darwin') && await exists(path.join(vscode.workspace.rootPath!, 'node_modules', '.bin', 'tsc'))) {
} else if ((platform === 'linux' || platform === 'darwin') && await exists(path.join(root.fsPath, 'node_modules', '.bin', 'tsc'))) {
return path.join('.', 'node_modules', '.bin', 'tsc');
} else {
return 'tsc';