Skip to content

Commit

Permalink
[PoC] ZipArchive Adapter: Either skip validations or use adapter prov…
Browse files Browse the repository at this point in the history
…ided by projectPreprocessor to access project resources
  • Loading branch information
RandomByte committed Oct 1, 2020
1 parent d3614d2 commit 0aab3e3
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 58 deletions.
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

0 comments on commit 0aab3e3

Please sign in to comment.