Skip to content

Commit

Permalink
Provide a method to install files and inject HTML at the end of <head…
Browse files Browse the repository at this point in the history
…> section
  • Loading branch information
ikedam committed Feb 10, 2020
1 parent b932d81 commit b7fc2f0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
30 changes: 30 additions & 0 deletions index.js
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;
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "screenshoter-report-analyzer",
"description": "A beautiful angular based analytics tool to visually check and fix protractor tests results.",
"version": "0.6.0",
"dependencies": {},
"dependencies": {
"fs-extra": "^7.0.0"
},
"main": "index.js",
"scripts": {
"test": "gulp test",
"release": "standard-version"
Expand Down

0 comments on commit b7fc2f0

Please sign in to comment.