ui5-tooling
ui5-tooling copied to clipboard
Access package.json in custom task
Expected Behavior
It would be nice to be able to access the projects package.json within a custom task (e.g. for getting the version or the like).
Current Behavior
The only hacky way I've found was by using workspace._reader._readers[0]._project
.
Affected components (if known)
- [X] ui5-builder
- [ ] ui5-server
- [ ] ui5-cli
- [ ] ui5-fs
- [ ] ui5-project
- [ ] ui5-logger
Hey, we already have the general requirement to read (and write) files from a projects root directory.
Therefore we are wondering whether you are only interested in the projects version or also need other information from the package.json. In case you just need the version, we could also think of enhancing the custom task API to also pass in the project version.
I was only interested in the version (passing in the whole package.json wouldn't hurt though IMO).
Ok! We'll discuss this and may add the version information as an additional parameter to the custom task interface 👍
passing in the whole package.json wouldn't hurt though IMO
The problem is that we don't want to force projects to use npm or even have a package.json. Our "translator" concept allows the use of other dependency management tools, so we can't really rely on a package.json.
The problem is that we don't want to force projects to use npm or even have a package.json. Our "translator" concept allows the use of other dependency management tools, so we can't really rely on a package.json.
Ah ok, wasn't aware of this (didn't dig deep enough into the tooling so far).
This is how I currently set the version/commit hash during build process (once this is done, this certainly can be improved):
module.exports = async function ({ workspace }) {
const [view] = await workspace.byGlob('**/SomeView.view.xml');
// it's a beauty!
const version = workspace._reader._readers[0]._project.version;
let commit = '';
try {
commit = ` (${require('child_process').execSync('git rev-parse --short HEAD').toString().trim()})`;
} catch (e) {
// fail silently
}
await view.setString((await view.getString()).replace('${version}', `${version}${commit}`));
return workspace.write(view);
};