Skip to content

Commit 6a6c085

Browse files
committed
feat: configure the path to the task binary
1 parent e32abc5 commit 6a6c085

File tree

6 files changed

+41
-17
lines changed

6 files changed

+41
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
- Ability to initialize a Taskfile in the current workspace.
1111
- If no Taskfile is detected a button will appear in the sidebar.
1212
- Refresh on save.
13-
- Configurable via `task.updateOn` setting (values: `save` (default) or `manual`).
13+
- Configurable via `task.updateOn` setting (values: `"save"` (default) or `"manual"`).
1414
- Toggle tree nesting on/off
1515
- Configurable via `task.nesting` setting (values: `true` (default) or `false`).
16+
- Change the path to the Task binary.
17+
- Can also be set to the name of a binary in your `$PATH`.
18+
- Configurable via `task.path` setting (defaults to `"task"`).
1619
- Sidebar icon provided by @drite93.

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232

3333
## Configuration
3434

35-
| Setting | Type | Allowed Values | Default | Description |
36-
| -------------- | --------- | -------------------- | -------- | ------------------------------------------------ |
37-
| `updateOn` | `string` | `"manual"`, `"save"` | `"save"` | When should the task list be updated. |
38-
| `tree.nesting` | `boolean` | | `true` | Should the task list be nested or not by default |
35+
| Setting | Type | Allowed Values | Default | Description |
36+
| -------------- | --------- | -------------------- | -------- | ----------------------------------------------------------------------- |
37+
| `updateOn` | `string` | `"manual"`, `"save"` | `"save"` | When should the task list be updated. |
38+
| `path` | `string` | | `task` | Path to the Task binary. Can also the name of a binary in your `$PATH`. |
39+
| `tree.nesting` | `boolean` | | `true` | Should the task list be nested or not by default. |

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@
213213
"default": "save",
214214
"description": "When the list of tasks should be updated."
215215
},
216+
"path": {
217+
"type": "string",
218+
"default": "task",
219+
"description": "Path to the Task binary. If not set, the extension will try to find the binary in the PATH environment variable."
220+
},
216221
"tree": {
217222
"type": "object",
218223
"description": "Tree view configuration options.",

src/services/taskfile.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import * as models from '../models';
44
import * as path from 'path';
55
import * as fs from 'fs';
66
import * as semver from 'semver';
7+
import { settings } from '../settings';
78
import { Octokit } from 'octokit';
89
import { Endpoints } from "@octokit/types";
910

1011
const octokit = new Octokit();
1112
type ReleaseRequest = Endpoints["GET /repos/{owner}/{repo}/releases/latest"]["parameters"];
1213
type ReleaseResponse = Endpoints["GET /repos/{owner}/{repo}/releases/latest"]["response"];
1314

14-
const taskCommand = 'task';
1515
const minimumRequiredVersion = '3.19.1';
1616
const minimumRecommendedVersion = '3.23.0';
1717

@@ -29,9 +29,17 @@ class TaskfileService {
2929
return this._instance ?? (this._instance = new this());
3030
}
3131

32+
private command(command?: string): string {
33+
if (command === undefined) {
34+
return settings.path;
35+
}
36+
return `${settings.path} ${command}`;
37+
}
38+
3239
public async checkInstallation(): Promise<void> {
3340
return await new Promise((resolve) => {
34-
cp.exec(`${taskCommand} --version`, (_, stdout: string, stderr: string) => {
41+
let command = this.command('--version');
42+
cp.exec(command, (_, stdout: string, stderr: string) => {
3543

3644
// If the version is a devel version, ignore all version checks
3745
if (stdout.includes("devel")) {
@@ -109,7 +117,7 @@ class TaskfileService {
109117

110118
public async init(dir: string): Promise<void> {
111119
return await new Promise((resolve) => {
112-
let command = `${taskCommand} --init`;
120+
let command = this.command('--init');
113121
cp.exec(command, { cwd: dir }, (_, stdout: string, stderr: string) => {
114122
if (stderr) {
115123
vscode.window.showErrorMessage(stderr);
@@ -134,7 +142,7 @@ class TaskfileService {
134142

135143
public async read(dir: string): Promise<models.Taskfile> {
136144
return await new Promise((resolve) => {
137-
let command = `${taskCommand} --list-all --json`;
145+
let command = this.command('--list-all --json');
138146
cp.exec(command, { cwd: dir }, (_, stdout: string) => {
139147
var taskfile: models.Taskfile = JSON.parse(stdout);
140148
taskfile.workspace = dir;
@@ -154,7 +162,7 @@ class TaskfileService {
154162
public async runTask(taskName: string, dir?: string): Promise<void> {
155163
return await new Promise((resolve) => {
156164
// Spawn a child process
157-
let child = cp.spawn(taskCommand, [taskName], { cwd: dir });
165+
let child = cp.spawn(this.command(), [taskName], { cwd: dir });
158166

159167
// Clear the output channel and show it
160168
TaskfileService.outputChannel.clear();

src/settings.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
import * as vscode from 'vscode';
22

3-
export class Settings {
3+
class Settings {
4+
private static _instance: Settings;
45
public updateOn!: string;
6+
public path!: string;
57
public treeNesting!: boolean;
68

79
constructor() {
810
this.update();
911
}
1012

13+
public static get instance() {
14+
return this._instance ?? (this._instance = new this());
15+
}
16+
1117
// Fetches all the settings from the workspace configuration file
1218
public update() {
1319
// Get the workspace config
1420
let config = vscode.workspace.getConfiguration("task");
1521

1622
// Set the properties
1723
this.updateOn = config.get("updateOn") ?? "change";
24+
this.path = config.get("path") ?? "task";
1825
this.treeNesting = config.get("tree.nesting") ?? true;
1926
}
2027
}
28+
29+
export const settings = Settings.instance;

src/task.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@ import * as vscode from 'vscode';
22
import * as elements from './elements';
33
import * as services from './services';
44
import * as models from './models';
5-
import { Settings } from './settings';
5+
import { settings } from './settings';
66

77
export class TaskExtension {
88
private _taskfiles: models.Taskfile[] = [];
9-
private _settings: Settings;
109
private _activityBar: elements.ActivityBar;
1110
private _watcher: vscode.FileSystemWatcher;
1211

1312
constructor() {
14-
this._settings = new Settings();
1513
this._activityBar = new elements.ActivityBar();
1614
this._watcher = vscode.workspace.createFileSystemWatcher("**/*.{yml,yaml}");
1715
services.taskfile.checkInstallation();
18-
this.setTreeNesting(this._settings.treeNesting);
16+
this.setTreeNesting(settings.treeNesting);
1917
}
2018

2119
public async update(): Promise<void> {
@@ -162,14 +160,14 @@ export class TaskExtension {
162160

163161
private async _onDidTaskfileChange() {
164162
// If manual updating is turned off (update on save)
165-
if (this._settings.updateOn !== "manual") {
163+
if (settings.updateOn !== "manual") {
166164
await this.updateAndRefresh();
167165
}
168166
}
169167

170168
private _onDidChangeConfiguration(event: vscode.ConfigurationChangeEvent) {
171169
if (event.affectsConfiguration("task")) {
172-
this._settings.update();
170+
settings.update();
173171
}
174172
}
175173
}

0 commit comments

Comments
 (0)