@code-to-json/cli
Version:
48 lines • 1.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var validators_1 = require("./validators");
var path = require("path");
var validation_1 = require("./errors/validation");
var guards_1 = require("@code-to-json/core/guards");
function validateEntries(entries) {
return guards_1.isHomogenousArray(entries, function (e) { return typeof e === 'string'; });
}
exports.validateEntries = validateEntries;
function isExistingFilePath(rawPath, errors) {
var pathErrors = [];
if (typeof rawPath !== 'string') {
pathErrors.push('path must be a string');
}
if (validators_1.isEmpty(rawPath)) {
pathErrors.push('path must not be empty');
}
if (validators_1.isFileThatExists(path.join(process.cwd(), rawPath))) {
console.error('----', path.join(process.cwd(), rawPath));
pathErrors.push('path must point to a folder that exists');
}
if (pathErrors.length > 0) {
errors.path = pathErrors;
}
}
function validateConfig(rawOptions) {
var validationErrors = {};
var configPath = rawOptions.config;
var entries = rawOptions.entries;
if (!validateEntries(entries)) {
validationErrors.entries = ['Invalid entries'];
}
if (typeof configPath === 'string') {
isExistingFilePath(configPath, validationErrors);
}
if (Object.keys(validationErrors).length === 0) {
return ['ok', { entries: entries, configPath: configPath }];
}
else {
return [
'error',
new validation_1.default('configuration is invalid', validationErrors)
];
}
}
exports.validateConfig = validateConfig;
//# sourceMappingURL=config.js.map