Skip to content

Commit

Permalink
feat: Blueprint removes <title> from app/index.html upon install for …
Browse files Browse the repository at this point in the history
…FastBoot (#177)

* Blueprint removes <title> from app/index.html upon install for FastBoot

* Make replacement regular expression more strict
  • Loading branch information
raido authored Sep 23, 2020
1 parent 0c7b999 commit 84a39f0
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion blueprints/ember-page-title/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
'use strict';

const path = require('path');
const fs = require('fs');

module.exports = {
normalizeEntityName: function () {}
normalizeEntityName() {},

afterInstall(opts) {
let project = opts.project;

let isFastBootPresent = 'ember-cli-fastboot' in project.dependencies();

if (isFastBootPresent) {
let isAddon = 'ember-addon' in project.pkg;

let indexHtmlPath = isAddon ?
path.join(project.root, 'tests', 'dummy', 'app', 'index.html') :
path.join(project.root, 'app', 'index.html');

if (fs.existsSync(indexHtmlPath)) {
const contents = fs.readFileSync(
indexHtmlPath,
{
encoding: 'utf8'
}
);

const titleMatches = contents.match(/<title>(.*)<\/title>/i);
const title = titleMatches[1] || "Example Title";
fs.writeFileSync(
indexHtmlPath,
contents.replace(/\s*<title>.*<\/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`);
}
}
}
};

0 comments on commit 84a39f0

Please sign in to comment.