Skip to content

Commit

Permalink
[PoC] ZipArchive Adapter: Hack it till you make it
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Sep 30, 2020
1 parent 2f6d847 commit c0b0c37
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
34 changes: 26 additions & 8 deletions lib/projectPreprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c0b0c37

Please sign in to comment.