diff --git a/scripts/documentation/documentation.ts b/scripts/documentation/documentation.ts index dda8ed0bca3c9..931f77b7a19a7 100644 --- a/scripts/documentation/documentation.ts +++ b/scripts/documentation/documentation.ts @@ -53,13 +53,3 @@ function checkDocumentation() { } generate().then(() => checkDocumentation()); - -function printInfo( - str: string, - newLine: boolean = true, - newLineAfter: boolean = true -) { - console.log( - `${newLine ? '\n' : ''}${chalk.blue('i')} ${str}${newLineAfter ? '\n' : ''}` - ); -} diff --git a/scripts/documentation/schema-flattener.ts b/scripts/documentation/schema-flattener.ts index 1bb66cc0cc886..eb2ebfa22cdd5 100644 --- a/scripts/documentation/schema-flattener.ts +++ b/scripts/documentation/schema-flattener.ts @@ -1,71 +1,5 @@ -import { deepCopy, json, schema } from '@angular-devkit/core'; -import { visitJsonSchema } from '@angular-devkit/core/src/json/schema'; -import * as Ajv from 'ajv'; -import * as Url from 'url'; +import { json } from '@angular-devkit/core'; export interface SchemaFlattener { 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; - }, - }; -} diff --git a/scripts/documentation/utils.ts b/scripts/documentation/utils.ts index 19750bbab6efc..1c442091894fa 100644 --- a/scripts/documentation/utils.ts +++ b/scripts/documentation/utils.ts @@ -1,4 +1,4 @@ -import { outputFileSync, readJsonSync } from 'fs-extra'; +import { outputFileSync } from 'fs-extra'; import { join } from 'path'; import { format, resolveConfig } from 'prettier'; @@ -65,31 +65,6 @@ export async function formatWithPrettier(filePath: string, content: string) { 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( description: string, deprecated: boolean | string