Skip to content

Commit 5cdc70d

Browse files
don't ignore built files
1 parent 73b8c1f commit 5cdc70d

4 files changed

Lines changed: 125 additions & 2 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ node_modules/
2020

2121
# Build outputs
2222
dist/
23-
build/
2423
*.tsbuildinfo
2524

2625
# Environment variables

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@ repos:
1616
language: script
1717
stages: [commit, push]
1818
always_run: true
19+
20+
- repo: local
21+
hooks:
22+
- id: tests
23+
name: Run tests
24+
entry: yarn test --silent
25+
language: system
26+
files: ^lib/.*\.(ts|tsx|js|jsx)$
27+
stages: [commit, push]

build/compiled.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
(() => {
2+
// lib/plugin.js
3+
var plugin = {
4+
constants: {},
5+
// https://www.amplenote.com/help/developing_amplenote_plugins#noteOption
6+
taskOption: {
7+
"Bulk Reset Overdue Tasks": {
8+
run: async function(app, noteUUID) {
9+
try {
10+
const oneHourAgo = Math.floor(Date.now() / 1e3) - 3600;
11+
const taskDomains = await app.getTaskDomains();
12+
if (!taskDomains || taskDomains.length === 0) {
13+
await app.alert("No task domains found.");
14+
return;
15+
}
16+
const overdueTasks = [];
17+
const tasksByDomain = {};
18+
for (const taskDomain of taskDomains) {
19+
const domainTasks = [];
20+
for await (const task of app.getTaskDomainTasks(taskDomain.uuid)) {
21+
const taskDate = task.startAt || task.endAt;
22+
if (taskDate && taskDate < oneHourAgo) {
23+
overdueTasks.push(task);
24+
domainTasks.push(task);
25+
}
26+
}
27+
if (domainTasks.length > 0) {
28+
tasksByDomain[taskDomain.name] = domainTasks;
29+
}
30+
}
31+
if (overdueTasks.length === 0) {
32+
await app.alert("No overdue tasks found.");
33+
return;
34+
}
35+
const domainBreakdown = Object.entries(tasksByDomain).map(([domainName, tasks]) => {
36+
const taskList = tasks.map((task) => {
37+
const content = task.content || "Untitled task";
38+
const truncated = content.length > 60 ? content.substring(0, 57) + "..." : content;
39+
return ` - ${truncated}`;
40+
}).join("\n");
41+
return ` ${domainName} (${tasks.length}):
42+
${taskList}`;
43+
}).join("\n\n");
44+
const confirmMessage = `Found ${overdueTasks.length} overdue task${overdueTasks.length > 1 ? "s" : ""}:
45+
46+
${domainBreakdown}
47+
48+
Remove from calendar?`;
49+
const confirmed = await app.alert(confirmMessage, {
50+
actions: [
51+
{ label: "Cancel", icon: "cancel" },
52+
{ label: "Remove from calendar", icon: "check" }
53+
]
54+
});
55+
if (confirmed === 1) {
56+
let successCount = 0;
57+
let failCount = 0;
58+
const errors = [];
59+
for (const task of overdueTasks) {
60+
try {
61+
const updates = {};
62+
console.log(`Processing task ${task.uuid}:`);
63+
console.log(` startAt: ${task.startAt}`);
64+
console.log(` endAt: ${task.endAt}`);
65+
console.log(` hideUntil: ${task.hideUntil}`);
66+
if (task.startAt !== null && task.startAt !== void 0) {
67+
delete updates.startAt;
68+
}
69+
if (task.endAt !== null && task.endAt !== void 0) {
70+
delete updates.endAt;
71+
}
72+
if (task.hideUntil !== null && task.hideUntil !== void 0) {
73+
delete updates.hideUntil;
74+
}
75+
console.log(` Updates to apply:`, updates);
76+
if (Object.keys(updates).length > 0) {
77+
await app.updateTask(task.uuid, updates);
78+
console.log(` \u2713 Successfully updated task ${task.uuid}`);
79+
successCount++;
80+
} else {
81+
console.log(
82+
` \u26A0 Task ${task.uuid} has no calendar dates to remove`
83+
);
84+
successCount++;
85+
}
86+
} catch (error) {
87+
const errorMsg = `Task "${task.content || task.uuid}": ${error.message}`;
88+
console.error(`Failed to reset task ${task.uuid}:`, error);
89+
console.error(`Task data:`, JSON.stringify(task));
90+
errors.push(errorMsg);
91+
failCount++;
92+
}
93+
}
94+
let resultMessage = `Successfully reset ${successCount} task${successCount !== 1 ? "s" : ""}.`;
95+
if (failCount > 0) {
96+
resultMessage += `
97+
98+
${failCount} task${failCount !== 1 ? "s" : ""} failed:
99+
`;
100+
resultMessage += errors.map((e) => `\u2022 ${e}`).join("\n");
101+
}
102+
await app.alert(resultMessage);
103+
}
104+
} catch (error) {
105+
console.error("Error in Bulk Reset Overdue Tasks:", error);
106+
await app.alert(`Error: ${error.message}`);
107+
}
108+
}
109+
}
110+
},
111+
insertText: {},
112+
replaceText: {}
113+
};
114+
var plugin_default = plugin;
115+
})();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
},
2121
"testEnvironment": "jsdom",
2222
"type": "module",
23-
"version": "1.0.0"
23+
"version": "1.0.1"
2424
}

0 commit comments

Comments
 (0)