UNPKG

mobify-analytics-sdk

Version:

A unified way to setup Mobify analytics

57 lines (45 loc) 1.4 kB
#! /usr/bin/env node /** * A validator script for parsing our config * * validate-sdk <absolute-path-to-config> [-e] * -e expect an error on the config */ // NOTE: mobify-debug-js require windows object var fakeGlobal = function() { global.window = {}; global.document = {}; global.Mobify = {}; }; fakeGlobal(); var path = require('path'); var Validator = require('jsonschema').Validator; var schema = require('../sdkschema').SDKschema; var validate = function(file, expectError) { var absPath = path.resolve(file); console.log('Validating file: ' + absPath); var v = new Validator(); var configFile = require(absPath); if (!configFile) { throw 'Cannot find config file "' + absPath + '"'; } if (!configFile.config) { throw 'Config file must define .config'; } var validateResult = v.validate(configFile.config, schema); // for running test if (expectError) { if (!validateResult.valid) { console.log('File "' + file + '"" is a broken config file.'); } else { throw 'We did not throw error'; } return; } if (!validateResult.valid) { console.log(validateResult); throw validateResult.errors; } console.log('File "' + file + '"" is a valid Analytics SDK config file.'); }; validate(process.argv[2], process.argv[3] === '-e');