From c0b0c37613bbc120a7cdf7cb02aa6dbdf0eb5ef0 Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Mon, 28 Sep 2020 20:02:43 +0200 Subject: [PATCH] [PoC] ZipArchive Adapter: Hack it till you make it --- lib/projectPreprocessor.js | 34 ++++++++++++++++++++++++++-------- package.json | 1 + 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/projectPreprocessor.js b/lib/projectPreprocessor.js index 4771a5a40..2542f985b 100644 --- a/lib/projectPreprocessor.js +++ b/lib/projectPreprocessor.js @@ -5,6 +5,7 @@ const {promisify} = require("util"); const readFile = promisify(fs.readFile); const jsyaml = require("js-yaml"); const typeRepository = require("@ui5/builder").types.typeRepository; +const ZipArchive = require("@ui5/fs").adapters.ZipArchive; const {validate} = require("./validation/validator"); class ProjectPreprocessor { @@ -391,15 +392,32 @@ class ProjectPreprocessor { try { configFile = await readFile(configPath, {encoding: "utf8"}); } catch (err) { - const errorText = "Failed to read configuration for project " + - `${project.id} at "${configPath}". Error: ${err.message}`; - - // Something else than "File or directory does not exist" or root project - if (err.code !== "ENOENT" || project._isRoot) { - throw new Error(errorText); + if (project.path.endsWith(".zip")) { + try { + project._zipAdapter = new ZipArchive({ + virBasePath: "/", + fsArchive: project.path + }); + const resource = await project._zipAdapter.byPath("/ui5.yaml"); + if (!resource) { + throw new Error(`File not found in ZIP archive: /ui5.yaml`); + } + configFile = await resource.getBuffer(); + } catch (err) { + throw new Error(`Error file reading from ZIP file at ${configPath} for project ` + + `${project.id}: ${err.message}\n${err.stack}`); + } } else { - log.verbose(errorText); - return null; + const errorText = "Failed to read configuration for project " + + `${project.id} at "${configPath}". Error: ${err.message}`; + + // Something else than "File or directory does not exist" or root project + if (err.code !== "ENOENT" || project._isRoot) { + throw new Error(errorText); + } else { + log.verbose(errorText); + return null; + } } } diff --git a/package.json b/package.json index 6633be73b..b4c44c56a 100644 --- a/package.json +++ b/package.json @@ -98,6 +98,7 @@ }, "dependencies": { "@ui5/builder": "^2.2.0", + "@ui5/fs": "^2.0.3", "@ui5/logger": "^2.0.0", "@ui5/server": "^2.2.4", "ajv": "^6.12.5",