1+ 'use strict' ;
2+
13/* eslint-env node */
4+ const path = require ( 'path' ) ;
25const recast = require ( 'recast' ) ;
3- const { readFileSync, writeFileSync } = require ( 'fs' ) ;
6+ const { readFileSync, writeFileSync, existsSync } = require ( 'fs' ) ;
47
58module . exports = {
69 description : '' ,
@@ -9,6 +12,11 @@ module.exports = {
912 } ,
1013
1114 afterInstall ( ) {
15+ this . updateBabelTargets ( ) ;
16+ this . removeTitleFromIndexHtml ( ) ;
17+ } ,
18+
19+ updateBabelTargets ( ) {
1220 let targetsFile = './config/targets.js'
1321
1422 if ( this . project . isEmberCLIAddon ( ) ) {
@@ -40,5 +48,37 @@ module.exports = {
4048 } ) ;
4149
4250 writeFileSync ( targetsFile , recast . print ( targetsAst , { tabWidth : 2 , quote : 'single' } ) . code ) ;
51+ } ,
52+
53+ removeTitleFromIndexHtml ( ) {
54+ let isEmberPageTitlePresent = 'ember-page-title' in this . project . dependencies ( ) ;
55+
56+ if ( isEmberPageTitlePresent ) {
57+ let indexHtmlPath = this . project . isEmberCLIAddon ( ) ?
58+ path . join ( this . project . root , 'tests' , 'dummy' , 'app' , 'index.html' ) :
59+ path . join ( this . project . root , 'app' , 'index.html' ) ;
60+
61+ if ( existsSync ( indexHtmlPath ) ) {
62+ const contents = readFileSync (
63+ indexHtmlPath ,
64+ {
65+ encoding : 'utf8'
66+ }
67+ ) ;
68+
69+ const titleMatches = contents . match ( / < t i t l e > \s * ( .* ) \s * < \/ t i t l e > / i) ;
70+ const title = titleMatches && titleMatches [ 1 ] || "Example Title" ;
71+ if ( titleMatches ) {
72+ writeFileSync (
73+ indexHtmlPath ,
74+ contents . replace ( / \s * < t i t l e > \s * .* \s * < \/ t i t l e > / gi, '' ) ,
75+ {
76+ encoding : 'utf8'
77+ }
78+ ) ;
79+ }
80+ this . ui . writeWarnLine ( `<title> has been removed from index.html due to ember-page-title being present, please add {{page-title "${ title } "}} to application.hbs` ) ;
81+ }
82+ }
4383 }
4484} ;
0 commit comments