-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Autogenerate docs and autocompletion for composite block types (#632)
Autogenerate docs and autocompletion for composite block types
- Loading branch information
Showing
12 changed files
with
277 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// SPDX-FileCopyrightText: 2024 Friedrich-Alexander-Universitat Erlangen-Nurnberg | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
|
||
export class UserDocCategoryBuilder { | ||
generateDocsCategory( | ||
rootPath: string, | ||
dirName: string, | ||
label: string, | ||
position: number, | ||
description: string, | ||
): string { | ||
const categoryPath = path.join(rootPath, dirName); | ||
|
||
fs.mkdirSync(categoryPath, { recursive: true }); | ||
|
||
fs.writeFileSync( | ||
path.join(categoryPath, '_category_.json'), | ||
this.getCategoryJSONString(label, position, description), | ||
); | ||
|
||
fs.writeFileSync( | ||
path.join(categoryPath, '_category_.json.license'), | ||
this.getCategoryLicenseString(new Date().getFullYear()), | ||
); | ||
|
||
fs.writeFileSync( | ||
path.join(categoryPath, '.gitignore'), | ||
this.getCategoryGitignoreString(new Date().getFullYear()), | ||
); | ||
|
||
return categoryPath; | ||
} | ||
|
||
private getCategoryJSONString( | ||
label: string, | ||
position: number, | ||
description: string, | ||
): string { | ||
return `{ | ||
"label": "${label}", | ||
"position": ${position}, | ||
"link": { | ||
"type": "generated-index", | ||
"description": "${description}" | ||
} | ||
}`; | ||
} | ||
|
||
private getCategoryLicenseString(year: number): string { | ||
// REUSE-IgnoreStart | ||
return `SPDX-FileCopyrightText: ${year} Friedrich-Alexander-Universitat Erlangen-Nurnberg | ||
SPDX-License-Identifier: AGPL-3.0-only`; | ||
// REUSE-IgnoreEnd | ||
} | ||
|
||
private getCategoryGitignoreString(year: number): string { | ||
// REUSE-IgnoreStart | ||
return `# SPDX-FileCopyrightText: ${year} Friedrich-Alexander-Universitat Erlangen-Nurnberg | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-only | ||
*.md`; | ||
// REUSE-IgnoreEnd | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// SPDX-FileCopyrightText: 2024 Friedrich-Alexander-Universitat Erlangen-Nurnberg | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
import { | ||
type ExampleDoc, | ||
type IOType, | ||
MarkdownBuilder, | ||
type PropertySpecification, | ||
} from '@jvalue/jayvee-language-server'; | ||
|
||
export class UserDocMarkdownBuilder { | ||
private markdownBuilder = new MarkdownBuilder(); | ||
|
||
docTitle(blockType: string): UserDocMarkdownBuilder { | ||
this.markdownBuilder | ||
.line('---') | ||
.line(`title: ${blockType}`) | ||
.line('---') | ||
.newLine(); | ||
return this; | ||
} | ||
|
||
generationComment(): UserDocMarkdownBuilder { | ||
this.markdownBuilder | ||
.comment( | ||
'Do NOT change this document as it is auto-generated from the language server', | ||
) | ||
.newLine(); | ||
return this; | ||
} | ||
|
||
heading(heading: string, depth = 1): UserDocMarkdownBuilder { | ||
this.markdownBuilder.heading(heading, depth); | ||
return this; | ||
} | ||
|
||
propertyHeading(propertyName: string, depth = 1): UserDocMarkdownBuilder { | ||
this.markdownBuilder.heading(`\`${propertyName}\``, depth); | ||
return this; | ||
} | ||
|
||
propertySpec(propertySpec: PropertySpecification): UserDocMarkdownBuilder { | ||
this.markdownBuilder.line(`Type \`${propertySpec.type.getName()}\``); | ||
if (propertySpec.defaultValue !== undefined) { | ||
this.markdownBuilder | ||
.newLine() | ||
.line(`Default: \`${JSON.stringify(propertySpec.defaultValue)}\``); | ||
} | ||
this.markdownBuilder.newLine(); | ||
return this; | ||
} | ||
|
||
ioTypes(inputType: IOType, outputType: IOType): UserDocMarkdownBuilder { | ||
this.markdownBuilder | ||
.line(`Input type: \`${inputType}\``) | ||
.newLine() | ||
.line(`Output type: \`${outputType}\``) | ||
.newLine(); | ||
return this; | ||
} | ||
|
||
compatibleValueType(type: string): UserDocMarkdownBuilder { | ||
this.markdownBuilder.line(`Compatible value type: ${type}`); | ||
this.markdownBuilder.newLine(); | ||
return this; | ||
} | ||
|
||
description(text?: string, depth = 2): UserDocMarkdownBuilder { | ||
if (text === undefined) { | ||
return this; | ||
} | ||
this.markdownBuilder.heading('Description', depth).line(text).newLine(); | ||
return this; | ||
} | ||
|
||
propertiesHeading(): UserDocMarkdownBuilder { | ||
this.markdownBuilder.heading('Properties', 2); | ||
return this; | ||
} | ||
|
||
validation(text?: string, depth = 2): UserDocMarkdownBuilder { | ||
if (text === undefined) { | ||
return this; | ||
} | ||
this.markdownBuilder.heading('Validation', depth).line(text).newLine(); | ||
return this; | ||
} | ||
|
||
examples(examples?: ExampleDoc[], depth = 2): UserDocMarkdownBuilder { | ||
if (examples === undefined) { | ||
return this; | ||
} | ||
for (const [index, example] of examples.entries()) { | ||
this.markdownBuilder | ||
.heading(`Example ${index + 1}`, depth) | ||
.code(example.code, 'jayvee') | ||
.line(example.description) | ||
.newLine(); | ||
} | ||
return this; | ||
} | ||
|
||
build(): string { | ||
return this.markdownBuilder.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.