From 7c566f5b53d53c713323eb6c60a8f28521c682dd Mon Sep 17 00:00:00 2001 From: supermn54 Date: Thu, 14 Jun 2018 03:09:42 +0000 Subject: [PATCH] Generats Epic README.md --- packages/warriorjs-cli/src/Game.js | 1 + .../warriorjs-cli/src/ProfileGenerator.js | 33 ++++++++++++++----- .../warriorjs-cli/templates/README.md.ejs | 3 ++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/packages/warriorjs-cli/src/Game.js b/packages/warriorjs-cli/src/Game.js index d2f61428..0c3bcb2c 100644 --- a/packages/warriorjs-cli/src/Game.js +++ b/packages/warriorjs-cli/src/Game.js @@ -396,6 +396,7 @@ class Game { */ prepareEpicMode() { this.profile.enableEpicMode(); + this.generateProfileFiles(); } } diff --git a/packages/warriorjs-cli/src/ProfileGenerator.js b/packages/warriorjs-cli/src/ProfileGenerator.js index 67258c99..3d377439 100644 --- a/packages/warriorjs-cli/src/ProfileGenerator.js +++ b/packages/warriorjs-cli/src/ProfileGenerator.js @@ -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, - }; + 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) { + for (let i = 1; i < 10; i += 1) { + const data = { + getFloorMap, + getFloorMapKey, + profile: this.profile, + level: i, + }; + 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); + } } /** diff --git a/packages/warriorjs-cli/templates/README.md.ejs b/packages/warriorjs-cli/templates/README.md.ejs index ee09962f..55ec83b7 100644 --- a/packages/warriorjs-cli/templates/README.md.ejs +++ b/packages/warriorjs-cli/templates/README.md.ejs @@ -5,6 +5,9 @@ <% } -%> ## Level <%- level.number %> +<% levels.forEach(level => { -%> +<%- include('levels', { level }); %> +<% }); -%> <%- include('readme/level', { getFloorMap, getFloorMapKey, level }); -%>