@canonical/code-standards 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/.mcp.json +8 -0
- package/README.md +297 -0
- package/data/code.ttl +437 -0
- package/data/css.ttl +265 -0
- package/data/icons.ttl +359 -0
- package/data/packaging.ttl +464 -0
- package/data/react.ttl +752 -0
- package/data/rust.ttl +1806 -0
- package/data/storybook.ttl +403 -0
- package/data/styling.ttl +165 -0
- package/data/tsdoc.ttl +216 -0
- package/data/turtle.ttl +179 -0
- package/definitions/CodeStandard.ttl +80 -0
- package/docs/code.md +720 -0
- package/docs/css.md +275 -0
- package/docs/icons.md +367 -0
- package/docs/index.md +15 -0
- package/docs/react.md +766 -0
- package/docs/rust.md +1784 -0
- package/docs/storybook.md +413 -0
- package/docs/styling.md +163 -0
- package/docs/tsdoc.md +213 -0
- package/docs/turtle.md +179 -0
- package/package.json +9 -0
- package/skills/add-standard/SKILL.md +288 -0
- package/src/scripts/generate-docs.ts +131 -0
- package/src/scripts/index.ts +19 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Transforms code standards from TTL to readable markdown per category.
|
|
4
|
+
* Usage: bun src/scripts/generate-docs.ts [output-dir]
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { readFileSync, writeFileSync, mkdirSync, readdirSync } from "fs";
|
|
8
|
+
import { join, basename } from "path";
|
|
9
|
+
|
|
10
|
+
const DATA_DIR = join(import.meta.dir, "../../data");
|
|
11
|
+
const DEFAULT_OUTPUT = "./docs";
|
|
12
|
+
|
|
13
|
+
interface Standard {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
dos: string;
|
|
17
|
+
donts: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface Category {
|
|
21
|
+
label: string;
|
|
22
|
+
slug: string;
|
|
23
|
+
standards: Standard[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Minimal TTL parser - extracts string literals
|
|
27
|
+
function extractLiteral(content: string, predicate: string): string {
|
|
28
|
+
const regex = new RegExp(`${predicate}\\s+"""([\\s\\S]*?)"""`, "g");
|
|
29
|
+
const match = regex.exec(content);
|
|
30
|
+
if (match) return match[1].trim();
|
|
31
|
+
|
|
32
|
+
const singleLine = new RegExp(`${predicate}\\s+"([^"]*)"`, "g");
|
|
33
|
+
const singleMatch = singleLine.exec(content);
|
|
34
|
+
return singleMatch ? singleMatch[1].trim() : "";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function parseCategory(content: string): { label: string; slug: string } {
|
|
38
|
+
const label =
|
|
39
|
+
content.match(/rdfs:label\s+"([^"]+)"/)?.[1] ||
|
|
40
|
+
content.match(/rdfs:label\s+"([^"]+)"@en/)?.[1] ||
|
|
41
|
+
"";
|
|
42
|
+
const slug = content.match(/cs:slug\s+"([^"]+)"/)?.[1] || "";
|
|
43
|
+
return { label, slug };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function parseStandards(content: string): Standard[] {
|
|
47
|
+
// Split by standard definitions
|
|
48
|
+
const blocks = content.split(/\n(?=\w+:\w+\s+a\s+cs:CodeStandard)/);
|
|
49
|
+
const standards: Standard[] = [];
|
|
50
|
+
|
|
51
|
+
for (const block of blocks) {
|
|
52
|
+
if (!block.includes("a cs:CodeStandard")) continue;
|
|
53
|
+
|
|
54
|
+
const name = extractLiteral(block, "cs:name");
|
|
55
|
+
const description = extractLiteral(block, "cs:description");
|
|
56
|
+
const dos = extractLiteral(block, "cs:dos");
|
|
57
|
+
const donts = extractLiteral(block, "cs:donts");
|
|
58
|
+
|
|
59
|
+
if (name) {
|
|
60
|
+
standards.push({ name, description, dos, donts });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return standards.sort((a, b) => a.name.localeCompare(b.name));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function generateMarkdown(category: Category): string {
|
|
68
|
+
const lines: string[] = [
|
|
69
|
+
`# ${category.label} Standards`,
|
|
70
|
+
"",
|
|
71
|
+
`Standards for ${category.slug} development.`,
|
|
72
|
+
"",
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
for (const std of category.standards) {
|
|
76
|
+
lines.push(`## ${std.name}`, "", std.description, "");
|
|
77
|
+
|
|
78
|
+
if (std.dos) {
|
|
79
|
+
lines.push("### Do", "", std.dos, "");
|
|
80
|
+
}
|
|
81
|
+
if (std.donts) {
|
|
82
|
+
lines.push("### Don't", "", std.donts, "");
|
|
83
|
+
}
|
|
84
|
+
lines.push("---", "");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return lines.join("\n");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function main() {
|
|
91
|
+
const outputDir = process.argv[2] || DEFAULT_OUTPUT;
|
|
92
|
+
mkdirSync(outputDir, { recursive: true });
|
|
93
|
+
|
|
94
|
+
const files = readdirSync(DATA_DIR).filter((f) => f.endsWith(".ttl"));
|
|
95
|
+
const categories: Category[] = [];
|
|
96
|
+
|
|
97
|
+
for (const file of files) {
|
|
98
|
+
const content = readFileSync(join(DATA_DIR, file), "utf-8");
|
|
99
|
+
const { label, slug } = parseCategory(content);
|
|
100
|
+
const standards = parseStandards(content);
|
|
101
|
+
|
|
102
|
+
if (!label || standards.length === 0) continue;
|
|
103
|
+
|
|
104
|
+
const category = { label, slug: slug || basename(file, ".ttl"), standards };
|
|
105
|
+
categories.push(category);
|
|
106
|
+
|
|
107
|
+
const markdown = generateMarkdown(category);
|
|
108
|
+
const outFile = join(outputDir, `${category.slug}.md`);
|
|
109
|
+
writeFileSync(outFile, markdown);
|
|
110
|
+
console.log(`Generated ${outFile} (${standards.length} standards)`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Generate index
|
|
114
|
+
const index = [
|
|
115
|
+
"# Code Standards",
|
|
116
|
+
"",
|
|
117
|
+
"Standards documentation generated from the code-standards ontology.",
|
|
118
|
+
"",
|
|
119
|
+
"## Categories",
|
|
120
|
+
"",
|
|
121
|
+
...categories
|
|
122
|
+
.sort((a, b) => a.label.localeCompare(b.label))
|
|
123
|
+
.map((c) => `- [${c.label}](./${c.slug}.md) (${c.standards.length})`),
|
|
124
|
+
"",
|
|
125
|
+
].join("\n");
|
|
126
|
+
|
|
127
|
+
writeFileSync(join(outputDir, "index.md"), index);
|
|
128
|
+
console.log(`Generated ${join(outputDir, "index.md")}`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
main();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Code standards scripts entry point.
|
|
4
|
+
* Routes to specific scripts based on command.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const command = process.argv[2];
|
|
8
|
+
|
|
9
|
+
switch (command) {
|
|
10
|
+
case "docs":
|
|
11
|
+
case "generate-docs":
|
|
12
|
+
await import("./generate-docs.ts");
|
|
13
|
+
break;
|
|
14
|
+
default:
|
|
15
|
+
console.log("Usage: bun src/scripts/index.ts <command>");
|
|
16
|
+
console.log("");
|
|
17
|
+
console.log("Commands:");
|
|
18
|
+
console.log(" docs [output-dir] Generate markdown docs (default: ./docs)");
|
|
19
|
+
}
|