Refactor initialization code and update typical init#935
Refactor initialization code and update typical init#935yamgent merged 2 commits intoMarkBind:masterfrom
Conversation
|
Request for comments cc: @damithc |
As this is an internal design improvement, I'm not in a position to say much. I'll wait for senior devs to weigh in. |
|
I am leaning towards the second design, although I feel that both designs will start to show their flaws when we need to rename existing directories.
Actually, is there strictly a need to follow a directory structure for the template in the first place? I feel that this requirement will make it harder to maintain as we now have to ensure that both the code and the template directory structure are in sync with each other, which isn't desirable either. |
|
@yamgent very good points raised there, definitely there are some restrictions on both designs. On those points, I think a mixture of first and second design can provide both flexibility and proper safeguards. I treat the We can then follow the first design to initialize the site if those basic directories exist (passes validation) by copying the entire template files. What do you think? |
Sure, let's evolve the design to that direction and see how it goes. |
02e7e02 to
80344d9
Compare
|
Test changes:
Current design: Main differences lies in Site initialization process. Previous site initialization does not require user input, so the unit test was resembling an integration test. Current site initialization requires user input and the output depends on the template that was chosen. Since this is a Unit Test, user input does not matter for us (should be covered by integration tests for future templates added), we mock the template input accordingly. |
|
@yamgent wondering whether you have any insight on the failing test. It is passing locally for me, seems it could be because of the node_modules cache. |
Were you running npm 5.8.0 when you update package-lock.json? I recall the newer version of npm handling versions differently, which may cause certain dependencies to be the wrong versions and could result in different test outputs generated. |
f220b8f to
d068f31
Compare
|
Ready for review. Thanks for your help @yamgent so far! I reverted to node 8 and npm 6 to get this working. Definitely some issue dependency issues there when using node 10 and upgrading our dependencies. It will cause deploy/netlify stage to fail I would attempt to reproduce in a fresh issue. The architecture and design are stated in previous comments on how I approached this issue. Hopefully that will help in reviewing. I adopted open-close principal in allowing for developers to create new initialization templates, and also this design made it easier to integrate with remote templates in the future. |
yamgent
left a comment
There was a problem hiding this comment.
I am fine with the current implementation atm.
Future extension work on this feature could allow users to use customized templates that are not shipped together with MarkBind (currently all templates must be stored in src/template/ folder, which is not accessible to MarkBind users normally). This can be explored in a future PR.
A comment: src/template/page.ejs seems a bit out of place now that the template/ folder is used for a different purpose.
e8d1d52 to
51e2369
Compare
|
Made changes accordingly @yamgent. Thanks for helping to review! I was wondering where would be most appropriate to place Based on my understanding, our current logic doesn't allow multiple forms of base template which means the current structure of |
yamgent
left a comment
There was a problem hiding this comment.
Based on my understanding, our current logic doesn't allow multiple forms of base template which means the current structure of
page.ejsis quite coupled with our design. In that direction of thought, I would think that placing it at top level together with Page.js and Site.js would be appropriate. To limit the scope of this PR, I feel that it would be better to refactor this in a separate PR. What do you think?
Yes we can do it in a separate PR, putting it together with Page.js and Site.js seems fine.
There is still a problem with the template overwriting existing files already on the directory. Steps to reproduce:
- Do a
markbind initon an empty directory. - Modify a file (e.g. modify
index.md). - Run
markbind initon the same directory.
Expected: The second run of markbind init does not touch index.md.
Actual: index.md is overwritten with the template content again and the modifications are lost.
We want the expected behaviour because authors might re-run markbind init on an existing project directory in order to add new files that weren't present in previous versions of MarkBind. So this behaviour needs to be fixed.
|
Great looking out there! Added a fix and a unit test to check that behavior |
yamgent
left a comment
There was a problem hiding this comment.
You might want to rename the first commit to follow the same as the PR title.
The second commit's title can be "Fix missing google-analytics code for test case outputs" to be more clear about what is going on (mainly fixing the test case outputs). The PR number can be mentioned in the body of the commit as additional details.
Also one minor nit:
3e39f77 to
e593a91
Compare
|
Changed according to comments. Ready for review @yamgent. Thanks a lot! |
Apologies for being unclear, when I stated this, I meant removing the "[861-update-init-command]" part, so the title should only be "Refactor initialization code and update typical init". We don't put branch names in commit titles here. 😛 Otherwise this looks pretty good. 👍 |
e593a91 to
5494cd8
Compare
5494cd8 to
4760ecc
Compare
|
Updated the commit name. Also merged the third commit into the first. Thanks a lot 😄 |
Refactor page.ejs to be at src directory as discussed in #935. This is because template directory is hijacked to include markbind initialized templates. In the near future, there seems to have no plans to have multiple base templates, as the design is very coupled with current base template in page.ejs. If there are plans to decouple, we should consider refactoring again.


Things Left To Do:
defaulttheme to actually reflect what is required in Update 'init' command to create a site given in markbind/init-typical #861What is the purpose of this pull request? (put "X" next to an item, remove the rest)
Fixes: #861
Related to: #519
What is the rationale for this request?
This PR updates current initialization to illustrate a more complete set of features. On top of that, it also addresses the issue that editing our scaffold markbind or providing more initialization options is too complex in our current codebase which uses const hardcoded defaults.
What changes did you make? (Give an overview)
There were two main architecture that I explored in this PR on how to refactor this initialization code:
Copying the entire theme:

Creating all the files and directories, and copying from the theme if file exist for the theme:

Provide some example code that this change will affect:
The code below illustrates the change in Site.initSite based on the first architecture.
Is there anything you'd like reviewers to focus on?
When adding a new directory, we don't have to go into each of those themes to add those empty directory if those themes don't require.
This commit illustrates the first design, but I am more for the second design which is basically adding 1 additional line to each promise blocks of the previous code. Would appreciate some discussion here.
Example second design: