Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgraded, made small fixes afterwards #11

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ Thumbs.db
.angular

**/doc-page-loaders.ts

.nx/cache
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/dist
/coverage
**/project.json

/.nx/cache
17 changes: 5 additions & 12 deletions apps/component-doc-portal/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,35 +94,28 @@
"executor": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "component-doc-portal:ng-build:production"
"buildTarget": "component-doc-portal:ng-build:production"
},
"development": {
"browserTarget": "component-doc-portal:ng-build:development"
"buildTarget": "component-doc-portal:ng-build:development"
}
},
"defaultConfiguration": "development"
},
"ng-extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "component-doc-portal:ng-build"
"buildTarget": "component-doc-portal:ng-build"
}
},
"lint": {
"executor": "@nx/linter:eslint",
"options": {
"lintFilePatterns": [
"apps/component-doc-portal/src/**/*.ts",
"apps/component-doc-portal/src/**/*.html"
]
}
"executor": "@nx/eslint:lint"
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/apps/component-doc-portal"],
"options": {
"jestConfig": "apps/component-doc-portal/jest.config.ts",
"passWithNoTests": true
"jestConfig": "apps/component-doc-portal/jest.config.ts"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion apps/ng-doc-portal-plugin-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/ng-doc-portal-plugin-e2e/jest.config.ts",
"runInBand": true
"runInBand": true,
"passWithNoTests": false
},
"dependsOn": ["ng-doc-portal-plugin:build"]
}
Expand Down
10 changes: 5 additions & 5 deletions libs/ng-doc-portal-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
"generators": "./generators.json",
"executors": "./executors.json",
"peerDependencies": {
"prettier": "^2.6.2",
"@nx/devkit": "^16.0.0",
"@nx/angular": "^16.0.0"
"prettier": "^3.2.5",
"@nx/devkit": "^18.0.0",
"@nx/angular": "^18.0.0"
},
"dependencies": {
"@phenomnomnominal/tsquery": "^6.0.0",
"chalk": "^4.1.2",
"chokidar": "^3.5.3",
"date-fns": "2.30.0",
"fast-glob": "^3.3.0",
"date-fns": "^3.6.0",
"fast-glob": "^3.3.2",
"minimatch": "^9.0.3"
},
"publishConfig": {
Expand Down
15 changes: 3 additions & 12 deletions libs/ng-doc-portal-plugin/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,14 @@
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"libs/ng-doc-portal-plugin/**/*.ts",
"libs/ng-doc-portal-plugin/generators.json",
"libs/ng-doc-portal-plugin/executors.json",
"libs/ng-doc-portal-plugin/package.json"
]
}
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"]
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/libs/ng-doc-portal-plugin"],
"options": {
"jestConfig": "libs/ng-doc-portal-plugin/jest.config.ts",
"passWithNoTests": true
"jestConfig": "libs/ng-doc-portal-plugin/jest.config.ts"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export class DocPageLoadersCompiler {
constructor(
private readonly configFileLocation: string,
private readonly docPageLoadersFileLocation: string,
private readonly silenced = false
private readonly silenced = false,
) {
if (!existsSync(this.configFileLocation)) {
throw new Error(
`Could not find config file at ${this.configFileLocation}`
`Could not find config file at ${this.configFileLocation}`,
);
}

Expand Down Expand Up @@ -77,11 +77,11 @@ export class DocPageLoadersCompiler {
watch() {
const fileEvents = concat(
this.buildInitialFileEvent(),
this.buildWatcher()
this.buildWatcher(),
);

const handledFileEvents = this.handleFileEvents(fileEvents).pipe(
shareReplay(1)
shareReplay(1),
);

handledFileEvents.pipe(take(1)).subscribe(() => {
Expand All @@ -100,12 +100,12 @@ export class DocPageLoadersCompiler {
map((payloads) => this.detectAndHandleDuplicateTitles(payloads)),
map((eventPayloads) =>
eventPayloads.map((eventPayload) =>
generateDocPageLoader(eventPayload.filePath, eventPayload.title)
)
generateDocPageLoader(eventPayload.filePath, eventPayload.title),
),
),
map(wrapTypescriptBoilerplate),
map(formatContent),
switchMap((content) => this.writeDynamicPageContentToFile(content))
switchMap((content) => formatContent(content)),
switchMap((content) => this.writeDynamicPageContentToFile(content)),
);
}

Expand All @@ -125,13 +125,13 @@ export class DocPageLoadersCompiler {
dot: true,
onlyFiles: true,
ignore: ['node_modules'],
})
}),
).pipe(
map((filePaths): RawInitEvent => ({ type: 'init', filePaths })),
tap(() => {
const endTime = Date.now();
this.log(green(`Searching complete in ${endTime - startTime}ms\n`));
})
}),
);
}

Expand All @@ -142,7 +142,7 @@ export class DocPageLoadersCompiler {
private buildWatcher(): Observable<RawFileEvent> {
return new Observable<RawFileEvent>((observer) => {
const patternStrings = convertPatternOrGlobPatternArray(
this.globPatterns
this.globPatterns,
);

const watcher = watch(patternStrings, {
Expand All @@ -168,7 +168,7 @@ export class DocPageLoadersCompiler {
*/
private buildRawFileEvent(
rawFilePath: string,
event: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir'
event: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir',
): RawFileEvent {
const filePath = rawFilePath.replace(/\\/g, '/');
if (event === 'add' || event === 'addDir') {
Expand All @@ -191,7 +191,7 @@ export class DocPageLoadersCompiler {
* @private
*/
private async addPayloadToEvent(
fileEvent: RawFileEvent
fileEvent: RawFileEvent,
): Promise<ProcessedFileEvent | null> {
try {
if (fileEvent.type === 'init') {
Expand All @@ -201,7 +201,7 @@ export class DocPageLoadersCompiler {
for (const filePath of fileEvent.filePaths) {
const title = await extractTitleFromDocPageFile(
filePath,
this.globPatterns
this.globPatterns,
);
payload.push({ filePath, title });
}
Expand All @@ -210,21 +210,21 @@ export class DocPageLoadersCompiler {
green(
`Finished compiling component document page files in ${
endTime - startTime
}ms\n`
)
}ms\n`,
),
);
return { ...fileEvent, payload };
} else if (fileEvent.type === 'add' || fileEvent.type === 'change') {
const startTime = Date.now();
const title = await extractTitleFromDocPageFile(
fileEvent.filePath,
this.globPatterns
this.globPatterns,
);
const endTime = Date.now();
this.log(
blue(
`${timeNow()} - COMPILE - recompiled in ${endTime - startTime}ms`
)
`${timeNow()} - COMPILE - recompiled in ${endTime - startTime}ms`,
),
);
return { ...fileEvent, title };
} else {
Expand All @@ -244,16 +244,16 @@ export class DocPageLoadersCompiler {
duplicatesDetected = true;
this.log(
yellow(
`Duplicated title of "${payload.title}" detected in file '${payload.filePath}'`
)
`Duplicated title of "${payload.title}" detected in file '${payload.filePath}'`,
),
);
payload.title += ` ${++titles[payload.title]}`;
}
titles[payload.title] = 1;
}
if (duplicatesDetected) {
this.log(
yellow('\nPlease resolve duplicated titles before publishing!\n')
yellow('\nPlease resolve duplicated titles before publishing!\n'),
);
}
return eventPayloads;
Expand All @@ -272,8 +272,8 @@ export class DocPageLoadersCompiler {
console.error(e);
this.log(
red(
`\n\nUnexpected error occurred while generating doc-page-loaders.ts\n`
)
`\n\nUnexpected error occurred while generating doc-page-loaders.ts\n`,
),
);
}
}
Expand Down
26 changes: 13 additions & 13 deletions libs/ng-doc-portal-plugin/src/executors/compiler/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { basename } from 'path';
*/
export function accumulatePayloads(
acc: EventPayload[],
curr: ProcessedFileEvent
curr: ProcessedFileEvent,
): EventPayload[] {
if (curr.type === 'init') {
const list = sortFullPayloadList(curr.payload);
Expand Down Expand Up @@ -50,7 +50,7 @@ export function sortFullPayloadList(list: EventPayload[]) {

export function insertIntoSortedPayloadList(
list: EventPayload[],
item: EventPayload
item: EventPayload,
) {
let index = 0;
let low = 0;
Expand Down Expand Up @@ -86,7 +86,7 @@ export function comparePayloadTitles(a: EventPayload, b: EventPayload) {

export function findTitlePrefixFromGlobPatterns(
filePath: string,
globPatterns: (string | GlobPattern)[]
globPatterns: (string | GlobPattern)[],
): string | undefined {
const pattern = globPatterns.find((globPattern) => {
if (typeof globPattern === 'string') {
Expand Down Expand Up @@ -136,7 +136,7 @@ export async function getTitleFromTypeScript(filePath: string) {

const defaultExportClassDeclaration = tsquery(
ast,
'ClassDeclaration:has(ExportKeyword):has(DefaultKeyword)'
'ClassDeclaration:has(ExportKeyword):has(DefaultKeyword)',
).at(0);

if (defaultExportClassDeclaration) {
Expand All @@ -156,16 +156,16 @@ export async function getTitleFromTypeScript(filePath: string) {

let objectLiteralExpression = tsquery(
exportAssignment,
'ObjectLiteralExpression'
'ObjectLiteralExpression',
).at(0);

if (!objectLiteralExpression) {
const identifier = tsquery(exportAssignment, 'Identifier').at(0);
objectLiteralExpression = tsquery(
ast,
`VariableDeclaration:has(Identifier[name="${identifier?.getText(
ast
)}"]) > ObjectLiteralExpression`
ast,
)}"]) > ObjectLiteralExpression`,
).at(0);
}

Expand All @@ -175,7 +175,7 @@ export async function getTitleFromTypeScript(filePath: string) {

const title = tsquery(
objectLiteralExpression,
'PropertyAssignment:has(Identifier[name="title"]) > StringLiteral'
'PropertyAssignment:has(Identifier[name="title"]) > StringLiteral',
)
.at(0)
?.getText(ast);
Expand All @@ -185,7 +185,7 @@ export async function getTitleFromTypeScript(filePath: string) {
return title.replace(/'/g, '');
} else {
throw new Error(
`No property found for 'title' in exported object literal for file: ${filePath}`
`No property found for 'title' in exported object literal for file: ${filePath}`,
);
}
} else {
Expand All @@ -205,7 +205,7 @@ export async function getTitleFromTypeScript(filePath: string) {
*/
export async function extractTitleFromDocPageFile(
filePath: string,
globPatterns: (string | GlobPattern)[]
globPatterns: (string | GlobPattern)[],
) {
const title = await getTitleFromTypeScript(filePath);
const prefix = findTitlePrefixFromGlobPatterns(filePath, globPatterns);
Expand Down Expand Up @@ -240,7 +240,7 @@ export function generateDocPageLoader(filePath: string, title: string) {
*
* @param content The file content to be prettified
*/
export function formatContent(content: string): string {
export async function formatContent(content: string): Promise<string> {
return prettierFormat(content, {
parser: 'typescript',
printWidth: 100,
Expand All @@ -264,12 +264,12 @@ export function wrapTypescriptBoilerplate(configStrings: string[]) {
}

export function convertPatternOrGlobPatternArray(
patterns: (string | GlobPattern)[]
patterns: (string | GlobPattern)[],
) {
return patterns.map((strOrGlobPattern) =>
typeof strOrGlobPattern === 'string'
? strOrGlobPattern
: strOrGlobPattern.pattern
: strOrGlobPattern.pattern,
);
}

Expand Down
10 changes: 5 additions & 5 deletions libs/ng-doc-portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"description": "Documentation portal system written natively in Angular",
"version": "v1.7.1",
"peerDependencies": {
"@angular/common": "^16.0.0",
"@angular/core": "^16.0.0",
"@angular/forms": "^16.0.0",
"@angular/router": "^16.0.0",
"@angular/platform-browser": "^16.0.0",
"@angular/common": "^17.0.0",
"@angular/core": "^17.0.0",
"@angular/forms": "^17.0.0",
"@angular/router": "^17.0.0",
"@angular/platform-browser": "^17.0.0",
"tslib": "^2.3.0"
},
"dependencies": {
Expand Down
Loading
Loading