-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a method to install files and inject HTML at the end of <head…
…> section
- Loading branch information
Showing
2 changed files
with
34 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const fse = require('fs-extra'); | ||
const path = require('path'); | ||
|
||
/** | ||
* Copy files for screenshoter-report-analyzer to the specified directory. | ||
* | ||
* @param {String} dest The destination directory | ||
* @param {Object} options Optional parameters. | ||
* injectToHead: HTML string to inject into the end of the <head> section. | ||
* @param {Promise} a promise | ||
*/ | ||
function setup(dest, options) { | ||
const src = path.join(__dirname, 'dist'); | ||
return fse.copy(src, dest).then(() => { | ||
if (!options || !options.injectToHead) { | ||
return; | ||
} | ||
const indexFile = path.join(dest, 'index.html'); | ||
const endOfHead = /(<\/head\s*>)/i; | ||
let html = fs.readFileSync(indexFile, {encoding: 'utf-8'}); | ||
html = html.replace(endOfHead, match => { return options.injectToHead + match; }); | ||
fs.writeFileSync(indexFile, html, {encoding: 'utf-8'}) | ||
return; | ||
}); | ||
} | ||
|
||
module.exports.setup = setup; |
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