Skip to content

Commit c0b0c37

Browse files
committed
[PoC] ZipArchive Adapter: Hack it till you make it
1 parent 2f6d847 commit c0b0c37

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

lib/projectPreprocessor.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {promisify} = require("util");
55
const readFile = promisify(fs.readFile);
66
const jsyaml = require("js-yaml");
77
const typeRepository = require("@ui5/builder").types.typeRepository;
8+
const ZipArchive = require("@ui5/fs").adapters.ZipArchive;
89
const {validate} = require("./validation/validator");
910

1011
class ProjectPreprocessor {
@@ -391,15 +392,32 @@ class ProjectPreprocessor {
391392
try {
392393
configFile = await readFile(configPath, {encoding: "utf8"});
393394
} catch (err) {
394-
const errorText = "Failed to read configuration for project " +
395-
`${project.id} at "${configPath}". Error: ${err.message}`;
396-
397-
// Something else than "File or directory does not exist" or root project
398-
if (err.code !== "ENOENT" || project._isRoot) {
399-
throw new Error(errorText);
395+
if (project.path.endsWith(".zip")) {
396+
try {
397+
project._zipAdapter = new ZipArchive({
398+
virBasePath: "/",
399+
fsArchive: project.path
400+
});
401+
const resource = await project._zipAdapter.byPath("/ui5.yaml");
402+
if (!resource) {
403+
throw new Error(`File not found in ZIP archive: /ui5.yaml`);
404+
}
405+
configFile = await resource.getBuffer();
406+
} catch (err) {
407+
throw new Error(`Error file reading from ZIP file at ${configPath} for project ` +
408+
`${project.id}: ${err.message}\n${err.stack}`);
409+
}
400410
} else {
401-
log.verbose(errorText);
402-
return null;
411+
const errorText = "Failed to read configuration for project " +
412+
`${project.id} at "${configPath}". Error: ${err.message}`;
413+
414+
// Something else than "File or directory does not exist" or root project
415+
if (err.code !== "ENOENT" || project._isRoot) {
416+
throw new Error(errorText);
417+
} else {
418+
log.verbose(errorText);
419+
return null;
420+
}
403421
}
404422
}
405423

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
},
9999
"dependencies": {
100100
"@ui5/builder": "^2.2.0",
101+
"@ui5/fs": "^2.0.3",
101102
"@ui5/logger": "^2.0.0",
102103
"@ui5/server": "^2.2.4",
103104
"ajv": "^6.12.5",

0 commit comments

Comments
 (0)