@bretwardjames/tw-bridge 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +6 -0
- package/dist/hooks/on-modify.js +32 -2
- package/examples/config.json +5 -1
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -393,6 +393,12 @@ async function install() {
|
|
|
393
393
|
console.log("urgency.user.tag.in_review.coefficient=-2.0");
|
|
394
394
|
console.log("urgency.user.tag.ready_for_beta.coefficient=-4.0");
|
|
395
395
|
console.log("urgency.user.tag.in_beta.coefficient=-6.0");
|
|
396
|
+
const timewHook = path3.join(HOOKS_DIR, "on-modify.timewarrior");
|
|
397
|
+
if (fs2.existsSync(timewHook)) {
|
|
398
|
+
console.log("\nNote: Found on-modify.timewarrior hook.");
|
|
399
|
+
console.log("If you enable tw-bridge Timewarrior management, disable it to avoid double-tracking:");
|
|
400
|
+
console.log(` mv ${timewHook} ${timewHook}.disabled`);
|
|
401
|
+
}
|
|
396
402
|
installShellFunction();
|
|
397
403
|
}
|
|
398
404
|
var SHELL_FUNCTION = `
|
package/dist/hooks/on-modify.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/hooks/on-modify.ts
|
|
4
4
|
import fs2 from "fs";
|
|
5
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
5
6
|
|
|
6
7
|
// src/config.ts
|
|
7
8
|
import fs from "fs";
|
|
@@ -176,17 +177,46 @@ async function resolveAdapter(task, config) {
|
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
// src/hooks/on-modify.ts
|
|
180
|
+
function timewTags(task) {
|
|
181
|
+
const tags = [];
|
|
182
|
+
if (task.backend) tags.push(task.backend);
|
|
183
|
+
if (task.backend_id) tags.push(`#${task.backend_id}`);
|
|
184
|
+
if (task.project) tags.push(task.project);
|
|
185
|
+
for (const tag of task.tags ?? []) {
|
|
186
|
+
if (!tag.includes("_")) tags.push(tag);
|
|
187
|
+
}
|
|
188
|
+
return [...new Set(tags)];
|
|
189
|
+
}
|
|
190
|
+
function handleTimewarrior(config, oldTask, newTask, wasStarted, wasStopped, wasCompleted) {
|
|
191
|
+
const twConfig = config.timewarrior;
|
|
192
|
+
if (!twConfig?.enabled) return;
|
|
193
|
+
const overlap = twConfig.allow_overlaps ?? false;
|
|
194
|
+
if (wasStarted) {
|
|
195
|
+
const tags = timewTags(newTask);
|
|
196
|
+
const args = ["start", ...tags];
|
|
197
|
+
if (overlap) args.splice(1, 0, ":overlap");
|
|
198
|
+
spawnSync2("timew", args, { stdio: "pipe" });
|
|
199
|
+
} else if (wasStopped || wasCompleted) {
|
|
200
|
+
const tags = timewTags(oldTask);
|
|
201
|
+
if (overlap) {
|
|
202
|
+
spawnSync2("timew", ["stop", ...tags], { stdio: "pipe" });
|
|
203
|
+
} else {
|
|
204
|
+
spawnSync2("timew", ["stop"], { stdio: "pipe" });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
179
208
|
async function main() {
|
|
180
209
|
const input = fs2.readFileSync("/dev/stdin", "utf-8").trim().split("\n");
|
|
181
210
|
const oldTask = JSON.parse(input[0]);
|
|
182
211
|
const newTask = JSON.parse(input[1]);
|
|
183
212
|
process.stdout.write(JSON.stringify(newTask) + "\n");
|
|
184
213
|
const config = loadConfig();
|
|
185
|
-
const adapter = await resolveAdapter(newTask, config);
|
|
186
|
-
if (!adapter) return;
|
|
187
214
|
const wasStarted = !oldTask.start && !!newTask.start;
|
|
188
215
|
const wasStopped = !!oldTask.start && !newTask.start && newTask.status === "pending";
|
|
189
216
|
const wasCompleted = oldTask.status !== "completed" && newTask.status === "completed";
|
|
217
|
+
handleTimewarrior(config, oldTask, newTask, wasStarted, wasStopped, wasCompleted);
|
|
218
|
+
const adapter = await resolveAdapter(newTask, config);
|
|
219
|
+
if (!adapter) return;
|
|
190
220
|
let ttyFd = null;
|
|
191
221
|
try {
|
|
192
222
|
if (wasStarted && adapter.onStart) {
|
package/examples/config.json
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
+
"timewarrior": {
|
|
3
|
+
"enabled": true,
|
|
4
|
+
"allow_overlaps": true
|
|
5
|
+
},
|
|
2
6
|
"backends": {
|
|
3
7
|
"ghp": {
|
|
4
8
|
"adapter": "ghp",
|
|
@@ -6,7 +10,7 @@
|
|
|
6
10
|
"tags": ["ghp"]
|
|
7
11
|
},
|
|
8
12
|
"config": {
|
|
9
|
-
"cwd": "/
|
|
13
|
+
"cwd": "/path/to/your/repo",
|
|
10
14
|
"project": "ghp"
|
|
11
15
|
}
|
|
12
16
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bretwardjames/tw-bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Taskwarrior backend bridge — unified sync and hooks for multiple task management platforms",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/bretwardjames/tw-bridge.git"
|
|
9
|
+
"url": "git+https://github.com/bretwardjames/tw-bridge.git"
|
|
10
10
|
},
|
|
11
11
|
"keywords": [
|
|
12
12
|
"taskwarrior",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"sync"
|
|
17
17
|
],
|
|
18
18
|
"bin": {
|
|
19
|
-
"tw-bridge": "
|
|
19
|
+
"tw-bridge": "dist/cli.js"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"dist",
|