From 72754770282135c9ebe87e3b0051f4770f5a6932 Mon Sep 17 00:00:00 2001 From: Enlcxx Date: Thu, 22 Dec 2022 10:50:50 -0500 Subject: [PATCH] fix some bugs --- package.json | 4 +-- ...rate-api-docs.ts => generate-api-docs.mts} | 25 ++++++++++--------- .../{highlight.ts => highlight.mts} | 0 .../src/utils/{hash-code.ts => hash-code.mts} | 0 4 files changed, 15 insertions(+), 14 deletions(-) rename tools/src/{generate-api-docs.ts => generate-api-docs.mts} (95%) rename tools/src/html-loader/{highlight.ts => highlight.mts} (100%) rename tools/src/utils/{hash-code.ts => hash-code.mts} (100%) diff --git a/package.json b/package.json index d4141f6ab..01e664f01 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ "tools:bump": "ts-node tools/*/bump-version && yarn changelog", "tools:bump-nightly": "ts-node tools/src/bump-version --nightly", "tools:deploy": "ts-node tools/src/deploy", - "tools:docs-api": "ts-node --esm --project ./tools/tsconfig.tn.json tools/src/generate-api-docs.ts", - "watch-docs": "ts-node --esm --project ./tools/tsconfig.tn.json ./tools/src/markdown-to-html/markdown-to-html", + "tools:docs-api": "ts-node --esm --project ./tools/tsconfig.tn.json ./tools/src/generate-api-docs.mts", + "watch-docs": "ts-node --esm --project ./tools/tsconfig.tn.json ./tools/src/markdown-to-html/markdown-to-html.mts", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", "serve:lib": "hs dist/docs-content -p 1212 -g --cors 'Access-Control-Allow-Origin' -c0", "build:schematics": "tsc -p src/lib/schematics/tsconfig.json && cp -r src/lib/schematics/ dist/@alyle/ui/ && rm -rf dist/@alyle/ui/schematics/**/*.ts", diff --git a/tools/src/generate-api-docs.ts b/tools/src/generate-api-docs.mts similarity index 95% rename from tools/src/generate-api-docs.ts rename to tools/src/generate-api-docs.mts index d991f6ef2..ac3bf3f6d 100644 --- a/tools/src/generate-api-docs.ts +++ b/tools/src/generate-api-docs.mts @@ -1,11 +1,11 @@ -import * as ts from 'typescript'; +import ts from 'typescript'; import * as path from 'path'; import * as fs from 'fs'; import chalk from 'chalk'; import { Application, TypeDocReader, TSConfigReader, ProjectReflection, DeclarationReflection, Reflection } from 'typedoc'; -import { highlight } from './html-loader/highlight'; -import { hashCode } from './utils/hash-code'; +import { highlight } from './html-loader/highlight.mjs'; +import { hashCode } from './utils/hash-code.mjs'; const { readFile, mkdir, writeFile } = fs.promises; interface PkgSymbol { @@ -56,9 +56,9 @@ async function render() { if (!child.children) { continue; } - let pkgName = child.sources![0].fileName.replace(/src\/lib/, '@alyle/ui'); + let pkgName = child.sources![0]!.fileName.replace(/src\/lib/, '@alyle/ui'); pkgName = path.dirname(pkgName); - console.log(child.sources![0].fileName); + console.log(child.sources![0]!.fileName); pkgName = pkgName.endsWith('/') ? pkgName.slice(0, -1) : pkgName; console.log(chalk.greenBright(`\nPackage: ${pkgName}`)); let API = APIList.find(api => api.pkg === pkgName); @@ -74,19 +74,19 @@ async function render() { APIList.push(API); } for (const _child of child.children) { - const file = _child.sources![0].fileName; + const file = _child.sources![0]!.fileName; const { name, decorators, kindString } = _child; const type = decorators - ? decorators[0].name + ? decorators[0]!.name : (kindString! === 'Variable' ? 'Const' : kindString!); const symbol = hasTag(_child, 'decorator') ? 'Decorator' : decorators - ? decorators[0].name + ? decorators[0]!.name : _child.flags.isConst ? 'Const' : (kindString! === 'Variable' ? 'Const' : kindString!); - const Type = `${toCamelcase(type)}List`; + // const Type = `${toCamelcase(type)}List`; if ( !checkIfContainTagPrivate(_child) && !hasTag(_child, 'docsPrivate') && !name.startsWith('_') ) { @@ -206,6 +206,7 @@ async function render() { await generateJson(); await render(); })().catch((error) => { + console.log(error); throw new Error(error); }); @@ -217,7 +218,7 @@ function groupBy(xs: T[], key: string): { key: string, items: T[]}[] { items: [] }) as true /** <-- This always returns true, since an item is never removed */) && rv[rv.length - 1]); - item.items.push(x); + item!.items.push(x); return rv; }, [] as { key: string, items: T[]}[]); } @@ -256,7 +257,7 @@ function toCamelcase(str: string) { function hasTag(refl: DeclarationReflection, tag: string): boolean { const comment: Reflection['comment'] = refl.comment - || (refl['signatures'] && refl['signatures'].length ? refl['signatures'][0].comment : undefined); + || (refl['signatures'] && refl['signatures'].length ? refl['signatures'][0]!.comment : undefined); if (comment && comment.tags) { return comment.tags.some((_: any) => _.tag === tag); } else { @@ -266,7 +267,7 @@ function hasTag(refl: DeclarationReflection, tag: string): boolean { function checkIfContainTagPrivate(refl: DeclarationReflection): boolean { const comment: Reflection['comment'] = refl.comment - || (refl['signatures'] && refl['signatures'].length ? refl['signatures'][0].comment : undefined); + || (refl['signatures'] && refl['signatures'].length ? refl['signatures'][0]!.comment : undefined); if (comment && comment.tags) { return comment.tags.some((_: any) => _.tag === 'docs-private'); } else { diff --git a/tools/src/html-loader/highlight.ts b/tools/src/html-loader/highlight.mts similarity index 100% rename from tools/src/html-loader/highlight.ts rename to tools/src/html-loader/highlight.mts diff --git a/tools/src/utils/hash-code.ts b/tools/src/utils/hash-code.mts similarity index 100% rename from tools/src/utils/hash-code.ts rename to tools/src/utils/hash-code.mts