gardr-validator-web
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -17,4 +17,4 @@ { | ||
"dependencies": { | ||
"bootswatch": "~3.1.1" | ||
"bootswatch": "3.2.0" | ||
} | ||
} |
@@ -11,7 +11,8 @@ var domready = require('domready'); | ||
function findParentTag(item, name, cb){ | ||
function findParentTag(item, cb){ | ||
if (!item || !item.parentNode){ | ||
return null; | ||
} | ||
if (item.parentNode.tagName.toUpperCase() === name.toUpperCase()){ | ||
var value = item.parentNode.getAttribute('data-expandable-container'); | ||
if (value !== null){ | ||
if (cb) { | ||
@@ -22,3 +23,3 @@ cb(item.parentNode); | ||
} | ||
return findParentTag(item.parentNode, name, cb); | ||
return findParentTag(item.parentNode, cb); | ||
} | ||
@@ -34,4 +35,3 @@ | ||
var elem = this; | ||
var tagName = elem.getAttribute('data-tag-name')||'li'; | ||
findParentTag(elem, tagName, function(list){ | ||
findParentTag(elem, function(list){ | ||
var added = klasses.toggleClass(list, 'expanded-state'); | ||
@@ -42,2 +42,1 @@ klasses.addClass(elem, 'expanded-state-button', added); | ||
}; | ||
@@ -52,2 +52,3 @@ var domready = require('domready'); | ||
var bannerContainer = document.getElementById('result-preview-container'); | ||
console.log('js/main.js:gardr-host -> start rendering', name); | ||
@@ -65,2 +66,3 @@ m.queue(name, { | ||
} | ||
console.log('js/main.js:gardr-host done rendering', name, res.rendered); | ||
var para = document.createElement('p'); | ||
@@ -67,0 +69,0 @@ para.innerHTML = 'Rendered <a href="'+options.previewUrl+'">'+options.previewUrl+'</a>. Viewport width '+ options.viewport.width+', height '+options.viewport.height; |
@@ -68,3 +68,9 @@ module.exports = [{ | ||
'sizes': { | ||
thresholdBytes: 150000 | ||
thresholdBytes: 150000, | ||
maxRequests: { | ||
style: 1 | ||
} | ||
}, | ||
'gardr': { | ||
enforceSpec: false | ||
} | ||
@@ -85,3 +91,9 @@ }, | ||
'sizes': { | ||
thresholdBytes: 150000 | ||
thresholdBytes: 150000, | ||
maxRequests: { | ||
style: 1 | ||
} | ||
}, | ||
'gardr': { | ||
enforceSpec: false | ||
} | ||
@@ -88,0 +100,0 @@ }, |
@@ -33,7 +33,13 @@ var os = require('os'); | ||
'default': {} | ||
}, | ||
runner: { | ||
doc: 'Runner config base options', | ||
format: '*', | ||
'default': {} | ||
} | ||
}); | ||
if (process.env.CONFIG_FILE) { | ||
console.log('process.env.CONFIG_FILE', process.env.CONFIG_FILE); | ||
console.log('config.js custom loading from process.env.CONFIG_FILE:', process.env.CONFIG_FILE); | ||
conf.loadFile( | ||
@@ -46,6 +52,10 @@ path.resolve( | ||
//conf.loadFile(addFile('defaults')); | ||
conf.load({"formats": require('../config/formats.js')}); | ||
conf.load({ | ||
"runner": require('../config/runner.js')(conf), | ||
"formats": require('../config/formats.js') | ||
}); | ||
conf.validate(); | ||
module.exports = conf; |
@@ -21,10 +21,18 @@ var storage = require('./storage.js'); | ||
function setError(id, msg, errObj){ | ||
console.log('jobs.js setError():', msg, errObj.message); | ||
log.error(msg, errObj); | ||
// setTimeout(function(){ | ||
// var stream = queue.readStream(); | ||
// stream.on('data', function(d) { | ||
// var jobId = d.key; | ||
// var work = JSON.parse(d.value); | ||
// console.log('pending job id: %s, work: %j', jobId, work.id); | ||
// }); | ||
// }, 1000); | ||
function setError(id, msg, err){ | ||
log.error(msg, {id: id, err: err}); | ||
return storage.set(id, { | ||
error: { | ||
error: true, | ||
err: errObj, | ||
message: msg | ||
err: err, | ||
message: msg + (err ? ':' + err.message : '') | ||
} | ||
@@ -38,4 +46,4 @@ }); | ||
// console.log('jobs.js', storageError.message/*, storageError.stack*/); | ||
//"Key not found in database"... | ||
return setError(id, 'Something went wrong. Storage error - Code 001:', storageError); | ||
//"Key not found in database"...? | ||
return setError(id, 'Something went wrong getting job. Storage error - Code 001:', storageError); | ||
} | ||
@@ -59,9 +67,6 @@ | ||
if (err){ | ||
return setError(id, 'Something went wrong. Storage error - Code 001:', err); | ||
return setError(id, 'Something went wrong. Storage error - Code 001', err); | ||
} | ||
var timer; | ||
queue.push(data, function(err){ | ||
clearTimeout(timer); | ||
var jobId = queue.push(data, function(err){ | ||
if (err){ | ||
@@ -73,15 +78,4 @@ console.log('jobs.js Queue.push error: ', err); | ||
} | ||
//console.log('jobs.js queue.push CALLBACK / done...'); | ||
}); | ||
// todo add timeout | ||
// timer = setTimeout(function(){ | ||
// // timed out: if not complete, kill it | ||
// console.log('jobs.js TIMER DONE'); | ||
// }, timeout); | ||
}); | ||
}); | ||
@@ -88,0 +82,0 @@ |
@@ -13,9 +13,11 @@ var pack = require('../package.json'); | ||
winston.alreadyLoaded = true; | ||
winston.add(winston.transports.DailyRotateFile, { | ||
filename: logFileName, | ||
datePattern: '.yyyyMMdd.log' | ||
}); | ||
winston.remove(winston.transports.Console); | ||
if (process.env.NODE_ENV !== 'test'){ | ||
winston.add(winston.transports.DailyRotateFile, { | ||
filename: logFileName, | ||
datePattern: '.yyyyMMdd.log' | ||
}); | ||
winston.remove(winston.transports.Console); | ||
} | ||
} | ||
module.exports = winston; |
@@ -9,3 +9,3 @@ var log = require('../logger.js'); | ||
return callback({message: 'Missing phantom url'}, null); | ||
} else { | ||
} else { | ||
throw new Error('Missing callback'); | ||
@@ -17,3 +17,3 @@ } | ||
var msg = ['Spawning / Processing', data && data.id, ' Spawning in ', data.runnerConfig.width, 'x', data.runnerConfig.height].join(' '); | ||
var msg = ['Spawning / Processing', data && data.id, ' Spawning in ', data && data.runnerConfig.width, 'x', data && data.runnerConfig.height].join(' '); | ||
log.info(msg); | ||
@@ -20,0 +20,0 @@ // console.log(msg); |
@@ -20,2 +20,3 @@ var Hoek = require('hoek'); | ||
var formats = config.get('formats'); | ||
var runnerConfigDefaults = config.get('runner'); | ||
@@ -111,2 +112,10 @@ /** | ||
// output runnerConfig defaults | ||
Object.keys(runnerConfigDefaults).forEach(function(key){ | ||
if (!output[key]){ | ||
output[key] = runnerConfigDefaults[key]; | ||
} | ||
}); | ||
output.format = { | ||
@@ -135,2 +144,1 @@ id: data.format.id, | ||
// module.exports({format: {id: 'mobil-vg', subId: 'default', index: 3}, output: {}, id: 'ads'}); | ||
@@ -35,3 +35,3 @@ var config = require('../config.js'); | ||
if (dataKey && data.output[dataKey]) { | ||
log.info('Served raw ' + dataTypes[dataKey] + ' ok:' + id); | ||
log.info('Served raw ' + dataTypes[dataKey] + ' ok:' + id, {id: id}); | ||
return reply(data.output[dataKey]).type(dataTypes[dataKey]); | ||
@@ -41,2 +41,3 @@ } | ||
if (dataKey && !data.output[dataKey]){ | ||
log.warn('Tried to request non-existant datatype', {id: id}); | ||
return reply(scriptLogErrorMessage('ID (' + id + ') has no type '+dataKey+'.')).type(dataTypes.js); | ||
@@ -53,2 +54,3 @@ } | ||
if (output.js && (!output.html || !output.css)) { | ||
log.info('Served raw js input', {id: id}); | ||
return reply(output.js).type(dataTypes.js); | ||
@@ -59,13 +61,3 @@ } | ||
if (output.html) { | ||
var trimmed = parseAndResolve(base, output.html); | ||
if (trimmed.pre) { | ||
resultHtmlString += toDocumentWrite(trimmed.pre); | ||
} | ||
if (trimmed.style) { | ||
resultHtmlString += toDocumentWrite(minifyCSS(trimmed.style), 'style'); | ||
} | ||
resultHtmlString += toDocumentWrite(trimmed.content); | ||
if (trimmed.script){ | ||
resultHtmlString += toDocumentWrite(trimmed.script, 'script'); | ||
} | ||
resultHtmlString += toDocumentWrite(parseAndResolve(base, output.html)); | ||
} | ||
@@ -87,3 +79,3 @@ | ||
reply(resultHtmlString).type('application/javascript'); | ||
log.info('Served composed file'); | ||
log.info('Served "composed" file for '+id, {id: id}); | ||
@@ -90,0 +82,0 @@ }); |
@@ -20,3 +20,7 @@ var uuid = require('node-uuid'); | ||
var processStamp = '_' + Date.now() + process.pid; | ||
internals.phantomWorker = function(data, next){ | ||
var id = data && data.id; | ||
log.info(id + ' processStamp', {processStamp: processStamp, id: id}); | ||
getReport(data, function (err, harvest, report) { | ||
@@ -31,12 +35,20 @@ data.state.processed = new Date(); | ||
}, | ||
message: 'An error occured. Code 002. ' + err.message | ||
message: 'An error occured. Code 002.\n\r ' + err.message | ||
}; | ||
log.error('An error occured. Code 002 (User input / Runnner Error):', err); | ||
return storage.set(data.id, data); | ||
log.error('An error occured. Code 002. (Runtime Error):', {error: err, id: id}); | ||
storage.set(id, data); | ||
// set success on job to avoid retries | ||
return next(); | ||
} | ||
var hasPredefinedError = (data && !data.error); | ||
var hasNoAppError = (data && !data.error); | ||
var hasOutput = harvest && report; | ||
if (hasPredefinedError || ((!err || hasPredefinedError) && data && hasOutput)) { | ||
log.info('getReport returned result from phamtom', { | ||
'id': id, | ||
'hasNoAppError': !!hasNoAppError, | ||
'hasOutput': !!hasOutput | ||
}); | ||
if (hasNoAppError || ((!err || hasNoAppError) && data && hasOutput)) { | ||
data.harvest = harvest; | ||
@@ -46,3 +58,4 @@ data.report = formatReport(report); | ||
storage.set(data.id, data, next); | ||
log.info('Formating done, saving result.', {'id': id}); | ||
storage.set(id, data, next); | ||
}); | ||
@@ -54,5 +67,11 @@ }; | ||
if (!_queue){ | ||
_queue = jobs(internals.phantomWorker, 5, 60) | ||
_queue = jobs(internals.phantomWorker, 5, 60); | ||
} | ||
_queue.push(id); | ||
if (id){ | ||
_queue.push(id); | ||
} | ||
}; | ||
if (process.env.NODE_ENV !== 'test'){ | ||
internals.queue(); | ||
} | ||
@@ -212,2 +231,4 @@ | ||
log.info('Generating new validation '+id,{id: id}); | ||
if (internals.hasCodePayload(data.input)) { | ||
@@ -214,0 +235,0 @@ data.output.url = internals.generateUserEntryUrl(data.host, id); |
var config = require('./config.js'); | ||
var pathLib = require('path'); | ||
var os = require('os'); | ||
var pathLib = require('path'); | ||
var fs = require('fs'); | ||
var pack = require('../package.json'); | ||
module.exports = function(id){ | ||
var tmpDir = config.get('tmpDir'); | ||
var tmpDir; | ||
function setup(){ | ||
var appDir = pathLib.resolve(pathLib.join(__dirname, '..')); | ||
tmpDir = config.get('tmpDir'); | ||
if (tmpDir){ | ||
tmpDir = pathLib.resolve(tmpDir); | ||
} | ||
if (!tmpDir || typeof tmpDir === 'undefined' || tmpDir === 'undefined'){ | ||
tmpDir = os.tmpdir(); | ||
} | ||
return pathLib.resolve(pathLib.join(tmpDir, id)); | ||
if (appDir == tmpDir || !tmpDir) { | ||
tmpDir = pathLib.join(appDir, 'phantom_output_files_' + pack.version + '-' + (process.env.NODE_ENV||'X')); | ||
try{ | ||
fs.mkdirSync(tmpDir); | ||
}catch(e){} | ||
} | ||
} | ||
module.exports = function(id){ | ||
if (!tmpDir){ | ||
setup(); | ||
} | ||
return pathLib.join(tmpDir, id); | ||
}; |
@@ -74,6 +74,11 @@ var DecompressZip = require('decompress-zip'); | ||
unzipper.on('extract', function (log) { | ||
unzipper.on('extract', function (ziplog) { | ||
if (config.get('env') === 'development'){ | ||
require('colors'); | ||
console.log('FINISHED EXTRACTING:\n'.yellow, uploadedZipFile.path, '\n', (JSON.stringify(log, null, 4)+'').blue.bold, '\n->', data.output.zip.path); | ||
console.log('FINISHED EXTRACTING:\n'.yellow, | ||
uploadedZipFile.path, '\n', | ||
(JSON.stringify(ziplog, null, 4)+'').blue.bold, | ||
'\n->', | ||
data.output.zip.path | ||
); | ||
} | ||
@@ -80,0 +85,0 @@ |
@@ -14,2 +14,3 @@ var pack = require('../package.json'); | ||
view.minifyExtention = isDevelopment ? '' : '.min'; | ||
view.iframeUrl = config.get('runner').iframeUrl||'./preview/built/iframe.html'; | ||
@@ -16,0 +17,0 @@ if (isDevelopment || request.query.debug) { |
{ | ||
"name": "gardr-validator-web", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "The Web ui for the garðr validator", | ||
"main": "server.js", | ||
"scripts": { | ||
"clean": "rm -rf ./results-db-* && rm -rf logs/* && rm -rf ./client/built", | ||
"clean": "rm -rf ./results-db-* && rm -rf logs/* && rm -rf ./client/built && rm -rf phantom_output_files_*", | ||
"build-browser-js": "sh ./scripts/build-browser-js.sh", | ||
@@ -12,3 +12,4 @@ "build-css": "./node_modules/.bin/lessc client/styles.less client/built/styles.css", | ||
"build": "./node_modules/.bin/bower install --allow-root && npm run build-browser-js && npm run build-css", | ||
"start": "npm run build && npm run pre-start && node server.js", | ||
"postinstall": "npm run build", | ||
"start": "npm run pre-start && node server.js", | ||
"pre-start": "mkdir -p ./logs", | ||
@@ -35,5 +36,5 @@ "start-dev": "npm run pre-start && npm run watch-js & sleep 3 && NODE_ENV=development ./node_modules/.bin/nodemon", | ||
"dependencies": { | ||
"gardr-validator": "^0.6.0", | ||
"gardr-validator": "^0.7.0", | ||
"gardr-host": "^0.5.0", | ||
"document-write-html": "^0.1.3", | ||
"document-write-html": "^0.2.1", | ||
"hapi": "^6.0.2", | ||
@@ -40,0 +41,0 @@ "hoek": "^2.3.0", |
var expect = require('expect.js'); | ||
var proxyquire = require('proxyquire'); | ||
var proxyquire = require('proxyquire').noPreserveCache(); | ||
var multipart = require('../helpers/multipart.js'); | ||
@@ -4,0 +4,0 @@ |
@@ -6,7 +6,8 @@ function insertBanner(){ | ||
div.setAttribute('style', 'text-align:center;width:100%;height:225px;background:green;color:white;line-height: 225px;'); | ||
div.innerHTML = '<h1>script.js test</h1>'; | ||
div.innerHTML = '<h1>fixtures/script1.js test</h1>'; | ||
return div; | ||
} | ||
window.onload = function () { | ||
insertBanner(); | ||
var bannerEl = insertBanner(); | ||
@@ -20,4 +21,9 @@ var el = document.createElement('script'); | ||
}); | ||
}, 500); | ||
}, 500); | ||
jQuery(bannerEl).click(function(){ | ||
console.log('fixtures/script1.js - > jquery clickhandler'); | ||
}).mouseover(function(){ | ||
console.log('fixtures/script1.js - > jquery clickhandler'); | ||
}); | ||
}; | ||
@@ -24,0 +30,0 @@ //el.src = 'http://localhost:8000/components/jquery/jquery.js'; |
@@ -1,2 +0,2 @@ | ||
var proxyquire = require('proxyquire'); | ||
var proxyquire = require('proxyquire').noPreserveCache(); | ||
var storage = require('../../lib/storage.js'); | ||
@@ -3,0 +3,0 @@ var createJobs = require('../../lib/jobs.js'); |
@@ -5,3 +5,3 @@ var expect = require('expect.js'); | ||
var proxyquire = require('proxyquire'); | ||
var proxyquire = require('proxyquire').noPreserveCache(); | ||
@@ -52,3 +52,3 @@ var mockedRunner = proxyquire('../../lib/report/index.js', { | ||
it('should work to run', function(done){ | ||
this.timeout = 3000; | ||
this.timeout(4000); | ||
var options = { | ||
@@ -55,0 +55,0 @@ output: { |
var expect = require('expect.js'); | ||
var proxyquire = require('proxyquire'); | ||
var proxyquire = require('proxyquire').noPreserveCache(); | ||
@@ -5,0 +5,0 @@ var storage = proxyquire('../../lib/storage.js', { |
var expect = require('expect.js'); | ||
var proxyquire = require('proxyquire'); | ||
var proxyquire = require('proxyquire').noPreserveCache(); | ||
var unzip = require('../../lib/unzip.js'); | ||
@@ -4,0 +4,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
636909
80
2466
1
16
+ Addedcss-stringify@2.0.0(transitive)
+ Addeddocument-write-html@0.2.3(transitive)
+ Addedgardr-validator@0.7.4(transitive)
- Removedcss-parse@1.7.0(transitive)
- Removedcss-stringify@1.4.1(transitive)
- Removeddocument-write-html@0.1.3(transitive)
- Removedgardr-validator@0.6.2(transitive)
- Removedhtmlparser-to-html@0.0.5(transitive)
Updateddocument-write-html@^0.2.1
Updatedgardr-validator@^0.7.0