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AAsC;gBACtC,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;oBACzC,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC;iBACpB;qBAAM;oBACL,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC;iBACrB;aACF;SACF;KACF;SAAM,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACjC,2BAA2B;QAC3B,eAAe;QACf,8DAA8D;QAC9D,MAAM,GAAG,GAA+B,MAAA,gBAAgB,CAAC,UAAU,0CAAE,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YACjF,OAAO,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC;QAC3B,CAAC,CAAC,CAAC;QACH,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE;YACnB,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC;SACnB;KACF;IACD,YAAY;IACZ,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5D,MAAM,QAAQ,GAAW,mCAAmC,CAAC;IAE7D,OAAO,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;AACvD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type {\n IYamlItem,\n IYamlApiFile,\n IYamlSyntax,\n IYamlReferenceSpec,\n IYamlReference\n} from '../yaml/IYamlApiFile';\nimport type {\n PackageYamlModel,\n EnumYamlModel,\n TypeAliasYamlModel,\n TypeYamlModel,\n FieldYamlModel,\n FunctionYamlModel,\n CommonYamlModel\n} from '../yaml/ISDPYamlFile';\nimport path from 'path';\nimport { FileSystem, Encoding, NewlineKind } from '@rushstack/node-core-library';\nimport yaml = require('js-yaml');\n\nexport function convertUDPYamlToSDP(folderPath: string): void {\n convert(folderPath, folderPath);\n}\n\nfunction convert(inputPath: string, outputPath: string): void {\n console.log();\n if (!FileSystem.exists(inputPath)) {\n console.error(`input path: ${inputPath} is not exist`);\n return;\n }\n\n FileSystem.readFolderItemNames(inputPath).forEach((name) => {\n const fpath: string = path.join(inputPath, name);\n if (FileSystem.getStatistics(fpath).isFile()) {\n // only convert yaml\n if (!name.endsWith('.yml')) {\n return;\n }\n // parse file\n const yamlContent: string = FileSystem.readFile(fpath, { encoding: Encoding.Utf8 });\n // only convert universalreference yaml\n const isLegacyYaml: boolean = yamlContent.startsWith('### YamlMime:UniversalReference');\n if (!isLegacyYaml) {\n return;\n }\n\n console.log(`convert file ${fpath} from udp to sdp`);\n\n const file: IYamlApiFile = yaml.safeLoad(yamlContent) as IYamlApiFile;\n const result: { model: CommonYamlModel; type: string } | undefined = convertToSDP(file);\n if (result && result.model) {\n const stringified: string = `### YamlMime:TS${result.type}\\n${yaml.safeDump(result.model, {\n lineWidth: 120\n })}`;\n FileSystem.writeFile(`${outputPath}/${name}`, stringified, {\n convertLineEndings: NewlineKind.CrLf,\n ensureFolderExists: true\n });\n } else {\n console.log('not target file ', fpath);\n }\n } else {\n // read contents\n convert(fpath, path.join(outputPath, name));\n }\n });\n}\n\nfunction convertToPackageSDP(transfomredClass: IYamlApiFile): PackageYamlModel {\n const element: IYamlItem = transfomredClass.items[0];\n const packageModel: PackageYamlModel = {\n uid: element.uid,\n name: element.name!,\n type: 'package'\n };\n if (element.summary) {\n packageModel.summary = element.summary;\n } else {\n packageModel.summary = '';\n }\n\n // search in children\n if (element.children) {\n element.children.forEach((child) => {\n if (child.endsWith(':class')) {\n assignPackageModelFields(packageModel, 'classes', child);\n } else if (child.endsWith(':interface')) {\n assignPackageModelFields(packageModel, 'interfaces', child);\n } else if (child.endsWith(':enum')) {\n assignPackageModelFields(packageModel, 'enums', child);\n } else if (child.endsWith(':type')) {\n assignPackageModelFields(packageModel, 'typeAliases', child);\n } else {\n // console.log(\"other type: \", child)\n }\n });\n }\n\n for (let i: number = 1; i < transfomredClass.items.length; i++) {\n const ele: IYamlItem = transfomredClass.items[i];\n switch (ele.type) {\n case 'typealias':\n // need generate typeAlias file for this\n break;\n case 'function':\n if (!packageModel.functions) {\n packageModel.functions = [];\n }\n packageModel.functions.push(convertToFunctionSDP(ele, element.uid, transfomredClass));\n break;\n default:\n // console.log(transfomredClass.items[0].name)\n console.log('[warning] not applied type(package): ', ele.type);\n }\n }\n\n return packageModel;\n}\n\nfunction assignPackageModelFields(\n packageModel: PackageYamlModel,\n name: 'classes' | 'interfaces' | 'enums' | 'typeAliases',\n uid: string\n): void {\n if (!packageModel[name]) {\n packageModel[name] = [];\n }\n packageModel[name]!.push(uid);\n}\n\nfunction convertToSDP(transfomredClass: IYamlApiFile): { model: CommonYamlModel; type: string } | undefined {\n const element: IYamlItem = transfomredClass.items[0];\n switch (element.type) {\n case 'class':\n case 'interface':\n return {\n model: convertToTypeSDP(transfomredClass, element.type === 'class'),\n type: 'Type'\n };\n case 'enum':\n if (transfomredClass.items.length < 2) {\n console.log(`[warning] enum ${element.uid}/${element.name} does not have fields`);\n return undefined;\n }\n return { model: convertToEnumSDP(transfomredClass), type: 'Enum' };\n case 'typealias':\n return { model: convertToTypeAliasSDP(element, transfomredClass), type: 'TypeAlias' };\n case 'package':\n return {\n model: convertToPackageSDP(transfomredClass),\n type: 'Package'\n };\n default:\n console.log('not applied type: ', element.type);\n return undefined;\n }\n}\n\nfunction convertToEnumSDP(transfomredClass: IYamlApiFile): EnumYamlModel {\n const element: IYamlItem = transfomredClass.items[0];\n const fields: FieldYamlModel[] = [];\n for (let i: number = 1; i < transfomredClass.items.length; i++) {\n const ele: IYamlItem = transfomredClass.items[i];\n const field: FieldYamlModel = {\n name: ele.name!,\n uid: ele.uid,\n package: element.package!\n };\n\n if (ele.summary) {\n field.summary = ele.summary;\n } else {\n field.summary = '';\n }\n\n if (ele.numericValue) {\n field.value = ele.numericValue;\n }\n fields.push(field);\n }\n\n const result: EnumYamlModel = {\n ...convertCommonYamlModel(element, element.package!, transfomredClass),\n fields: fields\n };\n return result;\n}\n\nfunction convertToTypeAliasSDP(element: IYamlItem, transfomredClass: IYamlApiFile): TypeAliasYamlModel {\n const result: TypeAliasYamlModel = {\n ...convertCommonYamlModel(element, element.package!, transfomredClass)\n } as TypeAliasYamlModel;\n\n if (element.syntax) {\n result.syntax = element.syntax.content!;\n }\n return result;\n}\n\nfunction convertToTypeSDP(transfomredClass: IYamlApiFile, isClass: boolean): TypeYamlModel {\n const element: IYamlItem = transfomredClass.items[0];\n const constructors: CommonYamlModel[] = [];\n const properties: CommonYamlModel[] = [];\n const methods: CommonYamlModel[] = [];\n const events: CommonYamlModel[] = [];\n for (let i: number = 1; i < transfomredClass.items.length; i++) {\n const ele: IYamlItem = transfomredClass.items[i];\n const item: CommonYamlModel = convertCommonYamlModel(ele, element.package!, transfomredClass);\n if (ele.type === 'constructor') {\n // interface does not need this field\n if (isClass) {\n constructors.push(item);\n }\n } else if (ele.type === 'property') {\n properties.push(item);\n } else if (ele.type === 'method') {\n methods.push(item);\n } else if (ele.type === 'event') {\n events.push(item);\n } else {\n console.log(`[warning] ${ele.uid}#${ele.name} is not applied sub type ${ele.type} for type yaml`);\n }\n }\n const result: TypeYamlModel = {\n ...convertCommonYamlModel(element, element.package!, transfomredClass),\n type: isClass ? 'class' : 'interface'\n };\n delete result.syntax;\n\n if (constructors.length > 0) {\n result.constructors = constructors;\n }\n\n if (properties.length > 0) {\n result.properties = properties;\n }\n\n if (methods.length > 0) {\n result.methods = methods;\n }\n\n if (events.length > 0) {\n result.events = events;\n }\n\n if (element.extends && element.extends.length > 0) {\n result.extends = convertSelfTypeToXref(element.extends[0] as string, transfomredClass);\n }\n return result;\n}\n\nfunction convertToFunctionSDP(\n element: IYamlItem,\n packageName: string,\n transfomredClass: IYamlApiFile\n): FunctionYamlModel {\n const model: CommonYamlModel = convertCommonYamlModel(element, packageName, transfomredClass);\n // don't need these fields\n delete model.fullName;\n return model;\n}\n\nfunction convertCommonYamlModel(\n element: IYamlItem,\n packageName: string,\n transfomredClass: IYamlApiFile\n): CommonYamlModel {\n const result: CommonYamlModel = {\n name: element.name!,\n uid: element.uid,\n package: packageName\n };\n\n if (element.fullName) {\n result.fullName = element.fullName;\n }\n\n if (element.summary) {\n result.summary = element.summary;\n } else {\n result.summary = '';\n }\n\n // because mustache meet same variable in different level\n // such as: { \"pre\": true, \"list\": [{}]}\n // if item in list wants to use pre but the pre is not assigned, it will use outer pre field.\n // so, there need to set below variable explict\n\n if (element.remarks) {\n result.remarks = element.remarks;\n } else {\n result.remarks = '';\n }\n\n if (element.example) {\n result.example = element.example;\n } else {\n result.example = [];\n }\n\n result.isPreview = element.isPreview;\n if (!result.isPreview) {\n result.isPreview = false;\n }\n\n if (element.deprecated) {\n result.isDeprecated = true;\n result.customDeprecatedMessage = element.deprecated.content;\n } else {\n result.isDeprecated = false;\n }\n\n if (element.syntax) {\n result.syntax = {};\n\n const syntax: IYamlSyntax = element.syntax;\n result.syntax.content = syntax.content;\n if (syntax.parameters && syntax.parameters.length > 0) {\n syntax.parameters?.forEach((it) => {\n delete it.optional;\n delete it.defaultValue;\n });\n result.syntax.parameters = syntax.parameters.map((it) => {\n return {\n ...it,\n id: it.id!,\n type: convertSelfTypeToXref(escapeMarkdown(it.type![0] as string), transfomredClass)\n };\n });\n }\n\n if (syntax.return) {\n result.syntax.return = {\n ...syntax.return,\n type: convertSelfTypeToXref(escapeMarkdown(syntax.return.type![0] as string), transfomredClass)\n };\n }\n }\n\n return result;\n}\n\nfunction escapeMarkdown(name: string): string {\n // eg: [key: string]: string\n const markdownLinkRegEx: RegExp = /^\\s*(\\[.+\\]):(.+)/g;\n return name.replace(markdownLinkRegEx, `$1\\\\:$2`);\n}\n\nfunction convertSelfTypeToXref(name: string, transfomredClass: IYamlApiFile): string {\n let result: string = name;\n\n // if complex type, need to get real type from references\n if (result.endsWith(':complex')) {\n const specs: IYamlReferenceSpec[] | undefined = transfomredClass.references?.find((item) => {\n return item.uid === name;\n })?.['spec.typeScript'];\n\n if (specs && specs.length > 0) {\n result = '';\n for (const spec of specs) {\n // start with ! will be node base type\n if (spec.uid && !spec.uid.startsWith('!')) {\n result += spec.uid;\n } else {\n result += spec.name;\n }\n }\n }\n } else if (result.startsWith('!')) {\n // uid: '!Object:interface'\n // name: Object\n // start with !, not complex type, use reference name directly\n const ref: IYamlReference | undefined = transfomredClass.references?.find((item) => {\n return item.uid === name;\n });\n if (ref && ref.name) {\n result = ref.name;\n }\n }\n // parse < >\n result = result.replace(/</g, '<').replace(/>/g, '>');\n const uidRegEx: RegExp = /(@?[\\w\\d\\-/!~\\.]+\\:[\\w\\d\\-\\(/]+)/g;\n\n return result.replace(uidRegEx, `<xref uid=\"$1\" />`);\n}\n"]} |