chore(core): add map.json jsonschema (#12701)

This commit is contained in:
Benjamin Cabanes 2022-10-18 15:30:15 -07:00 committed by GitHub
parent e8359d1d0d
commit 6520905fc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1699 additions and 1619 deletions

View File

@ -1,4 +1,8 @@
[ {
"$schema": "./../scripts/documentation/map-schema.json",
"title": "Documentation map reference",
"description": "This is used to create documentation routing and hierarchy on the nx.dev website.",
"content": [
{ {
"name": "Nx docs", "name": "Nx docs",
"id": "nx-documentation", "id": "nx-documentation",
@ -1184,7 +1188,11 @@
"id": "run", "id": "run",
"file": "generated/cli/run" "file": "generated/cli/run"
}, },
{ "name": "daemon", "id": "daemon", "file": "generated/cli/daemon" }, {
"name": "daemon",
"id": "daemon",
"file": "generated/cli/daemon"
},
{ {
"name": "graph", "name": "graph",
"id": "dep-graph", "id": "dep-graph",
@ -1241,7 +1249,11 @@
"tags": ["automate-updating-dependencies"], "tags": ["automate-updating-dependencies"],
"file": "generated/cli/migrate" "file": "generated/cli/migrate"
}, },
{ "name": "report", "id": "report", "file": "generated/cli/report" }, {
"name": "report",
"id": "report",
"file": "generated/cli/report"
},
{ "name": "list", "id": "list", "file": "generated/cli/list" }, { "name": "list", "id": "list", "file": "generated/cli/list" },
{ {
"name": "workspace-lint", "name": "workspace-lint",
@ -1613,3 +1625,4 @@
] ]
} }
] ]
}

View File

@ -24,10 +24,10 @@ export const packagesApi = new PackagesApi({
export const nxDocumentsApi = new DocumentsApi({ export const nxDocumentsApi = new DocumentsApi({
publicDocsRoot: 'nx-dev/nx-dev/public/documentation', publicDocsRoot: 'nx-dev/nx-dev/public/documentation',
documentSources: [ documentSources: [
documents.find( documents.content.find(
(x) => x.id === 'nx-documentation' (x) => x.id === 'nx-documentation'
) as Partial<DocumentMetadata>, ) as Partial<DocumentMetadata>,
documents.find( documents.content.find(
(x) => x.id === 'additional-api-references' (x) => x.id === 'additional-api-references'
) as Partial<DocumentMetadata>, ) as Partial<DocumentMetadata>,
] ]
@ -37,15 +37,15 @@ export const nxDocumentsApi = new DocumentsApi({
}); });
export const nxRecipesApi = new DocumentsApi({ export const nxRecipesApi = new DocumentsApi({
publicDocsRoot: 'nx-dev/nx-dev/public/documentation', publicDocsRoot: 'nx-dev/nx-dev/public/documentation',
documentSources: [documents.find((x) => x.id === 'nx-recipes')].filter( documentSources: [
(x) => !!x documents.content.find((x) => x.id === 'nx-recipes'),
) as DocumentMetadata[], ].filter((x) => !!x) as DocumentMetadata[],
addAncestor: { id: 'recipes', name: 'Recipes' }, addAncestor: { id: 'recipes', name: 'Recipes' },
}); });
export const nxCloudDocumentsApi = new DocumentsApi({ export const nxCloudDocumentsApi = new DocumentsApi({
publicDocsRoot: 'nx-dev/nx-dev/public/documentation', publicDocsRoot: 'nx-dev/nx-dev/public/documentation',
documentSources: [ documentSources: [
documents.find( documents.content.find(
(x) => x.id === 'nx-cloud-documentation' (x) => x.id === 'nx-cloud-documentation'
) as Partial<DocumentMetadata>, ) as Partial<DocumentMetadata>,
] ]

View File

@ -37,7 +37,7 @@ function filePathExtractor(file: any): string[] {
const mapPathList: string[] = readJsonSync(`${basePath}/map.json`, { const mapPathList: string[] = readJsonSync(`${basePath}/map.json`, {
encoding: 'utf8', encoding: 'utf8',
}) })
.map((file: any) => filePathExtractor(file)) .content.map((file: any) => filePathExtractor(file))
.flat(); .flat();
const readmeMissList = readmePathList.filter((x) => !mapPathList.includes(x)); const readmeMissList = readmePathList.filter((x) => !mapPathList.includes(x));
const mapMissList = mapPathList.filter((x) => !readmePathList.includes(x)); const mapMissList = mapPathList.filter((x) => !readmePathList.includes(x));

View File

@ -0,0 +1,67 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "documentation-map-schema",
"title": "JSON schema for documentation map",
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "Title of the document"
},
"description": {
"type": "string",
"description": "Description of the document"
},
"content": {
"type": "array",
"description": "Dictionary map section",
"items": {
"$ref": "#/definitions/entry"
}
}
},
"definitions": {
"entry": {
"type": "object",
"required": ["name", "id"],
"properties": {
"name": {
"type": "string",
"description": "Name for the current item"
},
"id": {
"type": "string",
"description": "Identifier for the current item"
},
"description": {
"type": "string",
"description": "Description for the item"
},
"file": {
"type": "string",
"description": "Path to the markdown file"
},
"tags": {
"type": "array",
"description": "Tags are used on nx.dev to link related piece of content together (e.g: Related Documentation)"
},
"path": {
"type": "string",
"description": "Custom path or URL to find the item on nx.dev"
},
"isExternal": {
"type": "boolean",
"description": "Is the path provided is external to nx.dev?"
},
"itemList": {
"type": "array",
"description": "Children for the item",
"items": {
"$ref": "#/definitions/entry"
}
}
},
"additionalProperties": false
}
}
}

View File

@ -2,7 +2,7 @@ import { Canvas, Image, SKRSContext2D } from '@napi-rs/canvas';
import { ensureDir, readFile, readJSONSync, writeFileSync } from 'fs-extra'; import { ensureDir, readFile, readJSONSync, writeFileSync } from 'fs-extra';
import { resolve } from 'path'; import { resolve } from 'path';
const mapJson = readJSONSync('./docs/map.json', 'utf8'); const mapJson = readJSONSync('./docs/map.json', 'utf8').content;
const documents: any[] = [ const documents: any[] = [
...mapJson.find((x) => x.id === 'nx-documentation')?.['itemList'], ...mapJson.find((x) => x.id === 'nx-documentation')?.['itemList'],

View File

@ -85,7 +85,7 @@ export function getPackageMetadataList(
/** /**
* Get all the custom overview information on each package if available * Get all the custom overview information on each package if available
*/ */
const additionalApiReferences: any = DocumentationMap.find( const additionalApiReferences: any = DocumentationMap.content.find(
(data) => data.id === 'additional-api-references' (data) => data.id === 'additional-api-references'
).itemList; ).itemList;