Skip to content

Commit c41bad5

Browse files
authored
ci: check component spec generation (#114)
1 parent abe363c commit c41bad5

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ jobs:
4545
- run: npm run build-webview
4646
- run: npm run build-cli
4747
- run: npm run lint
48+
- run: npm run validate-component-spec
49+
if: matrix.os == 'ubuntu-latest'
4850
- run: npm run package:win
4951
if: matrix.platform == 'win32-x64'
5052
- run: npm run package -- --target ${{ matrix.platform }}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@
348348
"build-webview": "webpack-cli --config webpack.config.webview.js",
349349
"build-cli": "webpack-cli --config webpack.config.cli.js",
350350
"generate-component-spec": "npm run compile && node ./out/poml-vscode/lsp/parseComments.js && npm run compile && node ./out/poml-vscode/lsp/parseComments.js",
351+
"validate-component-spec": "npm run compile && node ./out/poml-vscode/lsp/parseComments.js --check && npm run compile && node ./out/poml-vscode/lsp/parseComments.js --check",
351352
"generate-vscodeignore": "node ./vscodeignore.js",
352353
"compile": "tspc -p ./",
353354
"watch": "tspc -watch -p ./",

packages/poml-vscode/lsp/parseComments.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
import 'poml';
22
import { ComponentSpec, Parameter } from 'poml/base';
33

4-
import { readFileSync, readdirSync, writeFile, writeFileSync } from 'fs';
4+
import { readFileSync, readdirSync, writeFileSync } from 'fs';
55
import { join } from 'path';
66
import { formatComponentDocumentation } from './documentFormatter';
77

8+
const checkMode = process.argv.includes('--check');
9+
let hasChanges = false;
10+
11+
function writeOrCheck(filePath: string, content: string) {
12+
let existing: string | undefined;
13+
try {
14+
existing = readFileSync(filePath, 'utf8');
15+
} catch {
16+
existing = undefined;
17+
}
18+
19+
if (existing !== content) {
20+
if (checkMode) {
21+
console.error(`${filePath} is out of date.`);
22+
hasChanges = true;
23+
} else {
24+
writeFileSync(filePath, content);
25+
console.log(`Updated ${filePath}`);
26+
}
27+
}
28+
}
29+
830
const basicComponents: string[] = [];
931
const intentions: string[] = [];
1032
const dataDisplays: string[] = [];
@@ -287,7 +309,17 @@ class _TagLib:
287309

288310
const allDocs = scanComponentDocs('packages/poml');
289311
const pythonCode = generatePythonFile(allDocs);
290-
writeFileSync('packages/poml/assets/componentDocs.json', JSON.stringify(allDocs, null, 2));
291-
writeFileSync('docs/language/components.md', docsToMarkdown(allDocs));
292-
writeFileSync('python/poml/_tags.py', pythonCode);
293-
console.log('Component documentation generated successfully!');
312+
writeOrCheck('packages/poml/assets/componentDocs.json', JSON.stringify(allDocs, null, 2));
313+
writeOrCheck('docs/language/components.md', docsToMarkdown(allDocs));
314+
writeOrCheck('python/poml/_tags.py', pythonCode);
315+
316+
if (checkMode) {
317+
if (hasChanges) {
318+
console.error('Component documentation is out of date. Run `npm run generate-component-spec` to update.');
319+
process.exit(1);
320+
} else {
321+
console.log('Component documentation is up to date.');
322+
}
323+
} else {
324+
console.log('Component documentation generated successfully!');
325+
}

0 commit comments

Comments
 (0)