Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function readJson (file) {
if (!check('String', file)) return
if (file.slice(-5) !== '.json') {
console.log(chalk.red(`\n${chalk.bold('AppVersion:')} ${file} is not a Json\n`))
process.exit(1)
}
try {
let obj = require(file === JSON_FILE ? resolve('./', file) : resolve(file))
// checks if the appversion.json is at the latest version
if (file === JSON_FILE && (!obj.config || obj.config.appversion !== apvVersion)) obj = updateAppversion(obj)
return obj
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
console.log(chalk.red(`\n${chalk.bold('AppVersion:')} Could not find appversion.json\nType ${chalk.bold('\'apv init\'')} for generate the file and start use AppVersion.\n`))
process.exit(1)
} else {
throw new Error(err)
}
function setStatus (param) {
if (!check('String', param)) return
let obj = readJson(JSON_FILE)
let previousObj = {
status: {
stage: obj.status.stage,
number: obj.status.number
}
}
let status = param.split('.')
if (status[1] && !check('Number', Number(status[1]))) {
console.log(chalk.red(`\n${chalk.bold('AppVersion:')} Insert a valid status.number number\n`))
return
}
let match = ['Stable', 'stable', 'RC', 'rc', 'Beta', 'beta', 'Alpha', 'alpha']
if (match.indexOf(status[0]) === -1) {
console.log(chalk.red(`\n${chalk.bold('AppVersion:')} Insert a valid status.stage string\n`))
return
}
obj.status.stage = status[0]
// if there's not the status number, it's setted to zero
obj.status.number = Number(status[1]) || 0
writeJson(obj, chalk.green(`\n${chalk.bold('AppVersion:')} Status updated to ${status[0]}.${status[1] || 0}\n`))
createBadge('status', true, previousObj)
}
function createLogger(prefix) {
check(prefix, String);
// Return noop if logging is disabled.
if(Migrations.options.log === false) {
return function() {};
}
return function(level, ...args) {
//check(level, Match.OneOf('info', 'error', 'warn', 'debug'));
var logger = Migrations.options && Migrations.options.logger;
if(logger && _.isFunction(logger)) {
logger({level, ...args });
} else {
console[level]({ level, ...args });
function composePattern (pattern, callback) {
if (!check('String', pattern)) throw new Error('composePattern() -> pattern is not a string')
if (!check('Function', callback)) throw new Error('composePattern() -> callback is not a function')
pattern = pattern.split('')
getAppVersion((err, obj) => {
if (err) console.log(err)
let ptt = ''
pattern.map((ele) => {
ptt += switchPattern(obj, ele)
})
callback(ptt)
})
}
input.pages.forEach(page => {
if (!typeCheck(PAGE_INPUT_TYPE, page) && !isSinglePageInput) {
log('Expected input:');
log(INPUT_TYPE);
log('Received input:');
console.dir(input);
throw new Error('Received invalid input');
}
});
} else if (isSinglePageInput) {
function switchPattern (obj, pattern) {
if (!check('String', pattern)) throw new Error('switchPattern() -> pattern is not a string')
if (!check('Object', obj)) throw new Error('switchPattern() -> obj is not an object')
switch (pattern) {
case 'M' || 'B':
return obj.version.major
case 'm' || 'F':
return obj.version.minor
case 'p' || 'f':
return obj.version.patch
case 'S':
return obj.status.stage
case 's':
return obj.status.number
case 'n':
return obj.build.number
case 't':
return obj.build.total
module.exports.middleware = (req, res, next) => {
if (!typeCheck('Object', req)) {
throw new ErrorWrapper('req argument wrong type', 500)
}
if (!typeCheck('Object', res)) {
throw new ErrorWrapper('res argument wrong type', 500)
}
if (next && !typeCheck('Function', next)) {
throw new ErrorWrapper('next argument wrong type', 500)
}
}
module.exports.main = (argument, type, required) => {
/**
* check if required
*/
if (required && !argument) {
throw new ErrorWrapper('Required parameters not supplied', 500)
}
/**
* check arguments type
*/
const isArgumentExist = [null, false, NaN].includes(argument) || argument
if (isArgumentExist && !typeCheck(type, argument)) {
throw new ErrorWrapper('Argument wrong type', 500)
}
}
validator.type.some(function (type) {
return valid = typeCheck(type, data[key]);
});
function createBadge (tag, updateMD, previousObj) {
if (!check('String', tag) && !check('Boolean | Undefined', updateMD) && !check('Object | Undefined', previousObj)) return
tag === 'status' ? statusBadge(updateMD, previousObj) : versionBadge(updateMD, previousObj)
}