Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Global = 0, ExternalModule = 1
if (
node.kind === ReflectionKind.Global ||
node.kind === ReflectionKind.ExternalModule
) {
let children = node.children;
if (children && children.length > 0) {
children.forEach(function(child) {
findConstructs(child, files, node);
});
}
} else {
if (
(node.kind === ReflectionKind.Class ||
node.kind === ReflectionKind.Interface ||
node.kind === ReflectionKind.TypeAlias ||
node.kind === ReflectionKind.ObjectLiteral ||
node.kind === ReflectionKind.Module ||
node.kind === ReflectionKind.Variable ||
node.kind === ReflectionKind.Enum ||
node.kind === ReflectionKind.Function) &&
node.flags.isExported &&
files.find(
filePath =>
node.sources != null &&
node.sources[0].fileName.split('/').pop() ===
filePath.split('/').pop()
)
) {
if (parent && parent.kind === ReflectionKind.Module) {
// Set the node name with its parent namespace
node.name = parent ? parent.name + '.' + node.name : node.name;
// Global = 0, ExternalModule = 1
if (
node.kind === ReflectionKind.Global ||
node.kind === ReflectionKind.ExternalModule
) {
let children = node.children;
if (children && children.length > 0) {
children.forEach(function(child) {
findConstructs(child, files, node);
});
}
} else {
if (
(node.kind === ReflectionKind.Class ||
node.kind === ReflectionKind.Interface ||
node.kind === ReflectionKind.TypeAlias ||
node.kind === ReflectionKind.ObjectLiteral ||
node.kind === ReflectionKind.Module ||
node.kind === ReflectionKind.Variable ||
node.kind === ReflectionKind.Enum ||
node.kind === ReflectionKind.Function) &&
node.flags.isExported &&
files.find(
filePath =>
node.sources[0].fileName.split('/').pop() ===
filePath.split('/').pop(),
)
) {
if (parent && parent.kind === ReflectionKind.Module) {
// Set the node name with its parent namespace
node.name = parent ? parent.name + '.' + node.name : node.name;
}
// 构建包
_.exec(`typedoc --ignoreCompilerErrors --excludeNotExported --excludePrivate --excludeProtected --json ${typedocDataFile} --mode file src/index.ts`)
// 创建文档
const list = (await fs.readJSON(typedocDataFile)).children as Item[]
const listByKind = groupBy(list, item => item.kind)
const briefListByKind: Record = {} as any
const readMeFlagByKind: Partial> = {
[ReflectionKind.Function]: '工具函数',
[ReflectionKind.Class]: '工具类',
[ReflectionKind.TypeAlias]: '工具类型',
}
const contentItemCountPerLineByKind: Partial> = {
[ReflectionKind.Function]: 4,
[ReflectionKind.Class]: 3,
[ReflectionKind.TypeAlias]: 9,
}
let readme = (await fs.readFile(readMeFile)).toString()
forOwn(listByKind, (list, kind) => {
switch (Number(kind)) {
case ReflectionKind.Function:
list.forEach(item => {
(briefListByKind[kind] || (briefListByKind[kind] = [])).push({
name: item.name,
body: (item.signatures || []).map(signature => {
const desc = getDesc(signature)
const example = getExample(signature)
return dedent`
${desc}
export function memberSymbol(this: DeclarationReflection) {
const isStatic = this.flags.map(flag => flag).includes('Static');
const symbol = '•';
if (this.kind === ReflectionKind.ConstructorSignature) {
return '\\+';
}
if (this.kind === ReflectionKind.CallSignature) {
return '▸';
}
if (this.kind === ReflectionKind.TypeAlias) {
return 'Ƭ';
}
if (this.kind === ReflectionKind.ObjectLiteral) {
return '▪';
}
if (this.kind === ReflectionKind.Property && isStatic) {
return '▪';
}
return symbol;
}