docs(nxdev): cleanup documentation code generator (#13829)

This commit is contained in:
Benjamin Cabanes 2022-12-14 15:05:52 -05:00 committed by GitHub
parent dfd347cd39
commit c461488f4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 103 deletions

View File

@ -53,13 +53,3 @@ function checkDocumentation() {
} }
generate().then(() => checkDocumentation()); generate().then(() => checkDocumentation());
function printInfo(
str: string,
newLine: boolean = true,
newLineAfter: boolean = true
) {
console.log(
`${newLine ? '\n' : ''}${chalk.blue('i')} ${str}${newLineAfter ? '\n' : ''}`
);
}

View File

@ -1,71 +1,5 @@
import { deepCopy, json, schema } from '@angular-devkit/core'; import { json } from '@angular-devkit/core';
import { visitJsonSchema } from '@angular-devkit/core/src/json/schema';
import * as Ajv from 'ajv';
import * as Url from 'url';
export interface SchemaFlattener { export interface SchemaFlattener {
flatten: (schema) => json.JsonObject; flatten: (schema) => json.JsonObject;
} }
function _resolver(
ref: string,
validate?: Ajv.ValidateFunction
): { context?: Ajv.ValidateFunction; schema?: json.JsonObject } {
if (!validate || !ref) {
return {};
}
const schema = (validate as any).schemaEnv.root.schema;
const id = typeof schema === 'object' ? schema.$id : null;
let fullReference = ref;
if (typeof id === 'string') {
fullReference = Url.resolve(id, ref);
if (ref.startsWith('#')) {
fullReference = id + fullReference;
}
}
if (fullReference.startsWith('#')) {
fullReference = fullReference.slice(0, -1);
}
const resolvedSchema = this._ajv.getSchema(fullReference);
return {
context: resolvedSchema?.schemaEnv.validate,
schema: resolvedSchema?.schema as json.JsonObject,
};
}
export function createSchemaFlattener(
formats: schema.SchemaFormat[] = []
): SchemaFlattener {
const ajv = new Ajv({ passContext: true });
for (const format of formats) {
ajv.addFormat(format.name, format.formatter as any);
}
return {
flatten: function (schema) {
const validate = ajv.removeSchema(schema).compile(schema);
function visitor(current, pointer, parentSchema, index) {
if (
current &&
parentSchema &&
index &&
json.isJsonObject(current) &&
current.hasOwnProperty('$ref') &&
typeof current['$ref'] == 'string'
) {
const resolved = _resolver(current['$ref'], validate);
if (resolved.schema) {
parentSchema[index] = resolved.schema;
}
}
}
const schemaCopy = deepCopy(validate.schema) as json.JsonObject;
visitJsonSchema(schemaCopy, visitor);
return schemaCopy;
},
};
}

View File

@ -1,4 +1,4 @@
import { outputFileSync, readJsonSync } from 'fs-extra'; import { outputFileSync } from 'fs-extra';
import { join } from 'path'; import { join } from 'path';
import { format, resolveConfig } from 'prettier'; import { format, resolveConfig } from 'prettier';
@ -65,31 +65,6 @@ export async function formatWithPrettier(filePath: string, content: string) {
return format(content, options); return format(content, options);
} }
export function getNxPackageDependencies(packageJsonPath: string): {
name: string;
dependencies: string[];
peerDependencies: string[];
} {
const packageJson = readJsonSync(packageJsonPath);
if (!packageJson) {
console.log(`No package.json found at: ${packageJsonPath}`);
return null;
}
return {
name: packageJson.name,
dependencies: packageJson.dependencies
? Object.keys(packageJson.dependencies).filter((item) =>
item.includes('@nrwl')
)
: [],
peerDependencies: packageJson.peerDependencies
? Object.keys(packageJson.peerDependencies).filter((item) =>
item.includes('@nrwl')
)
: [],
};
}
export function formatDeprecated( export function formatDeprecated(
description: string, description: string,
deprecated: boolean | string deprecated: boolean | string