sardines-compile-time-tools
Version:
sardines.compile-time-tools.js is part of the sardines.io project
51 lines (50 loc) • 2.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.readSardinesConfigFile = void 0;
var path = require("path");
var fs = require("fs");
exports.readSardinesConfigFile = function (sardinesConfigFile) {
if (!fs.existsSync(sardinesConfigFile)) {
throw ("Sardines configure file [" + sardinesConfigFile + "] does not exist");
}
if (!fs.lstatSync(sardinesConfigFile).isFile()) {
throw ("Sardines configure file [" + sardinesConfigFile + "] is invalid");
}
if (path.extname(sardinesConfigFile).toLowerCase() !== '.json') {
throw ("Sardines configure file [" + sardinesConfigFile + "] must in JSON format");
}
var sardinesConfig = null;
try {
sardinesConfig = JSON.parse(fs.readFileSync(sardinesConfigFile).toString());
}
catch (e) {
throw ("Sardines configure file [" + sardinesConfigFile + "] has broken");
}
if (!sardinesConfig || JSON.stringify(sardinesConfig) === JSON.stringify({})) {
throw ("Sardines configure file [" + sardinesConfigFile + "] is empty");
}
if (!sardinesConfig.application || typeof sardinesConfig.application !== 'string') {
throw ("Application name is missing in sardines configure file [" + sardinesConfigFile + "]");
}
if (!sardinesConfig.repositoryEntries || !Array.isArray(sardinesConfig.repositoryEntries) || sardinesConfig.repositoryEntries.length === 0) {
throw ("Repository entries are missing in sardines configure file [" + sardinesConfigFile + "]");
}
if (sardinesConfig.srcRootDir && typeof sardinesConfig.srcRootDir !== 'string') {
throw ("srcRootDir is wrong in sardines configure file [" + sardinesConfigFile + "]");
}
if (sardinesConfig.sardinesDir && typeof sardinesConfig.sardinesDir !== 'string') {
throw ("sardinesDir is wrong in sardines configure file [" + sardinesConfigFile + "]");
}
if (!sardinesConfig.srcRootDir)
sardinesConfig.srcRootDir = './src';
if (!sardinesConfig.sardinesDir)
sardinesConfig.sardinesDir = 'sardines';
for (var _i = 0, _a = sardinesConfig.repositoryEntries; _i < _a.length; _i++) {
var entry = _a[_i];
if (!entry.user && !entry.password)
entry.password = 'anonymous';
if (!entry.user)
entry.user = 'anonymous';
}
return sardinesConfig;
};