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

Generate Epic README.md #199

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions packages/warriorjs-cli/src/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ class Game {
*/
prepareEpicMode() {
this.profile.enableEpicMode();
this.generateProfileFiles();
Copy link
Owner

Choose a reason for hiding this comment

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

👍

}
}

Expand Down
33 changes: 25 additions & 8 deletions packages/warriorjs-cli/src/ProfileGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,32 @@ class ProfileGenerator {
*/
generateReadmeFile() {
const template = fs.readFileSync(README_TEMPLATE_FILE_PATH, 'utf8');
const data = {
getFloorMap,
getFloorMapKey,
profile: this.profile,
level: this.level,
Copy link
Owner

Choose a reason for hiding this comment

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

You just need to change the level key to an array of levels, not the entire data object. The other three keys remain the same no matter the level.

};
const levels = [];

const options = { filename: README_TEMPLATE_FILE_PATH };
const renderedReadme = ejs.render(template, data, options);
fs.writeFileSync(this.profile.getReadmeFilePath(), renderedReadme);
if (this.profile.epic) {
Copy link
Owner

Choose a reason for hiding this comment

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

You should use this.profile.isEpic() here.

for (let i = 1; i < 10; i += 1) {
Copy link
Owner

Choose a reason for hiding this comment

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

Check my comments here explaining what we should use for the loop.

const data = {
getFloorMap,
getFloorMapKey,
profile: this.profile,
level: i,
Copy link
Owner

Choose a reason for hiding this comment

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

You're just passing the level number here, where we need the level config object instead. Check what we pass inside this.level, that should be what we pass for each level here. Also, check my general comment. The commit I talk about will make this much easier and cleaner.

};
levels.push(data);
}
const renderedReadme = ejs.render(template, levels, options);
fs.writeFileSync(this.profile.getReadmeFilePath(), renderedReadme);
} else {
const data = {
getFloorMap,
getFloorMapKey,
profile: this.profile,
level: this.level,
};
levels.push(data);
const renderedReadme = ejs.render(template, levels, options);
fs.writeFileSync(this.profile.getReadmeFilePath(), renderedReadme);
}
Copy link
Owner

Choose a reason for hiding this comment

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

The data object and the last two lines of this method can be moved outside the if/else blocks. The overall structure of the generateReadmeFile method should look something like this:

const template = fs.readFileSync(README_TEMPLATE_FILE_PATH, 'utf8');
const data = {
  getFloorMap,
  getFloorMapKey,
  profile: this.profile,
};
if (this.profile.isEpic()) {
  data.levels = ... // <-- Here you assemble the array of levels (all the levels)
} else {
  data.levels = ... // <-- Here you assemble the array of levels (only one level in this case)
}
const options = { filename: README_TEMPLATE_FILE_PATH };
const renderedReadme = ejs.render(template, data, options);
fs.writeFileSync(this.profile.getReadmeFilePath(), renderedReadme);

}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/warriorjs-cli/templates/README.md.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<% } -%>

## Level <%- level.number %>
<% levels.forEach(level => { -%>
<%- include('levels', { level }); %>
Copy link
Owner

Choose a reason for hiding this comment

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

You need to use the exact include line below instead of 'levels' (which you haven't defined yet?). Also, the header should be rendered inside the loop.

<% }); -%>

<%- include('readme/level', { getFloorMap, getFloorMapKey, level }); -%>

Expand Down