Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject HTML at the end of <head> section #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
215 changes: 55 additions & 160 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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