Skip to content

[PoC] ZipArchive Adapter #525

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

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
113 changes: 71 additions & 42 deletions lib/types/library/LibraryFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class LibraryFormatter extends AbstractUi5Formatter {
namespace = libraryNs.replace(/\./g, "/");

const namespacePath = this.getNamespaceFromFsPath(fsNamespacePath);
if (namespacePath !== namespace) {
if (false && namespacePath !== namespace) {
throw new Error(
`Detected namespace "${namespace}" does not match detected directory ` +
`structure "${namespacePath}" for project ${this._project.metadata.name}`);
Expand Down Expand Up @@ -337,32 +337,61 @@ class LibraryFormatter extends AbstractUi5Formatter {
if (this._pDotLibrary) {
return this._pDotLibrary;
}
const basePath = this.getSourceBasePath();
return this._pDotLibrary = glob("**/.library", {
cwd: basePath,
followSymbolicLinks: false
}).then(async (dotLibraryResources) => {
if (!dotLibraryResources.length) {
throw new Error(`Could not find .library file for project ${this._project.metadata.name}`);
}
if (dotLibraryResources.length > 1) {
throw new Error(`Found multiple (${dotLibraryResources.length}) .library files ` +
`for project ${this._project.metadata.name}`);
}
const fsPath = path.join(basePath, dotLibraryResources[0]);
const content = await readFile(fsPath);
const xml2js = require("xml2js");
const parser = new xml2js.Parser({
explicitArray: false,
ignoreAttrs: true
if (this._project._zipAdapter) {
const basePath = this.getSourceBasePath();
console.log("/" + this._project.resources.pathMappings["/resources/"] + "/**/.library");
return this._pDotLibrary = this._project._zipAdapter.byGlob(
"/" + this._project.resources.pathMappings["/resources/"] + "/**/.library")
.then(async (dotLibraryResources) => {
if (!dotLibraryResources.length) {
throw new Error(`Could not find .library file for project ${this._project.metadata.name}`);
}
if (dotLibraryResources.length > 1) {
throw new Error(`Found multiple (${dotLibraryResources.length}) .library files ` +
`for project ${this._project.metadata.name}`);
}
const fsPath = path.join(basePath, dotLibraryResources[0].getPath());
const content = await dotLibraryResources[0].getBuffer();
const xml2js = require("xml2js");
const parser = new xml2js.Parser({
explicitArray: false,
ignoreAttrs: true
});
const readXML = promisify(parser.parseString);
const contentJson = await readXML(content);
return {
content: contentJson,
fsPath
};
});
} else {
const basePath = this.getSourceBasePath();
return this._pDotLibrary = glob("**/.library", {
cwd: basePath,
followSymbolicLinks: false
}).then(async (dotLibraryResources) => {
if (!dotLibraryResources.length) {
throw new Error(`Could not find .library file for project ${this._project.metadata.name}`);
}
if (dotLibraryResources.length > 1) {
throw new Error(`Found multiple (${dotLibraryResources.length}) .library files ` +
`for project ${this._project.metadata.name}`);
}
const fsPath = path.join(basePath, dotLibraryResources[0]);
const content = await readFile(fsPath);
const xml2js = require("xml2js");
const parser = new xml2js.Parser({
explicitArray: false,
ignoreAttrs: true
});
const readXML = promisify(parser.parseString);
const contentJson = await readXML(content);
return {
content: contentJson,
fsPath
};
});
const readXML = promisify(parser.parseString);
const contentJson = await readXML(content);
return {
content: contentJson,
fsPath
};
});
}
}

/**
Expand Down Expand Up @@ -445,22 +474,22 @@ class LibraryFormatter extends AbstractUi5Formatter {

const absoluteSrcPath = path.join(project.path, project.resources.configuration.paths.src);
const absoluteTestPath = path.join(project.path, project.resources.configuration.paths.test);
return Promise.all([
this.dirExists(absoluteSrcPath).then(function(bExists) {
if (!bExists) {
throw new Error(`Could not find source directory of project ${project.id}: ` +
`${absoluteSrcPath}`);
}
}),
this.dirExists(absoluteTestPath).then(function(bExists) {
if (!bExists) {
log.verbose(`Could not find (optional) test directory of project ${project.id}: ` +
`${absoluteTestPath}`);
// Current signal to following consumers that "test" is not available is null
project.resources.configuration.paths.test = null;
}
})
]);
// return Promise.all([
// this.dirExists(absoluteSrcPath).then(function(bExists) {
// if (!bExists) {
// throw new Error(`Could not find source directory of project ${project.id}: ` +
// `${absoluteSrcPath}`);
// }
// }),
// this.dirExists(absoluteTestPath).then(function(bExists) {
// if (!bExists) {
// log.verbose(`Could not find (optional) test directory of project ${project.id}: ` +
// `${absoluteTestPath}`);
// // Current signal to following consumers that "test" is not available is null
// project.resources.configuration.paths.test = null;
// }
// })
// ]);
});
}
}
Expand Down
32 changes: 16 additions & 16 deletions lib/types/themeLibrary/ThemeLibraryFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ class ThemeLibraryFormatter extends AbstractUi5Formatter {

const absoluteSrcPath = path.join(project.path, project.resources.configuration.paths.src);
const absoluteTestPath = path.join(project.path, project.resources.configuration.paths.test);
return Promise.all([
this.dirExists(absoluteSrcPath).then(function(bExists) {
if (!bExists) {
throw new Error(`Could not find source directory of project ${project.id}: ` +
`${absoluteSrcPath}`);
}
}),
this.dirExists(absoluteTestPath).then(function(bExists) {
if (!bExists) {
log.verbose(`Could not find (optional) test directory of project ${project.id}: ` +
`${absoluteTestPath}`);
// Current signal to following consumers that "test" is not available is null
project.resources.configuration.paths.test = null;
}
})
]);
// return Promise.all([
// this.dirExists(absoluteSrcPath).then(function(bExists) {
// if (!bExists) {
// throw new Error(`Could not find source directory of project ${project.id}: ` +
// `${absoluteSrcPath}`);
// }
// }),
// this.dirExists(absoluteTestPath).then(function(bExists) {
// if (!bExists) {
// log.verbose(`Could not find (optional) test directory of project ${project.id}: ` +
// `${absoluteTestPath}`);
// // Current signal to following consumers that "test" is not available is null
// project.resources.configuration.paths.test = null;
// }
// })
// ]);
});
}
}
Expand Down