parent
b0006ef261
commit
2d4617876b
1 changed files with 69 additions and 28 deletions
|
@ -66,6 +66,19 @@ function showError() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function findJakeCommand(rootPath: string): Promise<string> {
|
||||||
|
let jakeCommand: string;
|
||||||
|
let platform = process.platform;
|
||||||
|
if (platform === 'win32' && await exists(path.join(rootPath!, 'node_modules', '.bin', 'jake.cmd'))) {
|
||||||
|
jakeCommand = path.join('.', 'node_modules', '.bin', 'jake.cmd');
|
||||||
|
} else if ((platform === 'linux' || platform === 'darwin') && await exists(path.join(rootPath!, 'node_modules', '.bin', 'jake'))) {
|
||||||
|
jakeCommand = path.join('.', 'node_modules', '.bin', 'jake');
|
||||||
|
} else {
|
||||||
|
jakeCommand = 'jake';
|
||||||
|
}
|
||||||
|
return jakeCommand;
|
||||||
|
}
|
||||||
|
|
||||||
interface JakeTaskDefinition extends vscode.TaskDefinition {
|
interface JakeTaskDefinition extends vscode.TaskDefinition {
|
||||||
task: string;
|
task: string;
|
||||||
file?: string;
|
file?: string;
|
||||||
|
@ -76,7 +89,9 @@ class FolderDetector {
|
||||||
private fileWatcher: vscode.FileSystemWatcher | undefined;
|
private fileWatcher: vscode.FileSystemWatcher | undefined;
|
||||||
private promise: Thenable<vscode.Task[]> | undefined;
|
private promise: Thenable<vscode.Task[]> | undefined;
|
||||||
|
|
||||||
constructor(private _workspaceFolder: vscode.WorkspaceFolder) {
|
constructor(
|
||||||
|
private _workspaceFolder: vscode.WorkspaceFolder,
|
||||||
|
private _jakeCommand: Promise<string>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public get workspaceFolder(): vscode.WorkspaceFolder {
|
public get workspaceFolder(): vscode.WorkspaceFolder {
|
||||||
|
@ -96,10 +111,28 @@ class FolderDetector {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getTasks(): Promise<vscode.Task[]> {
|
public async getTasks(): Promise<vscode.Task[]> {
|
||||||
if (!this.promise) {
|
if (this.isEnabled()) {
|
||||||
this.promise = this.computeTasks();
|
if (!this.promise) {
|
||||||
|
this.promise = this.computeTasks();
|
||||||
|
}
|
||||||
|
return this.promise;
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
return this.promise;
|
}
|
||||||
|
|
||||||
|
public async getTask(_task: vscode.Task): Promise<vscode.Task | undefined> {
|
||||||
|
const jakeTask = (<any>_task.definition).task;
|
||||||
|
if (jakeTask) {
|
||||||
|
let kind: JakeTaskDefinition = {
|
||||||
|
type: 'jake',
|
||||||
|
task: jakeTask
|
||||||
|
};
|
||||||
|
let options: vscode.ShellExecutionOptions = { cwd: this.workspaceFolder.uri.fsPath };
|
||||||
|
let task = new vscode.Task(kind, this.workspaceFolder, jakeTask, 'jake', new vscode.ShellExecution(await this._jakeCommand, [jakeTask], options));
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async computeTasks(): Promise<vscode.Task[]> {
|
private async computeTasks(): Promise<vscode.Task[]> {
|
||||||
|
@ -116,17 +149,7 @@ class FolderDetector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let jakeCommand: string;
|
let commandLine = `${await this._jakeCommand} --tasks`;
|
||||||
let platform = process.platform;
|
|
||||||
if (platform === 'win32' && await exists(path.join(rootPath!, 'node_modules', '.bin', 'jake.cmd'))) {
|
|
||||||
jakeCommand = path.join('.', 'node_modules', '.bin', 'jake.cmd');
|
|
||||||
} else if ((platform === 'linux' || platform === 'darwin') && await exists(path.join(rootPath!, 'node_modules', '.bin', 'jake'))) {
|
|
||||||
jakeCommand = path.join('.', 'node_modules', '.bin', 'jake');
|
|
||||||
} else {
|
|
||||||
jakeCommand = 'jake';
|
|
||||||
}
|
|
||||||
|
|
||||||
let commandLine = `${jakeCommand} --tasks`;
|
|
||||||
try {
|
try {
|
||||||
let { stdout, stderr } = await exec(commandLine, { cwd: rootPath });
|
let { stdout, stderr } = await exec(commandLine, { cwd: rootPath });
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
|
@ -149,7 +172,7 @@ class FolderDetector {
|
||||||
task: taskName
|
task: taskName
|
||||||
};
|
};
|
||||||
let options: vscode.ShellExecutionOptions = { cwd: this.workspaceFolder.uri.fsPath };
|
let options: vscode.ShellExecutionOptions = { cwd: this.workspaceFolder.uri.fsPath };
|
||||||
let task = new vscode.Task(kind, taskName, 'jake', new vscode.ShellExecution(`${jakeCommand} ${taskName}`, options));
|
let task = new vscode.Task(kind, taskName, 'jake', new vscode.ShellExecution(`${await this._jakeCommand} ${taskName}`, options));
|
||||||
result.push(task);
|
result.push(task);
|
||||||
let lowerCaseLine = line.toLowerCase();
|
let lowerCaseLine = line.toLowerCase();
|
||||||
if (isBuildTask(lowerCaseLine)) {
|
if (isBuildTask(lowerCaseLine)) {
|
||||||
|
@ -217,9 +240,9 @@ class TaskDetector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let add of added) {
|
for (let add of added) {
|
||||||
let detector = new FolderDetector(add);
|
let detector = new FolderDetector(add, findJakeCommand(add.uri.fsPath));
|
||||||
|
this.detectors.set(add.uri.toString(), detector);
|
||||||
if (detector.isEnabled()) {
|
if (detector.isEnabled()) {
|
||||||
this.detectors.set(add.uri.toString(), detector);
|
|
||||||
detector.start();
|
detector.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,18 +251,16 @@ class TaskDetector {
|
||||||
|
|
||||||
private updateConfiguration(): void {
|
private updateConfiguration(): void {
|
||||||
for (let detector of this.detectors.values()) {
|
for (let detector of this.detectors.values()) {
|
||||||
if (!detector.isEnabled()) {
|
detector.dispose();
|
||||||
detector.dispose();
|
this.detectors.delete(detector.workspaceFolder.uri.toString());
|
||||||
this.detectors.delete(detector.workspaceFolder.uri.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let folders = vscode.workspace.workspaceFolders;
|
let folders = vscode.workspace.workspaceFolders;
|
||||||
if (folders) {
|
if (folders) {
|
||||||
for (let folder of folders) {
|
for (let folder of folders) {
|
||||||
if (!this.detectors.has(folder.uri.toString())) {
|
if (!this.detectors.has(folder.uri.toString())) {
|
||||||
let detector = new FolderDetector(folder);
|
let detector = new FolderDetector(folder, findJakeCommand(folder.uri.fsPath));
|
||||||
|
this.detectors.set(folder.uri.toString(), detector);
|
||||||
if (detector.isEnabled()) {
|
if (detector.isEnabled()) {
|
||||||
this.detectors.set(folder.uri.toString(), detector);
|
|
||||||
detector.start();
|
detector.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -250,12 +271,13 @@ class TaskDetector {
|
||||||
|
|
||||||
private updateProvider(): void {
|
private updateProvider(): void {
|
||||||
if (!this.taskProvider && this.detectors.size > 0) {
|
if (!this.taskProvider && this.detectors.size > 0) {
|
||||||
|
const thisCapture = this;
|
||||||
this.taskProvider = vscode.workspace.registerTaskProvider('gulp', {
|
this.taskProvider = vscode.workspace.registerTaskProvider('gulp', {
|
||||||
provideTasks: () => {
|
provideTasks(): Promise<vscode.Task[]> {
|
||||||
return this.getTasks();
|
return thisCapture.getTasks();
|
||||||
},
|
},
|
||||||
resolveTask(_task: vscode.Task): vscode.Task | undefined {
|
resolveTask(_task: vscode.Task): Promise<vscode.Task | undefined> {
|
||||||
return undefined;
|
return thisCapture.getTask(_task);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -290,6 +312,25 @@ class TaskDetector {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getTask(task: vscode.Task): Promise<vscode.Task | undefined> {
|
||||||
|
if (this.detectors.size === 0) {
|
||||||
|
return undefined;
|
||||||
|
} else if (this.detectors.size === 1) {
|
||||||
|
return this.detectors.values().next().value.getTask(task);
|
||||||
|
} else {
|
||||||
|
if ((task.scope === vscode.TaskScope.Workspace) || (task.scope === vscode.TaskScope.Global)) {
|
||||||
|
// Not supported, we don't have enough info to create the task.
|
||||||
|
return undefined;
|
||||||
|
} else if (task.scope) {
|
||||||
|
const detector = this.detectors.get(task.scope.uri.toString());
|
||||||
|
if (detector) {
|
||||||
|
return detector.getTask(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let detector: TaskDetector;
|
let detector: TaskDetector;
|
||||||
|
|
Loading…
Reference in a new issue