Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PoC] ZipArchive Adapter #362

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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