-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
executable file
Β·191 lines (171 loc) Β· 5.63 KB
/
main.ts
File metadata and controls
executable file
Β·191 lines (171 loc) Β· 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import * as path from "@std/path";
import { parseArgs } from "@std/cli/parse-args";
import { colors } from "@cliffy/ansi/colors";
import { Select } from "@cliffy/prompt";
import type { EventBroker } from "@env/env-event-stream";
import { initBroker } from "./helpers/index.ts";
import { CONFIG_FILE } from "./config/constants.ts";
import { watchBuilds, watchFiles, watchGit } from "./config/watchers.ts";
import {
commandConfigure,
commandCreateAutomation,
commandGenerateInsights,
commandListTopics,
commandManageDLQ,
commandToggleFocus,
commandViewEvents,
} from "./commands/index.ts";
import {
setupAutomations,
setupInsights,
setupNotifications,
} from "./config/setup.ts";
// Main menu function
async function showMainMenu(broker: EventBroker): Promise<void> {
while (true) {
console.log(colors.blue("\nπ DevStream - Developer Productivity Stream"));
const action = await Select.prompt({
message: "Select an action",
options: [
{ name: "π View Recent Events", value: "events" },
{ name: "π List Topics & Subscriptions", value: "topics" },
{ name: "β οΈ Manage Dead Letter Queue", value: "dlq" },
{ name: "π§ Toggle Focus Mode", value: "focus" },
{ name: "π€ Create Automation", value: "automation" },
{ name: "π Generate Insights Report", value: "insights" },
{ name: "βοΈ Configure Settings", value: "configure" },
{ name: "β Exit", value: "exit" },
],
});
if (action === "exit") {
break;
} else if (action === "events") {
await commandViewEvents(broker, {});
} else if (action === "topics") {
await commandListTopics(broker);
} else if (action === "dlq") {
await commandManageDLQ(broker);
} else if (action === "focus") {
await commandToggleFocus(broker);
} else if (action === "automation") {
await commandCreateAutomation(broker);
} else if (action === "insights") {
await commandGenerateInsights(broker);
} else if (action === "configure") {
await commandConfigure();
}
}
}
// Main function
async function main(): Promise<void> {
const args = parseArgs(Deno.args, {
string: ["topic", "limit"],
default: {
topic: "",
limit: "10",
},
boolean: ["help", "version", "interactive"],
alias: {
h: "help",
v: "version",
i: "interactive",
t: "topic",
l: "limit",
},
});
// Show help
if (args.help) {
console.log(`
DevStream - Developer Productivity Stream
USAGE:
devstream [OPTIONS] [COMMAND]
OPTIONS:
-h, --help Show this help message
-v, --version Show version information
-i, --interactive Start in interactive mode
COMMANDS:
watch Start watching development activity
events [--topic=<topic>] View recent events (optionally filter by topic)
topics List all topics and subscriptions
dlq Manage dead letter queue
focus Toggle focus mode
automation Create a new automation
insights Generate development insights report
configure Configure DevStream settings
`);
Deno.exit(0);
}
// Show version
if (args.version) {
const configText = await Deno.readTextFile(CONFIG_FILE);
const config = JSON.parse(configText);
console.log(`DevStream v${config.version}`);
Deno.exit(0);
}
// Initialize broker
const broker = await initBroker();
// Load config
const configText = await Deno.readTextFile(CONFIG_FILE);
const config = JSON.parse(configText);
// Process commands
const command = args._[0]?.toString() ||
(args.interactive ? "interactive" : null);
if (!command) {
console.log(
"No command specified. Use --help for usage information or --interactive for interactive mode.",
);
Deno.exit(1);
}
if (command === "watch" || command === "interactive") {
console.log(colors.green("π Starting DevStream..."));
// Start watching files
const watchDirs = (config.watchDirs || []).map((dir: string) =>
path.join(Deno.cwd(), dir)
);
if (watchDirs.length === 0) {
console.error(colors.red("No watch directories specified"));
Deno.exit(1);
}
// Start watching stuff
await watchFiles(broker, watchDirs, config.ignorePaths);
await watchGit(broker);
watchBuilds(broker);
// Setup stuff
await setupNotifications(broker);
await setupAutomations(broker);
await setupInsights(broker);
console.log(
colors.green("β
DevStream is now monitoring your development activity"),
);
// Show interactive menu if requested
if (command === "interactive" || args.interactive) {
await showMainMenu(broker);
Deno.exit(0);
}
} else if (command === "events") {
await commandViewEvents(broker, { topic: args.topic, limit: args.limit });
} else if (command === "topics") {
await commandListTopics(broker);
} else if (command === "dlq") {
await commandManageDLQ(broker);
} else if (command === "focus") {
await commandToggleFocus(broker);
} else if (command === "automation") {
await commandCreateAutomation(broker);
} else if (command === "insights") {
await commandGenerateInsights(broker);
} else if (command === "configure") {
await commandConfigure();
} else {
console.error(colors.red(`Unknown command: ${command}`));
console.log("Use --help for usage information.");
Deno.exit(1);
}
}
// Start the application
if (import.meta.main) {
main().catch((error) => {
console.error(colors.red("Fatal error:"), error);
Deno.exit(1);
});
}