@wbg-mde/repository
Version:
Managing all common method for file system CRUD operations.
50 lines (49 loc) • 2.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const test_config_1 = require("./test_config");
const import_ddi_1 = require("../import-master/import.ddi");
const export_ddi_1 = require("../export-master/export.ddi");
class ImportDDITest {
constructor() {
this.importDDI = new import_ddi_1.ImportDDI();
this.exportDDI = new export_ddi_1.ExportDDI();
}
execute() {
try {
fs.readdir(test_config_1.TestConfig.inputPath.ddi, (err, files) => {
if (files) {
files.reduce((p, x) => p.then(_ => this.executeFile(x)), Promise.resolve());
}
});
}
catch (e) {
console.log('execute error >> ' + e);
}
}
executeFile(filepath) {
const inputPath = path.join(test_config_1.TestConfig.inputPath.ddi, filepath);
const outputPath = path.join(test_config_1.TestConfig.outputPath.ddi, filepath);
this.importDDI.readImportedFile(inputPath, test_config_1.TestConfig.ddiOptions.type, test_config_1.TestConfig.ddiOptions.language, test_config_1.TestConfig.ddiOptions.options, (resp) => {
if (resp.result === "ok") {
const project = {
header: {
type: test_config_1.TestConfig.ddiOptions.type,
language: test_config_1.TestConfig.ddiOptions.language
},
metadata: resp.data
};
this.exportDDI.exportStudy(outputPath, project, (res) => {
if (res.result === "ok") {
console.log(`file ${filepath} completed successfully!!`);
}
else {
console.log(`file ${filepath} completed with errors!!`);
}
});
}
});
}
}
exports.ImportDDITest = ImportDDITest;