diff --git a/libs/multi-entrypoint/one/README.md b/libs/multi-entrypoint/one/README.md new file mode 100644 index 0000000..c4ad09a --- /dev/null +++ b/libs/multi-entrypoint/one/README.md @@ -0,0 +1,3 @@ +# @multi/one + +Secondary entry point of `@multi`. It can be used by importing from `@multi/one`. diff --git a/libs/multi-entrypoint/one/ng-package.json b/libs/multi-entrypoint/one/ng-package.json new file mode 100644 index 0000000..c781f0d --- /dev/null +++ b/libs/multi-entrypoint/one/ng-package.json @@ -0,0 +1,5 @@ +{ + "lib": { + "entryFile": "src/index.ts" + } +} diff --git a/libs/multi-entrypoint/one/src/index.ts b/libs/multi-entrypoint/one/src/index.ts new file mode 100644 index 0000000..239b18f --- /dev/null +++ b/libs/multi-entrypoint/one/src/index.ts @@ -0,0 +1,3 @@ + +export * from './lib/one.module'; + diff --git a/libs/multi-entrypoint/one/src/lib/one.module.ts b/libs/multi-entrypoint/one/src/lib/one.module.ts new file mode 100644 index 0000000..7ca9c11 --- /dev/null +++ b/libs/multi-entrypoint/one/src/lib/one.module.ts @@ -0,0 +1,7 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +@NgModule({ + imports: [CommonModule], +}) +export class OneModule {} diff --git a/libs/multi-entrypoint/package.json b/libs/multi-entrypoint/package.json index 63694f6..5129f71 100644 --- a/libs/multi-entrypoint/package.json +++ b/libs/multi-entrypoint/package.json @@ -1,5 +1,5 @@ { - "name": "@multi", + "name": "@multi/test", "version": "0.0.1", "peerDependencies": { "@angular/common": "^13.2.0", diff --git a/libs/multi-entrypoint/project.json b/libs/multi-entrypoint/project.json index 4e2765e..f30cb2a 100644 --- a/libs/multi-entrypoint/project.json +++ b/libs/multi-entrypoint/project.json @@ -37,7 +37,13 @@ "options": { "lintFilePatterns": [ "libs/multi-entrypoint/src/**/*.ts", - "libs/multi-entrypoint/src/**/*.html" + "libs/multi-entrypoint/src/**/*.html", + "libs/multi-entrypoint/one/**/*.ts", + "libs/multi-entrypoint/one/**/*.html", + "libs/multi-entrypoint/two/**/*.ts", + "libs/multi-entrypoint/two/**/*.html", + "libs/multi-entrypoint/three/**/*.ts", + "libs/multi-entrypoint/three/**/*.html" ] } }, diff --git a/libs/multi-entrypoint/three/README.md b/libs/multi-entrypoint/three/README.md new file mode 100644 index 0000000..893b868 --- /dev/null +++ b/libs/multi-entrypoint/three/README.md @@ -0,0 +1,3 @@ +# @multi/three + +Secondary entry point of `@multi`. It can be used by importing from `@multi/three`. diff --git a/libs/multi-entrypoint/three/ng-package.json b/libs/multi-entrypoint/three/ng-package.json new file mode 100644 index 0000000..c781f0d --- /dev/null +++ b/libs/multi-entrypoint/three/ng-package.json @@ -0,0 +1,5 @@ +{ + "lib": { + "entryFile": "src/index.ts" + } +} diff --git a/libs/multi-entrypoint/three/src/index.ts b/libs/multi-entrypoint/three/src/index.ts new file mode 100644 index 0000000..5013962 --- /dev/null +++ b/libs/multi-entrypoint/three/src/index.ts @@ -0,0 +1,3 @@ + +export * from './lib/three.module'; + diff --git a/libs/multi-entrypoint/three/src/lib/three.module.ts b/libs/multi-entrypoint/three/src/lib/three.module.ts new file mode 100644 index 0000000..9c9b350 --- /dev/null +++ b/libs/multi-entrypoint/three/src/lib/three.module.ts @@ -0,0 +1,7 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +@NgModule({ + imports: [CommonModule], +}) +export class ThreeModule {} diff --git a/libs/multi-entrypoint/two/README.md b/libs/multi-entrypoint/two/README.md new file mode 100644 index 0000000..e73ccfd --- /dev/null +++ b/libs/multi-entrypoint/two/README.md @@ -0,0 +1,3 @@ +# @multi/two + +Secondary entry point of `@multi`. It can be used by importing from `@multi/two`. diff --git a/libs/multi-entrypoint/two/ng-package.json b/libs/multi-entrypoint/two/ng-package.json new file mode 100644 index 0000000..c781f0d --- /dev/null +++ b/libs/multi-entrypoint/two/ng-package.json @@ -0,0 +1,5 @@ +{ + "lib": { + "entryFile": "src/index.ts" + } +} diff --git a/libs/multi-entrypoint/two/src/index.ts b/libs/multi-entrypoint/two/src/index.ts new file mode 100644 index 0000000..0e45b1e --- /dev/null +++ b/libs/multi-entrypoint/two/src/index.ts @@ -0,0 +1,3 @@ + +export * from './lib/two.module'; + diff --git a/libs/multi-entrypoint/two/src/lib/two.module.ts b/libs/multi-entrypoint/two/src/lib/two.module.ts new file mode 100644 index 0000000..ce31a7c --- /dev/null +++ b/libs/multi-entrypoint/two/src/lib/two.module.ts @@ -0,0 +1,7 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +@NgModule({ + imports: [CommonModule], +}) +export class TwoModule {} diff --git a/libs/ngx-doc-gen/package.json b/libs/ngx-doc-gen/package.json index 434397f..2b806db 100644 --- a/libs/ngx-doc-gen/package.json +++ b/libs/ngx-doc-gen/package.json @@ -38,7 +38,8 @@ "fast-glob": "^3.2.11", "fs-extra": "^10.1.0", "highlight.js": "^11.5.1", - "jsonc-parser": "^3.0.0" + "jsonc-parser": "^3.0.0", + "ng-packagr": ">= 13.0.0" }, "ng-add": { "save": "devDependencies" diff --git a/libs/ngx-doc-gen/src/generate/dgeni-engine.ts b/libs/ngx-doc-gen/src/generate/dgeni-engine.ts index c16cc27..9d6836e 100644 --- a/libs/ngx-doc-gen/src/generate/dgeni-engine.ts +++ b/libs/ngx-doc-gen/src/generate/dgeni-engine.ts @@ -1,10 +1,10 @@ import { Dgeni, Package } from 'dgeni'; import { ReadTypeScriptModules } from 'dgeni-packages/typescript/processors/readTypeScriptModules'; import { TsParser } from 'dgeni-packages/typescript/services/TsParser'; +import { discoverPackages } from 'ng-packagr/lib/ng-package/discover-packages'; import * as path from 'canonical-path'; import { HighlightNunjucksExtension } from '../extensions/nunjucks'; -import { NgPackage } from '../interfaces/ng-package'; import { AsyncFunctionsProcessor } from '../processors/async-functions'; import { categorizer } from '../processors/categorizer'; import { DocsPrivateFilter } from '../processors/docs-private-filter'; @@ -15,18 +15,24 @@ import { MergeInheritedProperties, mergeInheritedProperties } from '../processor import { ResolveInheritedDocs, resolveInheritedDocs } from '../processors/resolve-inherited-docs'; import { NgxDocGenOptions } from '../schema/ngx-doc-gen.options'; import { LogLevel } from '../types/log-level'; -import { discoverNgPackage } from '../utils/discovery'; import { collectEntrypoints, createDgeniPackage } from '../utils/package-utils'; import { patchLogService } from '../utils/patch-log-service'; +import { NgPackage } from 'ng-packagr/lib/ng-package/package'; export const generate = async (options: NgxDocGenOptions, workingDirectory: string, projectRoot: string): Promise => { - const ngPackage = await discoverNgPackage(workingDirectory, projectRoot); + let projectPath = path.join(workingDirectory, projectRoot); + projectPath = path.isAbsolute(projectPath) ? projectPath : path.resolve(projectPath); + + const ngPackage = await discoverPackages({ + project: projectPath + }); + return await generateDocumentation(ngPackage, workingDirectory, options); }; const generateDocumentation = async (ngPackge: NgPackage, workingDirectory: string, options: NgxDocGenOptions): Promise => { - const outputDir = path.join(workingDirectory, options.outputPath); - const dgeniPackage = createDgeniPackage(ngPackge.packageName); + const outputDir = path.join(workingDirectory, options.outputPath) + const dgeniPackage = createDgeniPackage(ngPackge.primary.moduleId); setProcessors(dgeniPackage); @@ -42,7 +48,7 @@ const generateDocumentation = async (ngPackge: NgPackage, workingDirectory: stri return await new Dgeni([dgeniPackage]) .generate() - .then(() => ngPackge.packageName); + .then(() => ngPackge.primary.moduleId); }; /** @@ -194,7 +200,7 @@ const configureTypeScriptModule = ( writeFilesProcessor: any, readFilesProcessor: any) { - const packagePath = ngPackage.basePath; + const packagePath = ngPackage.src; // Set the base path for the "readFilesProcessor" to the execroot. This is necessary because // otherwise the "writeFilesProcessor" is not able to write to the specified output path. readFilesProcessor.basePath = workingDirectory; @@ -210,11 +216,10 @@ const configureTypeScriptModule = ( const packageEntrypoints = collectEntrypoints(ngPackage); packageEntrypoints.forEach(ep => { - const entrypointIndexPath = `${ep.basePath}/${ep.ngPackageJson.lib?.entryFile}`; + const entrypointIndexPath = `${ep.entryFilePath}`; entryPointGrouper.entryPoints.push(ep); - - tsParser.options.paths[`${ep.packageJson.name}`] = [entrypointIndexPath]; + tsParser.options.paths[`${ep.moduleId}`] = [entrypointIndexPath]; readTypeScriptModules.sourceFiles.push(entrypointIndexPath); }); diff --git a/libs/ngx-doc-gen/src/interfaces/ng-entrypoint.ts b/libs/ngx-doc-gen/src/interfaces/ng-entrypoint.ts deleted file mode 100644 index 4de89a5..0000000 --- a/libs/ngx-doc-gen/src/interfaces/ng-entrypoint.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { NgPackageJson } from './ng-package-json'; -import { PackageJson } from './package-json'; - -export interface NgEntrypoint { - basePath: string; - entrypointName: string; - packageJson: PackageJson; - ngPackageJson: NgPackageJson; -} diff --git a/libs/ngx-doc-gen/src/interfaces/ng-package-json.ts b/libs/ngx-doc-gen/src/interfaces/ng-package-json.ts deleted file mode 100644 index ae9e531..0000000 --- a/libs/ngx-doc-gen/src/interfaces/ng-package-json.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface NgPackageJson { - default?: NgPackageJson; - lib?: { - entryFile: string; - } -} diff --git a/libs/ngx-doc-gen/src/interfaces/ng-package.ts b/libs/ngx-doc-gen/src/interfaces/ng-package.ts deleted file mode 100644 index 20866eb..0000000 --- a/libs/ngx-doc-gen/src/interfaces/ng-package.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { NgEntrypoint } from './ng-entrypoint'; - -export interface NgPackage { - basePath: string; - version?: string; - packageName: string; - primary: NgEntrypoint; - secondaries: NgEntrypoint[]; -} diff --git a/libs/ngx-doc-gen/src/interfaces/package-json.ts b/libs/ngx-doc-gen/src/interfaces/package-json.ts deleted file mode 100644 index 26db90d..0000000 --- a/libs/ngx-doc-gen/src/interfaces/package-json.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { NgPackageJson } from './ng-package-json'; - -export interface PackageJson { - name: string; - version?: string; - ngPackage?: NgPackageJson; -} diff --git a/libs/ngx-doc-gen/src/processors/entry-point-grouper.ts b/libs/ngx-doc-gen/src/processors/entry-point-grouper.ts index 0a70f46..05a388f 100644 --- a/libs/ngx-doc-gen/src/processors/entry-point-grouper.ts +++ b/libs/ngx-doc-gen/src/processors/entry-point-grouper.ts @@ -4,10 +4,11 @@ import { ConstExportDoc } from 'dgeni-packages/typescript/api-doc-types/ConstExp import { FunctionExportDoc } from 'dgeni-packages/typescript/api-doc-types/FunctionExportDoc'; import { InterfaceExportDoc } from 'dgeni-packages/typescript/api-doc-types/InterfaceExportDoc'; import { TypeAliasExportDoc } from 'dgeni-packages/typescript/api-doc-types/TypeAliasExportDoc'; -import { computeApiDocumentUrl } from '../common/compute-api-url'; +import { NgEntryPoint } from 'ng-packagr/lib/ng-package/entry-point/entry-point'; +import * as path from 'canonical-path'; + import { isDeprecatedDoc, isPrimaryExportDoc } from '../common/decorators'; import { CategorizedClassDoc } from '../common/dgeni-definitions'; -import { NgEntrypoint } from '../interfaces/ng-entrypoint'; export interface ModuleInfo { /** Name of the module (e.g. toolbar, drag-drop, ripple, slider-testing) */ @@ -91,69 +92,64 @@ export class EntryPointGrouper implements Processor { name = 'entryPointGrouper'; $runBefore = ['docs-processed']; $runAfter = ['docs-private-filter']; - entryPoints: NgEntrypoint[] = []; + entryPoints: NgEntryPoint[] = []; $process(docs: DocCollection) { - const entryPoints = new Map(); + const entryPointsDocs = new Map(); docs.forEach(doc => { - const moduleInfo = this._getModulePackageInfo(doc); - - const packageName = moduleInfo.packageName; - // const packageDisplayName = packageName === 'cdk' ? 'CDK' : 'Material'; + const docEntryPoint = this._getDocumentEntryPoint(doc); - const moduleImportPath = `${packageName}/${moduleInfo.entryPointName}`; - const entryPointName = packageName + '-' + moduleInfo.name; + const entryPointName = docEntryPoint.flatModuleFile; // Compute a public URL that refers to the document. This is helpful if we want to // make references to other API documents. e.g. showing the extended class. - doc.publicUrl = computeApiDocumentUrl(doc, moduleInfo); + // TODO + // doc.publicUrl = computeApiDocumentUrl(doc, docEntryPoint); // Get the entry-point for this doc, or, if one does not exist, create it. - let entryPoint: EntryPointDoc; - if (entryPoints.has(entryPointName)) { - entryPoint = entryPoints.get(entryPointName); + let entryPointDoc: EntryPointDoc; + if (entryPointsDocs.has(entryPointName)) { + entryPointDoc = entryPointsDocs.get(entryPointName); } else { - entryPoint = new EntryPointDoc(entryPointName); - entryPoints.set(entryPointName, entryPoint); + entryPointDoc = new EntryPointDoc(entryPointName); + entryPointsDocs.set(entryPointName, entryPointDoc); } - entryPoint.displayName = moduleInfo.name; - entryPoint.moduleImportPath = moduleImportPath; - entryPoint.packageName = packageName; - // entryPoint.packageDisplayName = packageName; + entryPointDoc.displayName = docEntryPoint.moduleId; + entryPointDoc.moduleImportPath = docEntryPoint.moduleId; // Put this doc into the appropriate list in the entry-point doc. if (doc.isDirective) { - entryPoint.directives.push(doc); + entryPointDoc.directives.push(doc); } else if (doc.isService) { - entryPoint.services.push(doc); + entryPointDoc.services.push(doc); } else if (doc.isNgModule) { - entryPoint.exportedNgModules.push(doc); + entryPointDoc.exportedNgModules.push(doc); } else if (doc.docType === 'class') { - entryPoint.classes.push(doc); + entryPointDoc.classes.push(doc); if (doc.isTestHarness) { - entryPoint.testHarnesses.push(doc); + entryPointDoc.testHarnesses.push(doc); } } else if (doc.docType === 'interface') { - entryPoint.interfaces.push(doc); + entryPointDoc.interfaces.push(doc); } else if (doc.docType === 'type-alias') { - entryPoint.typeAliases.push(doc); + entryPointDoc.typeAliases.push(doc); } else if (doc.docType === 'function') { - entryPoint.functions.push(doc); + entryPointDoc.functions.push(doc); } else if (doc.docType === 'const') { - entryPoint.constants.push(doc); + entryPointDoc.constants.push(doc); } if (isPrimaryExportDoc(doc)) { - entryPoint.primaryExportName = doc.name; + entryPointDoc.primaryExportName = doc.name; } }); // For each entry-point where no explicit primary export has been specified // through the "@docs-primary-export" tag, we determine a primary export by // looking for possible "NgModule" classes or test harnesses. - entryPoints.forEach(entryPoint => { + entryPointsDocs.forEach(entryPoint => { if (entryPoint.primaryExportName !== null) { return; } @@ -169,7 +165,7 @@ export class EntryPointGrouper implements Processor { } }); - return Array.from(entryPoints.values()); + return Array.from(entryPointsDocs.values()); } /** @@ -189,32 +185,25 @@ export class EntryPointGrouper implements Processor { return null; } - /** Resolves module package information of the given Dgeni document. */ - private _getModulePackageInfo(doc: Document): ModuleInfo { - // Full path to the file for this doc. + /** + * Resolves entrypoint of the given Dgeni document. + */ + private _getDocumentEntryPoint(doc: Document): NgEntryPoint | never { const basePath: string = doc.fileInfo.basePath; - const foundEntryPoint = this._findMatchingEntryPoint(basePath); + const filePath: string = doc.fileInfo.filePath; + const relativeFilePath = path.relative(basePath, filePath).replace(/\\/g, '/'); + const foundEntryPoint = this._findMatchingEntryPoint(relativeFilePath); if (!foundEntryPoint) { throw Error(`Could not determine entry-point for: ${doc.name} in ${basePath}`); } - return { - name: foundEntryPoint.entrypointName, - packageName: foundEntryPoint.packageJson.name, - entryPointName: foundEntryPoint.entrypointName, - }; + return foundEntryPoint; } /** Finds the matching entry-point of the given file path. */ - private _findMatchingEntryPoint(basePath: string): NgEntrypoint | null { - let foundEntryPoint: NgEntrypoint | null = null; - for (const entryPoint of this.entryPoints) { - if (entryPoint.basePath !== basePath) { - continue; - } - foundEntryPoint = entryPoint; - } - return foundEntryPoint; + private _findMatchingEntryPoint(relativeFilePath: string): NgEntryPoint | null { + return this.entryPoints.find(ep => relativeFilePath.startsWith(path.basename(ep.basePath))) + || this.entryPoints.find(ep => ep.isSecondaryEntryPoint === false) || null; } } diff --git a/libs/ngx-doc-gen/src/utils/discovery.ts b/libs/ngx-doc-gen/src/utils/discovery.ts deleted file mode 100644 index 6892e4f..0000000 --- a/libs/ngx-doc-gen/src/utils/discovery.ts +++ /dev/null @@ -1,132 +0,0 @@ -import { statSync } from 'fs-extra'; -import * as path from 'canonical-path'; -import * as FastGlob from 'fast-glob'; - -import { NgEntrypoint } from '../interfaces/ng-entrypoint'; -import { NgPackageJson } from '../interfaces/ng-package-json'; -import { PackageJson } from '../interfaces/package-json'; -import { parseJson } from './json-utils'; -import { NgPackage } from '../interfaces/ng-package'; - -export const discoverNgPackage = async (workingDirectory: string, basePath: string): Promise => { - let projectPath = path.join(workingDirectory, basePath); - projectPath = path.isAbsolute(projectPath) ? projectPath : path.resolve(projectPath); - - const primary = resolveEntrypoint(projectPath); - if (!primary?.packageJson || !primary?.ngPackageJson) { - throw new Error(); - } - - const secondaryPaths = await findSecondaryEntryPointsPaths(projectPath); - const secondaries: NgEntrypoint[] = []; - - for (const folderPath of secondaryPaths) { - const secondaryPackage = resolveEntrypoint(folderPath, true); - if (secondaryPackage) { - secondaries.push(secondaryEntryPoint(primary, secondaryPackage)); - } - } - - return { - basePath: projectPath, - packageName: primary.entrypointName, - version: primary.packageJson.version, - primary, - secondaries - }; -}; - -/** - * Resolves a given path to an entrypoint. - * @param entryPointPath - * @param isSecondary - * @returns - */ -const resolveEntrypoint = (entryPointPath: string, isSecondary = false): NgEntrypoint | undefined => { - const fullPath = path.resolve(entryPointPath); - const pathStats = statSync(fullPath); - const basePath = pathStats.isDirectory() ? fullPath : path.dirname(fullPath); - const packageJson = parseJson(path.join(basePath, 'package.json')); - - if (!packageJson && !isSecondary) { - throw new Error(`Cannot discover package sources at ${basePath} as 'package.json' was not found.`); - } - - if (packageJson && typeof packageJson !== 'object') { - throw new Error(`Invalid 'package.json' at ${basePath}.`); - } - - let ngPackageJson: NgPackageJson | null; - if (packageJson && packageJson?.ngPackage) { - // Read `ngPackage` from `package.json` - ngPackageJson = packageJson.ngPackage; - } else if (pathStats.isDirectory()) { - ngPackageJson = parseJson(path.join(basePath, 'ng-package.json')); - if (!ngPackageJson) { - ngPackageJson = parseJson(path.join(basePath, 'ng-package.js')); - } - } else { - ngPackageJson = parseJson(basePath); - } - - if (ngPackageJson) { - ngPackageJson = ngPackageJson['default'] ?? ngPackageJson; - - return { - basePath, - entrypointName: packageJson.name, - packageJson, - ngPackageJson - }; - } - - if (pathStats.isDirectory()) { - // return even if it's undefined and use defaults when it's not a file - return undefined; - } - - if (pathStats.isFile()) { - // a project file was specified but was in valid - if (path.basename(entryPointPath) === 'package.json') { - throw new Error(`Cannot read a package from 'package.json' without 'ngPackage' property.`); - } - - throw new Error(`Trying to read a package from unsupported file extension. Path: ${entryPointPath}`); - } - - throw new Error(`Cannot discover package sources at ${entryPointPath}`); -}; - -const findSecondaryEntryPointsPaths = async (directoryPath: string): Promise => { - const ignorePattern = [ - '**/node_modules/**', - '**/.git/**', - `${directoryPath}/package.json`, - `${directoryPath}/ng-package.json`, - ]; - - return await FastGlob.default(`${directoryPath}/**/{package,ng-package}.json`, { - ignore: ignorePattern, - onlyFiles: true, - cwd: directoryPath - }); -}; - -const secondaryEntryPoint = (primary: NgEntrypoint, userPackage: any): NgEntrypoint => { - const { packageJson, ngPackageJson, basePath } = userPackage; - if (path.resolve(basePath) === path.resolve(primary.basePath)) { - console.error(`Cannot read secondary entry point. It's already a primary entry point. Path: ${basePath}`); - throw new Error(`Secondary entry point is already a primary.`); - } - - const relativeSourcePath = path.relative(primary.basePath, basePath); - const secondaryModuleId = path.join(`${primary.entrypointName}/${relativeSourcePath}`); - - return { - basePath, - entrypointName: secondaryModuleId, - packageJson, - ngPackageJson - }; -}; - diff --git a/libs/ngx-doc-gen/src/utils/file-utils.ts b/libs/ngx-doc-gen/src/utils/file-utils.ts deleted file mode 100644 index f551f10..0000000 --- a/libs/ngx-doc-gen/src/utils/file-utils.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { readFileSync } from 'fs-extra'; - -export const readFile = (filePath: string, encoding?: BufferEncoding): Buffer | string | null => { - try { - const content: Buffer = fsReadFile(filePath); - - return encoding ? content.toString(encoding) : content; - } catch (error) { - console.error(error); - return null; - } -}; - -const fsReadFile = (filePath: string): Buffer => { - return readFileSync(filePath); -}; diff --git a/libs/ngx-doc-gen/src/utils/json-utils.ts b/libs/ngx-doc-gen/src/utils/json-utils.ts deleted file mode 100644 index a0a4382..0000000 --- a/libs/ngx-doc-gen/src/utils/json-utils.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { parse, printParseErrorCode } from 'jsonc-parser'; -import type { ParseError } from 'jsonc-parser'; -import { readFile } from './file-utils'; - -export const parseJson = ( - filePath: string, - disallowComments = false, - expectComments = true -): T | null => { - - const fileContent = readFile(filePath, 'utf-8'); - - if (!fileContent) { - return null; - } - - try { - - if (disallowComments || !expectComments) { - return JSON.parse(fileContent as string); - } - - } catch (error) { - if (disallowComments) { - throw error; - } - } - - const errors: ParseError[] = []; - const result: T = parse(fileContent as string, errors); - - if (errors.length > 0) { - const { error, offset } = errors[0]; - throw new Error( - `${printParseErrorCode(error)} in JSON at position ${offset}` - ); - } - - return result; -} diff --git a/libs/ngx-doc-gen/src/utils/package-utils.ts b/libs/ngx-doc-gen/src/utils/package-utils.ts index d65b615..9184e0e 100644 --- a/libs/ngx-doc-gen/src/utils/package-utils.ts +++ b/libs/ngx-doc-gen/src/utils/package-utils.ts @@ -2,8 +2,8 @@ import { Package } from 'dgeni'; import * as jsdocPackage from 'dgeni-packages/jsdoc'; import * as nunjucksPackage from 'dgeni-packages/nunjucks'; import * as typescriptPackage from 'dgeni-packages/typescript'; -import { NgEntrypoint } from '../interfaces/ng-entrypoint'; -import { NgPackage } from '../interfaces/ng-package'; +import { NgEntryPoint } from 'ng-packagr/lib/ng-package/entry-point/entry-point'; +import { NgPackage } from 'ng-packagr/lib/ng-package/package'; export const createDgeniPackage = (packageName: string): Package => { return new Package(packageName, [ @@ -13,7 +13,7 @@ export const createDgeniPackage = (packageName: string): Package => { ]); }; -export const collectEntrypoints = (ngPackage: NgPackage): NgEntrypoint[] => { +export const collectEntrypoints = (ngPackage: NgPackage): NgEntryPoint[] => { return [ ngPackage.primary, ...ngPackage.secondaries diff --git a/libs/single-entrypoint/package.json b/libs/single-entrypoint/package.json index d3846ea..0431877 100644 --- a/libs/single-entrypoint/package.json +++ b/libs/single-entrypoint/package.json @@ -1,5 +1,5 @@ { - "name": "@single", + "name": "@single/test", "version": "0.0.1", "peerDependencies": { "@angular/common": "^13.2.0", diff --git a/package.json b/package.json index 8c6cd4b..c1db6c0 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,13 @@ "name": "ngx-doc-gen", "scripts": { "ng": "nx", + "nx": "nx", "postinstall": "node ./decorate-angular-cli.js && ngcc --properties es2015 browser module main", "build": "nx run ngx-doc-gen:build", "lint": "nx run ngx-doc-gen:lint", "test": "nx run ngx-doc-gen:test", - "test:doc-gen:single-entrypoint": "nx run single-entrypoint:doc-gen", - "test:doc-gen:multi-entrypoint": "nx run multi-entrypoint:doc-gen" + "test:doc-gen:single-entrypoint": "npm run build && nx run single-entrypoint:doc-gen", + "test:doc-gen:multi-entrypoint": "npm run build && nx run multi-entrypoint:doc-gen" }, "private": true, "dependencies": { diff --git a/tsconfig.base.json b/tsconfig.base.json index a43e948..9fc8d4e 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -21,6 +21,15 @@ "@multi": [ "libs/multi-entrypoint/src/index.ts" ], + "@multi/one": [ + "libs/multi-entrypoint/one/src/index.ts" + ], + "@multi/three": [ + "libs/multi-entrypoint/three/src/index.ts" + ], + "@multi/two": [ + "libs/multi-entrypoint/two/src/index.ts" + ], "@single": [ "libs/single-entrypoint/src/index.ts" ]