@vulcan-sql/build
Version:
VulcanSQL package for building projects
61 lines • 2.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileSchemaReader = void 0;
const tslib_1 = require("tslib");
const models_1 = require("../../../models/index");
const glob = require("glob");
const fs_1 = require("fs");
const path = require("path");
const options_1 = require("../../../options/index");
const core_1 = require("@vulcan-sql/core");
const inversify_1 = require("inversify");
const containers_1 = require("../../../containers/index");
let FileSchemaReader = class FileSchemaReader extends models_1.SchemaReader {
constructor(options, config, moduleName) {
super(config, moduleName);
this.options = options;
}
readSchema() {
var _a;
return tslib_1.__asyncGenerator(this, arguments, function* readSchema_1() {
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.folderPath))
throw new core_1.ConfigurationError(`Config schema-parser.folderPath must be defined`);
const files = yield tslib_1.__await(this.getSchemaFilePaths());
for (const file of files) {
const fileName = path.relative(this.options.folderPath, file);
const { ext } = path.parse(fileName);
const sourceName = fileName.replace(new RegExp(`\\${ext}$`), '');
yield yield tslib_1.__await({
sourceName,
content: yield tslib_1.__await(fs_1.promises.readFile(file, 'utf8')),
type: models_1.SchemaFormat.YAML,
});
}
});
}
getSchemaFilePaths() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
glob(path
.resolve(this.options.folderPath, '**', '*.yaml')
.split(path.sep)
.join('/'), { nodir: true }, (err, files) => {
if (err)
return reject(err);
else
return resolve(files);
});
});
});
}
};
FileSchemaReader = tslib_1.__decorate([
(0, core_1.VulcanInternalExtension)(),
(0, core_1.VulcanExtensionId)(models_1.SchemaReaderType.LocalFile),
tslib_1.__param(0, (0, inversify_1.inject)(containers_1.TYPES.SchemaParserOptions)),
tslib_1.__param(1, (0, inversify_1.inject)(core_1.TYPES.ExtensionConfig)),
tslib_1.__param(2, (0, inversify_1.inject)(core_1.TYPES.ExtensionName)),
tslib_1.__metadata("design:paramtypes", [options_1.SchemaParserOptions, Object, String])
], FileSchemaReader);
exports.FileSchemaReader = FileSchemaReader;
//# sourceMappingURL=fileSchemaReader.js.map