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

Implement Site.Prototype methods in ES6 syntax #2280 #2356

Merged
merged 6 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions packages/cli/src/util/serveUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const addHandler = (site, onePagePath) => (filePath) => {
}
Promise.resolve('').then(async () => {
if (site.isFilepathAPage(filePath) || site.isDependencyOfPage(filePath)) {
return site.rebuildSourceFiles(filePath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, maybe there's something wrong here. I'm not sure why we are rebuilding all source files when one file is added/removed. Anyhow, it's not related to this PR.

return site.rebuildSourceFiles();
}
return site.buildAsset(filePath);
}).catch((err) => {
Expand Down Expand Up @@ -59,7 +59,7 @@ const removeHandler = (site, onePagePath) => (filePath) => {
}
Promise.resolve('').then(async () => {
if (site.isFilepathAPage(filePath) || site.isDependencyOfPage(filePath)) {
return site.rebuildSourceFiles(filePath);
return site.rebuildSourceFiles();
}
return site.removeAsset(filePath);
}).catch((err) => {
Expand Down
80 changes: 27 additions & 53 deletions packages/core/src/Site/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ export class Site {
currentOpenedPages: string[];
toRebuild: Set<string>;
externalManager!: ExternalManager;
buildAsset?: (this: any, arg: unknown) => Bluebird<unknown>;
rebuildAffectedSourceFiles?: (this: any, arg: unknown) => Bluebird<unknown>;
rebuildSourceFiles?: (this: any, arg: unknown) => Bluebird<unknown>;
// TODO: add LayoutManager when it has been migrated
layoutManager: any;

Expand Down Expand Up @@ -1678,58 +1675,35 @@ export class Site {
this.variableProcessor.addUserDefinedVariableForAllSites('timestamp', time);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this
async rebuildPagesBeingViewed(_currentPageViewed: string) {
throw new Error('Method not implemented.');
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this
async removeAsset(_removedPageFilePaths: string | string[]) {
throw new Error('Method not implemented.');
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this
async backgroundBuildNotViewedFiles(_arg0?: any, _arg1?: any) {
throw new Error('Method not implemented.');
}
}

/**
* Below are functions that are not compatible with the ES6 class syntax.
*/

/**
* Build/copy assets that are specified in filePaths
* @param filePaths a single path or an array of paths corresponding to the assets to build
*/
Site.prototype.buildAsset = delay(Site.prototype._buildMultipleAssets as () => Bluebird<unknown>, 1000);
/**
* Build/copy assets that are specified in filePaths
* @param filePaths a single path or an array of paths corresponding to the assets to build
*/
buildAsset = delay(this._buildMultipleAssets as () => Bluebird<unknown>, 1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might cause a type problem in the future when serveUtil.js is migrated to TypeScript, but should be ok for now.


Site.prototype.rebuildPagesBeingViewed = delay(
Site.prototype._rebuildPagesBeingViewed as () => Bluebird<unknown>, 1000);
/**
* Remove assets that are specified in filePaths
* @param filePaths a single path or an array of paths corresponding to the assets to remove
*/
removeAsset = delay(this._removeMultipleAssets as () => Bluebird<unknown>, 1000);

/**
* Rebuild pages that are affected by changes in filePaths
* @param filePaths a single path or an array of paths corresponding to the files that have changed
*/
Site.prototype.rebuildAffectedSourceFiles = delay(
Site.prototype._rebuildAffectedSourceFiles as () => Bluebird<unknown>, 1000);
rebuildPagesBeingViewed = delay(this._rebuildPagesBeingViewed as () => Bluebird<unknown>, 1000);

/**
* Rebuild all pages
* @param filePaths a single path or an array of paths corresponding to the files that have changed
*/
Site.prototype.rebuildSourceFiles = delay(
Site.prototype._rebuildSourceFiles as () => Bluebird<unknown>, 1000);
/**
* Rebuild pages that are affected by changes in filePaths
* @param filePaths a single path or an array of paths corresponding to the files that have changed
*/
rebuildAffectedSourceFiles = delay(this._rebuildAffectedSourceFiles as () => Bluebird<unknown>, 1000);

/**
* Remove assets that are specified in filePaths
* @param filePaths a single path or an array of paths corresponding to the assets to remove
*/
Site.prototype.removeAsset = delay(
Site.prototype._removeMultipleAssets as () => Bluebird<unknown>, 1000);
/**
* Rebuild all pages
*/
rebuildSourceFiles
= delay(this._rebuildSourceFiles as () => Bluebird<unknown>, 1000) as () => Bluebird<unknown>;

/**
* Builds pages that are yet to build/rebuild in the background
*/
Site.prototype.backgroundBuildNotViewedFiles = delay(
Site.prototype._backgroundBuildNotViewedFiles as () => Bluebird<unknown>, 1000);
/**
* Builds pages that are yet to build/rebuild in the background
*/
backgroundBuildNotViewedFiles
= delay(this._backgroundBuildNotViewedFiles as () => Bluebird<unknown>, 1000) as () => Bluebird<unknown>;
}