eventmodeler 0.1.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/formatters.d.ts +17 -0
- package/dist/formatters.js +482 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +186 -0
- package/dist/lib/file-loader.d.ts +5 -0
- package/dist/lib/file-loader.js +53 -0
- package/dist/projection.d.ts +3 -0
- package/dist/projection.js +781 -0
- package/dist/slices/export-eventmodel-to-json/index.d.ts +2 -0
- package/dist/slices/export-eventmodel-to-json/index.js +296 -0
- package/dist/slices/list-chapters/index.d.ts +2 -0
- package/dist/slices/list-chapters/index.js +22 -0
- package/dist/slices/list-commands/index.d.ts +2 -0
- package/dist/slices/list-commands/index.js +21 -0
- package/dist/slices/list-events/index.d.ts +2 -0
- package/dist/slices/list-events/index.js +21 -0
- package/dist/slices/list-slices/index.d.ts +2 -0
- package/dist/slices/list-slices/index.js +21 -0
- package/dist/slices/mark-slice-status/index.d.ts +2 -0
- package/dist/slices/mark-slice-status/index.js +38 -0
- package/dist/slices/open-app/index.d.ts +1 -0
- package/dist/slices/open-app/index.js +36 -0
- package/dist/slices/search/index.d.ts +2 -0
- package/dist/slices/search/index.js +175 -0
- package/dist/slices/show-chapter/index.d.ts +2 -0
- package/dist/slices/show-chapter/index.js +43 -0
- package/dist/slices/show-command/index.d.ts +2 -0
- package/dist/slices/show-command/index.js +78 -0
- package/dist/slices/show-event/index.d.ts +2 -0
- package/dist/slices/show-event/index.js +75 -0
- package/dist/slices/show-model-summary/index.d.ts +2 -0
- package/dist/slices/show-model-summary/index.js +20 -0
- package/dist/slices/show-slice/index.d.ts +2 -0
- package/dist/slices/show-slice/index.js +239 -0
- package/dist/types.d.ts +161 -0
- package/dist/types.js +1 -0
- package/package.json +40 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { EventModel, RawEvent } from '../types.js';
|
|
2
|
+
export declare function promptForFile(files: string[]): Promise<string>;
|
|
3
|
+
export declare function findEventModelFile(): Promise<string | null>;
|
|
4
|
+
export declare function loadModel(filePath: string): EventModel;
|
|
5
|
+
export declare function appendEvent(filePath: string, event: RawEvent): void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import * as readline from 'node:readline';
|
|
4
|
+
import { projectEvents } from '../projection.js';
|
|
5
|
+
export async function promptForFile(files) {
|
|
6
|
+
const rl = readline.createInterface({
|
|
7
|
+
input: process.stdin,
|
|
8
|
+
output: process.stderr,
|
|
9
|
+
});
|
|
10
|
+
console.error('\nMultiple .eventmodel files found:\n');
|
|
11
|
+
files.forEach((file, index) => {
|
|
12
|
+
console.error(` ${index + 1}) ${file}`);
|
|
13
|
+
});
|
|
14
|
+
console.error('');
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
rl.question('Select a file (number): ', (answer) => {
|
|
17
|
+
rl.close();
|
|
18
|
+
const index = parseInt(answer, 10) - 1;
|
|
19
|
+
if (index >= 0 && index < files.length) {
|
|
20
|
+
resolve(path.join(process.cwd(), files[index]));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
console.error('Invalid selection. Using first file.');
|
|
24
|
+
resolve(path.join(process.cwd(), files[0]));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export async function findEventModelFile() {
|
|
30
|
+
const files = fs.readdirSync(process.cwd());
|
|
31
|
+
const eventModelFiles = files.filter(f => f.endsWith('.eventmodel'));
|
|
32
|
+
if (eventModelFiles.length === 0) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (eventModelFiles.length === 1) {
|
|
36
|
+
return path.join(process.cwd(), eventModelFiles[0]);
|
|
37
|
+
}
|
|
38
|
+
return promptForFile(eventModelFiles);
|
|
39
|
+
}
|
|
40
|
+
export function loadModel(filePath) {
|
|
41
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
42
|
+
if (!content.trim()) {
|
|
43
|
+
return projectEvents([]);
|
|
44
|
+
}
|
|
45
|
+
const events = content
|
|
46
|
+
.trim()
|
|
47
|
+
.split('\n')
|
|
48
|
+
.map(line => JSON.parse(line));
|
|
49
|
+
return projectEvents(events);
|
|
50
|
+
}
|
|
51
|
+
export function appendEvent(filePath, event) {
|
|
52
|
+
fs.appendFileSync(filePath, JSON.stringify(event) + '\n');
|
|
53
|
+
}
|