Skip to content

Commit 81c46a0

Browse files
committed
feat: add demo validation service and commands for fixing duplicate IDs
1 parent ce0e589 commit 81c46a0

File tree

10 files changed

+800
-1
lines changed

10 files changed

+800
-1
lines changed

.demo/test-global-duplicates.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://demotime.show/demo-time.schema.json",
3+
"title": "Test Global Duplicates",
4+
"description": "Demo file to test global duplicate ID validation",
5+
"demos": [
6+
{
7+
"id": "demo1",
8+
"title": "Global Duplicate Demo",
9+
"description": "This demo has an ID that conflicts with test-validation.json",
10+
"steps": [
11+
{
12+
"action": "create",
13+
"path": "global-test.txt",
14+
"content": "Global duplicate test"
15+
}
16+
]
17+
},
18+
{
19+
"id": "yaml-demo1",
20+
"title": "Another Global Duplicate",
21+
"description": "This demo conflicts with the YAML file",
22+
"steps": [
23+
{
24+
"action": "create",
25+
"path": "another-global-test.txt",
26+
"content": "Another global duplicate test"
27+
}
28+
]
29+
}
30+
]
31+
}

.demo/test-validation.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"$schema": "https://demotime.show/demo-time.schema.json",
3+
"title": "Test Validation",
4+
"description": "Demo file to test duplicate ID validation",
5+
"demos": [
6+
{
7+
"id": "demo1",
8+
"title": "First Demo",
9+
"description": "This is the first demo",
10+
"steps": [
11+
{
12+
"action": "create",
13+
"path": "test1.txt",
14+
"content": "Test content 1"
15+
}
16+
]
17+
},
18+
{
19+
"id": "demo1",
20+
"title": "Second Demo (Duplicate ID)",
21+
"description": "This demo has a duplicate ID",
22+
"steps": [
23+
{
24+
"action": "create",
25+
"path": "test2.txt",
26+
"content": "Test content 2"
27+
}
28+
]
29+
},
30+
{
31+
"id": "demo3",
32+
"title": "Third Demo",
33+
"description": "This demo has a unique ID",
34+
"steps": [
35+
{
36+
"action": "create",
37+
"path": "test3.txt",
38+
"content": "Test content 3"
39+
}
40+
]
41+
}
42+
]
43+
}

.demo/test-validation.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
$schema: https://demotime.show/demo-time.schema.json
2+
title: Test YAML Validation
3+
description: YAML demo file to test duplicate ID validation
4+
demos:
5+
- id: yaml-demo1
6+
title: First YAML Demo
7+
description: This is the first YAML demo
8+
steps:
9+
- action: create
10+
path: yaml-test1.txt
11+
content: YAML test content 1
12+
- id: yaml-demo1
13+
title: Second YAML Demo (Duplicate ID)
14+
description: This YAML demo has a duplicate ID
15+
steps:
16+
- action: create
17+
path: yaml-test2.txt
18+
content: YAML test content 2
19+
- id: yaml-demo3
20+
title: Third YAML Demo
21+
description: This YAML demo has a unique ID
22+
steps:
23+
- action: create
24+
path: yaml-test3.txt
25+
content: YAML test content 3

.frontmatter/database/mediaDb.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"apps":{"vscode-extension":{"tests":{}}}}

apps/vscode-extension/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@
358358
"title": "Close presentation view",
359359
"category": "Demo Time"
360360
},
361+
{
362+
"command": "demoTime.fixDuplicateIds",
363+
"title": "Fix duplicate demo IDs",
364+
"category": "Demo Time",
365+
"icon": "$(warning)"
366+
},
361367
{
362368
"command": "demo-time.reset",
363369
"title": "Reset",

apps/vscode-extension/src/services/DemoListeners.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TextDocument, Uri, workspace } from 'vscode';
1+
import { ExtensionContext, TextDocument, Uri, workspace } from 'vscode';
22
import { parseWinPath } from '../utils';
33
import { DemoPanel } from '../panels/DemoPanel';
44
import { General } from '../constants';
@@ -7,9 +7,21 @@ import { DemoRunner } from './DemoRunner';
77
import { DemoStatusBar } from './DemoStatusBar';
88
import { Config } from '@demotime/common';
99
import { Overview } from '../overview/Overview';
10+
import { DemoValidationService } from './DemoValidationService';
11+
import { Extension } from '.';
1012

1113
export class DemoListeners {
1214
public static register() {
15+
const ext = Extension.getInstance();
16+
if (!ext) {
17+
return;
18+
}
19+
20+
const ctx = ext.context;
21+
22+
// Initialize validation service
23+
DemoValidationService.register(ctx);
24+
1325
workspace.onDidSaveTextDocument(DemoListeners.checkToUpdate);
1426
workspace.onDidChangeConfiguration((e) => {
1527
if (e.affectsConfiguration(Config.root)) {

0 commit comments

Comments
 (0)