Skip to content

Commit

Permalink
fix(core): should prevent the next build while building
Browse files Browse the repository at this point in the history
  • Loading branch information
why520crazy committed Sep 3, 2022
1 parent 5ee49ad commit 365f323
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
9 changes: 9 additions & 0 deletions packages/core/src/builders/library-component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ describe('#library-component', () => {
await component.build();
expect(component.examples.find(example => example.name === notExistExample)).toBeTruthy();
});

it('should prevent the next build while building', () => {
const component = new LibraryComponentImpl(context, library, 'button', `${DEFAULT_TEST_ROOT_PATH}/alib/button`);
const resetEmittedSpy = spyOn(component, 'resetEmitted');
component.build();
component.build();
component.build();
expect(resetEmittedSpy).toHaveBeenCalledTimes(1);
});
});

describe('api-docs', () => {
Expand Down
21 changes: 16 additions & 5 deletions packages/core/src/builders/library-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class LibraryComponentImpl extends FileEmitter implements LibraryComponen
public absExamplesPath: string;
public absDocPath: string;
public absApiPath: string;
private isBuilding = false;
private get absDestSiteContentComponentsPath() {
return resolve(this.docgeni.paths.absSiteContentPath, `components/${this.lib.name}/${this.name}`);
}
Expand Down Expand Up @@ -66,11 +67,21 @@ export class LibraryComponentImpl extends FileEmitter implements LibraryComponen
}

public async build(): Promise<void> {
this.resetEmitted();
await this.buildOverviews();
await this.buildExamples();
await this.buildApiDocs();
await this.buildDocItems();
if (this.isBuilding) {
return;
}
try {
this.isBuilding = true;
this.resetEmitted();
await this.buildOverviews();
await this.buildExamples();
await this.buildApiDocs();
await this.buildDocItems();
} catch (error) {
throw error;
} finally {
this.isBuilding = false;
}
}

public async onEmit(): Promise<void> {
Expand Down

0 comments on commit 365f323

Please sign in to comment.