-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Blueprint removes <title> from app/index.html upon install for …
…FastBoot (#177) * Blueprint removes <title> from app/index.html upon install for FastBoot * Make replacement regular expression more strict
- Loading branch information
Showing
1 changed file
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
} | ||
} | ||
} | ||
}; |