import { IConfigFile } from '@microsoft/api-extractor' ; import fs from 'fs-extra' ; import path from 'path' ; const { getPackages : getLernaPackages } = require ( '@lerna/project' ) ; /**
 * TypeScript definition for
 *  https export interface LernaPackage { /**
     * Package name
     */ name : string ; /**
     * Location of the package
     */ location : string ; /**
     * Root directory of the monorepo
     */ rootPath : string ; /**
     * Location of `package.json`
     */ manifestLocation : string ; /**
     * Is it a private package?
     */ private : boolean ; } example param name export function getUnscopedPackageName ( name ) { if ( name . startsWith ( '@' ) ) { return name . split ( '/' ) [ 1 ] ; } return name ; } param rootDir export async function getPackages ( rootDir = process . cwd ( ) ) { const packages = await getLernaPackages ( rootDir ) ; packages . sort ( ( p1 , p2 ) => p1 . location . localeCompare ( p2 . location ) ) ; return packages ; } param pkg export function shouldGenerateTsDocs ( pkg ) { if ( pkg . name === '@loopback/tsdocs' ) return true ; if ( pkg . private && pkg . name !== '@loopback/tsdocs' ) return false ; if ( pkg . name . startsWith ( '@loopback/example-' ) ) return false ; if ( ! fs . existsSync ( path . join ( pkg . location , 'tsconfig.build.json' ) ) && ! fs . existsSync ( path . join ( pkg . location , 'tsconfig.json' ) ) ) { return false ; } if ( ! fs . existsSync ( path . join ( pkg . location , 'dist/index.d.ts' ) ) ) return false ; return true ; } param rootDir export async function getPackagesWithTsDocs ( rootDir = process . cwd ( ) ) { const packages = await getPackages ( rootDir ) ; return packages . filter ( shouldGenerateTsDocs ) ; } /**
 * Default path for apidocs to be generated for loopback.io site
 */ export const DEFAULT_APIDOCS_GENERATION_PATH = 'docs/site/apidocs' ; /**
 * Options for api docs
 */ export interface ApiDocsOptions { /**
     * To have a dry-run without generating api reports/doc models
     */ dryRun ? : boolean ; /**
     * If `true`, do not print messages to console
     */ silent ? : boolean ; /**
     * Root directory for the lerna-managed monorepo, default to current dir
     */ rootDir ? : string ; /**
     * Path to tsdocs reports/models
     */ apiDocsExtractionPath ? : string ; /**
     * Path to target directory to generate apidocs
     */ apiDocsGenerationPath ? : string ; /**
     * A flag to generate default package documentation
     */ generateDefaultPackageDoc ? : boolean ; /**
     * Package metadata
     */ lernaPackages ? : Record < string , LernaPackage > ; } /**
 * Options to run api-extractor against the lerna repo
 */ export interface ExtractorOptions extends ApiDocsOptions { /**
     * Configuration for api-extractor
     */ config ? : IConfigFile ; /**
     * Custom TypeScript compiler dir
     */ typescriptCompilerFolder ? : string ; /**
     * Path for tsconfig
     */ tsconfigFilePath ? : string ; /**
     * mainEntryPointFilePath
     */ mainEntryPointFilePath ? : string ; /**
     * A flag to control if `apiReport` should be enabled
     */ apiReportEnabled ? : boolean ; /**
     * A flag to control if errors should be ignored
     */ ignoreErrors ? : boolean ; } /**
 * Default path as the output directory for extracted api reports and models
 */ export const DEFAULT_APIDOCS_EXTRACTION_PATH = 'docs/apidocs' ; /**
 * Export the TypeScript path from `@loopback/build`
 */ export const typeScriptPath = require ( '@loopback/build' ) . typeScriptPath ;