UNPKG

@wbg-mde/repository

Version:

Managing all common method for file system CRUD operations.

50 lines (49 loc) 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("fs"); const path = require("path"); const test_config_1 = require("./test_config"); const import_geospatial_1 = require("../import-master/import.geospatial"); const export_geospatial_1 = require("../export-master/export.geospatial"); class ImportGeospatialTest { constructor() { this.importGeospatial = new import_geospatial_1.ImportGeospatial(); this.exportGeospatial = new export_geospatial_1.ExportGeospatial(); } execute() { try { fs.readdir(test_config_1.TestConfig.inputPath.geospatial, (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.geospatial, filepath); const outputPath = path.join(test_config_1.TestConfig.outputPath.geospatial, filepath); this.importGeospatial.readImportedFile(inputPath, test_config_1.TestConfig.geospatialOptions.type, test_config_1.TestConfig.geospatialOptions.language, (resp) => { if (resp.result === "ok") { const project = { header: { type: test_config_1.TestConfig.geospatialOptions.type, language: test_config_1.TestConfig.geospatialOptions.language }, metadata: resp.data }; this.exportGeospatial.exportStudy(outputPath, project, (res) => { if (res.result === "ok") { console.log(`file ${filepath} completed successfully!!`); } else { console.log(`file ${filepath} completed with errors!!`); } }); } }); } } exports.ImportGeospatialTest = ImportGeospatialTest;