File tree Expand file tree Collapse file tree 2 files changed +59
-2
lines changed Expand file tree Collapse file tree 2 files changed +59
-2
lines changed Original file line number Diff line number Diff line change @@ -155,12 +155,18 @@ module.exports = class AddonDocsDeployPlugin {
155155 let addonDocsRootURL = rootURL === '' ? '/' : `/${ rootURL } /` ;
156156 let contents = fs . readFileSync ( indexPath , 'utf-8' ) ;
157157 let encodedVersion = encodeURIComponent ( JSON . stringify ( deployVersion ) ) ;
158- let updated = contents . replace ( / \/ ? A D D O N _ D O C S _ R O O T _ U R L \/ ? / g, addonDocsRootURL )
159- . 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 ) ;
158+ let updated = this . _macroReplaceIndexContent ( contents , addonDocsRootURL , encodedVersion ) ;
160159
161160 fs . writeFileSync ( indexPath , updated ) ;
162161 }
163162
163+ _macroReplaceIndexContent ( contents , addonDocsRootURL , encodedVersion ) {
164+ return contents
165+ . replace ( '%2FADDON_DOCS_ROOT_URL%2F' , encodeURIComponent ( addonDocsRootURL ) )
166+ . replace ( / \/ ? A D D O N _ D O C S _ R O O T _ U R L \/ ? / g, addonDocsRootURL )
167+ . 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 ) ;
168+ }
169+
164170 _currentDeployVersion ( ) {
165171 let curpath = path . join ( 'versions' , this . _getVersionPath ( ) ) ;
166172 let name = this . userConfig . getVersionName ( ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const QUnit = require ( 'qunit' ) ;
4+ const AddonDocsDeployPlugin = require ( '../../../lib/deploy/plugin' ) ;
5+
6+ const qModule = QUnit . module ;
7+ const test = QUnit . test ;
8+
9+ qModule ( '`deploy` | plugin test' , hooks => {
10+ hooks . beforeEach ( function ( ) {
11+ this . pluginInstance = new AddonDocsDeployPlugin ( ) ;
12+ } ) ;
13+
14+ test ( '_macroReplaceIndexContent' , function ( assert ) {
15+ const contents = `
16+ <!DOCTYPE html>
17+ <html>
18+ <head>
19+ <meta name="dummy/config/environment" content="%7B%22rootURL%22%3A%22%2FADDON_DOCS_ROOT_URL%2F%22%7D" />
20+ </head>
21+ <body>
22+ <script src="/ADDON_DOCS_ROOT_URL/assets/vendor.js"></script>
23+ <script src="/ADDON_DOCS_ROOT_URL/assets/dummy.js"></script>
24+ </body>
25+ </html>
26+ ` ;
27+ const encodedVersion = encodeURIComponent ( JSON . stringify ( {
28+ path : 'versions/master' ,
29+ name : 'master' ,
30+ sha : 'eef3' ,
31+ tag : null ,
32+ key : 'master'
33+ } ) ) ;
34+ const addonDocsRootURL = '/my-addon/versions/master/'
35+ const actual = this . pluginInstance . _macroReplaceIndexContent ( contents , addonDocsRootURL , encodedVersion ) ;
36+ const expected = `
37+ <!DOCTYPE html>
38+ <html>
39+ <head>
40+ <meta name="dummy/config/environment" content="%7B%22rootURL%22%3A%22%2Fmy-addon%2Fversions%2Fmaster%2F%22%7D" />
41+ </head>
42+ <body>
43+ <script src="/my-addon/versions/master/assets/vendor.js"></script>
44+ <script src="/my-addon/versions/master/assets/dummy.js"></script>
45+ </body>
46+ </html>
47+ ` ;
48+
49+ assert . equal ( actual , expected ) ;
50+ } ) ;
51+ } ) ;
You can’t perform that action at this time.
0 commit comments