Description
Is your feature request related to a problem? Please describe the problem.
I am trying to use kiota in a standard TypeSpec npm-based project at the command line. I'm not using TTK. This is just an example of usage - any number of use cases exist for typical NPM package behavior.
I expect to be able to do the following as a canonical example:
npx @microsoft/kiota --version
Client library/SDK language
None
Describe the solution you'd like
To do this effectively with minimal code we need to use standard NPM techniques.
- Remove the platform-specific subfolder from the download. E.g. switch from
@microsoft\kiota\dist\cjs\.kiotabin\1.25.1\win-x64
to
@microsoft\kiota\dist\cjs\.kiotabin\1.25.1
As we will only have one architecture on a given machine this is fine.
It provides a stable cross-platform path that can be referenced from the bin
node in package.json
By using the bin
node like so
"bin": {
"kiota": "./dist\cjs\.kiotabin\1.25.1\kiota"
}
NPM will then automatically create links to the named bin in the node_modules/.bin folder.
in order to trigger all of this, an install script is needed running from the postinstall trigger:
Trigger:
"scripts": {
"postinstall": "node scripts/install.js"
Script: `scripts\install.js'
// Import the ensureKiotaIsPresent function
const { ensureKiotaIsPresent } = require('./dist/cjs/install.js');
// Call the function and handle the promise
(async () => {
try {
const result = await ensureKiotaIsPresent();
if (result) {
console.log(`Kiota successfully ensured: ${result}`);
} else {
console.log("Kiota is already present.");
}
} catch (error) {
console.error("Error during Kiota installation:", error);
process.exit(1); // Exit with an error code if something goes wrong
}
})();
Additional context
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status