@@ -6,6 +6,7 @@ const execa = require('execa');
66const quickTemp = require ( 'quick-temp' ) ;
77const hostedGitInfo = require ( 'hosted-git-info' ) ;
88const maybeMigrateSiteFormat = require ( './migration' ) ;
9+ const findAndReplaceInDirectory = require ( '../utils/find-and-replace-in-directory' ) ;
910const { LATEST_VERSION_NAME } = require ( '../..' ) ;
1011
1112module . exports = class AddonDocsDeployPlugin {
@@ -201,38 +202,22 @@ module.exports = class AddonDocsDeployPlugin {
201202 }
202203
203204 _updateIndexContents ( context , stagingDirectory , appRoot , deployVersion ) {
204- let indexPath = `${ stagingDirectory } /${ appRoot } /index.html ` ;
205- let rootURL = [ this . _getRootURL ( ) , appRoot ]
205+ const directory = `${ stagingDirectory } /${ appRoot } ` ;
206+ const rootURL = [ this . _getRootURL ( ) , appRoot ]
206207 . filter ( Boolean )
207208 . join ( '/' )
208209 . replace ( / \\ / g, '/' ) ;
209- let addonDocsRootURL = rootURL === '' ? '/' : `/${ rootURL } /` ;
210- let contents = fs . readFileSync ( indexPath , 'utf-8' ) ;
211- let encodedVersion = encodeURIComponent ( JSON . stringify ( deployVersion ) ) ;
212- let updated = this . _macroReplaceIndexContent (
213- contents ,
214- addonDocsRootURL ,
215- encodedVersion ,
216- ) ;
217-
218- fs . writeFileSync ( indexPath , updated ) ;
219- }
210+ const addonDocsRootURL = rootURL === '' ? '/' : `/${ rootURL } /` ;
211+ const encodedVersion = encodeURIComponent ( JSON . stringify ( deployVersion ) ) ;
220212
221- _macroReplaceIndexContent ( contents , addonDocsRootURL , encodedVersion ) {
222- return contents
223- . replace (
224- '%2FADDON_DOCS_ROOT_URL%2F' ,
225- encodeURIComponent ( addonDocsRootURL ) ,
226- )
227- . replace ( / \/ ? A D D O N _ D O C S _ R O O T _ U R L \/ ? / g, addonDocsRootURL )
228- . replace ( / % 2 2 A D D O N _ D O C S _ D E P L O Y _ V E R S I O N % 2 2 / g, encodedVersion ) ;
213+ findAndReplaceInDirectory ( directory , addonDocsRootURL , encodedVersion ) ;
229214 }
230215
231216 _currentDeployVersion ( ) {
232- let curpath = path . join ( 'versions' , this . _getVersionPath ( ) ) ;
233- let name = this . userConfig . getVersionName ( ) ;
234- let sha = this . userConfig . repoInfo . sha ;
235- let tag = this . userConfig . repoInfo . tag ;
217+ const curpath = path . join ( 'versions' , this . _getVersionPath ( ) ) ;
218+ const name = this . userConfig . getVersionName ( ) ;
219+ const sha = this . userConfig . repoInfo . sha ;
220+ const tag = this . userConfig . repoInfo . tag ;
236221 return { path : curpath , name, sha, tag, key : name } ;
237222 }
238223
0 commit comments