From cc5a9c5bd84ef1588bb4136bc143256726dc68a9 Mon Sep 17 00:00:00 2001 From: Raido Kuli Date: Thu, 24 Sep 2020 09:21:36 +0300 Subject: [PATCH 1/3] chore: Use project.isEmberCLIAddon() instead --- blueprints/ember-page-title/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/blueprints/ember-page-title/index.js b/blueprints/ember-page-title/index.js index 8dcd5ab0..083d8640 100644 --- a/blueprints/ember-page-title/index.js +++ b/blueprints/ember-page-title/index.js @@ -12,9 +12,7 @@ module.exports = { let isFastBootPresent = 'ember-cli-fastboot' in project.dependencies(); if (isFastBootPresent) { - let isAddon = 'ember-addon' in project.pkg; - - let indexHtmlPath = isAddon ? + let indexHtmlPath = project.isEmberCLIAddon() ? path.join(project.root, 'tests', 'dummy', 'app', 'index.html') : path.join(project.root, 'app', 'index.html'); From 248f1de88a4a7d4792a9193f77ca23643fd8a855 Mon Sep 17 00:00:00 2001 From: Raido Kuli Date: Thu, 24 Sep 2020 09:24:26 +0300 Subject: [PATCH 2/3] fix: Avoid crashing if title is not present in index.html --- blueprints/ember-page-title/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blueprints/ember-page-title/index.js b/blueprints/ember-page-title/index.js index 083d8640..01b638fe 100644 --- a/blueprints/ember-page-title/index.js +++ b/blueprints/ember-page-title/index.js @@ -25,7 +25,7 @@ module.exports = { ); const titleMatches = contents.match(/(.*)<\/title>/i); - const title = titleMatches[1] || "Example Title"; + const title = titleMatches && titleMatches[1] || "Example Title"; fs.writeFileSync( indexHtmlPath, contents.replace(/\s*<title>.*<\/title>/gi, ''), From 26d1cd601c92f3340c7a0160f5dc50f8fd96ec42 Mon Sep 17 00:00:00 2001 From: Raido Kuli <raido357@gmail.com> Date: Thu, 24 Sep 2020 09:34:05 +0300 Subject: [PATCH 3/3] fix: Support multiline <title> in index.html --- blueprints/ember-page-title/index.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/blueprints/ember-page-title/index.js b/blueprints/ember-page-title/index.js index 01b638fe..806b1836 100644 --- a/blueprints/ember-page-title/index.js +++ b/blueprints/ember-page-title/index.js @@ -24,15 +24,17 @@ module.exports = { } ); - const titleMatches = contents.match(/<title>(.*)<\/title>/i); + const titleMatches = contents.match(/<title>\s*(.*)\s*<\/title>/i); const title = titleMatches && titleMatches[1] || "Example Title"; - fs.writeFileSync( - indexHtmlPath, - contents.replace(/\s*<title>.*<\/title>/gi, ''), - { - encoding: 'utf8' - } - ); + if (titleMatches) { + fs.writeFileSync( + indexHtmlPath, + contents.replace(/\s*<title>\s*.*\s*<\/title>/gi, ''), + { + encoding: 'utf8' + } + ); + } opts.ui.writeWarnLine(`<title> has been removed from index.html due to ember-cli-fastboot being present, please add {{page-title "${title}"}} to application.hbs`); } }