Skip to content

Commit

Permalink
Blueprint removes <title> from app/index.html upon install for FastBoot
Browse files Browse the repository at this point in the history
  • Loading branch information
raido committed Sep 23, 2020
1 parent 7266d6b commit 0561c2b
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 0561c2b

Please sign in to comment.