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

General Refactoring work #1756

Open
ong6 opened this issue Feb 8, 2022 · 3 comments
Open

General Refactoring work #1756

ong6 opened this issue Feb 8, 2022 · 3 comments

Comments

@ong6
Copy link
Contributor

ong6 commented Feb 8, 2022

Is your request related to a problem?

Feels like the current core/site/index.js file is getting a little long (over 1.5k lines), making it hard to read and find important information, what is the general consensus around refactoring it?

Describe the solution you'd like

I propose we refactor the core/site/index.js file into all the different commands such as deploy, convert etc. Each command can be a separate class that contains its own functionality, while site can still exist as a the main driver class. This way, we can easily view all the code related to each command and make adding new commands easier.

Though I'm not sure how doable this is since everything looks very tightly coupled. Any suggestions or ideas on how to go about refactoring this would be great!

Describe alternatives you've considered

Nil

Additional context

Nil

@tlylt tlylt added the s.UnderDiscussion The team will evaluate this issue to decide whether it is worth adding label Feb 9, 2022
@jonahtanjz
Copy link
Contributor

Related to #1495

@ang-zeyu ang-zeyu added p.Medium and removed s.UnderDiscussion The team will evaluate this issue to decide whether it is worth adding labels Feb 9, 2022
@lhw-1
Copy link
Contributor

lhw-1 commented Mar 13, 2023

Let me try researching this issue further - I'll post any updates / findings if I run into issues with decoupling and refactoring 😅

(Keeping this in mind: Completing TypeScript migration of Site/index.js first might be preferrable as mentioned in #1495 (comment) by @ang-zeyu)

The current plan is to refactor Site/index.js according to the commands specified in packages/cli/index.js, namely init, serve, build, and deploy. init can be tackled first as it is quite decoupled from the rest & will serve as continuation of #2148 (relevant comment here), but for the other three, some more digging may have to be done before coming up with further plans. (Currently I am thinking of just having a SiteServeManager, SiteBuildManager, and SiteDeployManager within Site/index.js, but this depends on how coupled the functions are)

Update 1:

After looking through Site/index.js and trying to make sense of which functions are being called where, I think that there should be two more classes in particular that can be refactored: SiteConfigManager and SitePageManager. There are numerous functions for both SiteConfig and Page that are being called during init, serve, and build, and it should be a good first step to refactor these out before working on the command-specific managers.

The advantage of having command-specific managers: SiteInitManager, SiteServeManager, SiteBuildManager, and SiteDeployManager would be that we can have more modularity with the CLI commands in the future - e.g. with this refactor, we can have the --template and the --convert option handled entirely within the SiteInitManager (it is currently being done in cli/index.js, which is alright for now, but cli/index.js is slowly building up as well - we should try to refactor some parts of it before it gets difficult to manage it like Site/index.js). Of course, this means that we would have to refactor parts of cli/index.js together with Site/index.js, but with long-term code quality in mind, I think this is worth working on.

Update 2:

After some preliminary refactoring and testing, it seems that with other files in TypeScript, it would be preferrable to not only have Site/index.js be migrated to TypeScript before any refactoring, but having cli/index.js be migrated would likely reduce obstacles for the refactoring process. (Neither seem to be mandatory, but would be preferrable)

As a side note, I have identified readSiteConfig, addDefaultLayoutToSiteConfig, and writeToSiteConfig to be possibly refactored into SiteConfigManager class, with possible a few other methods as well. If there are parts of Site/index.js that can be refactored without affecting the TypeScript migration, I will create separate PRs for those.

@ang-zeyu
Copy link
Contributor

Both general directions sound good. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants