-
Notifications
You must be signed in to change notification settings - Fork 6
feat(cli): provide executable script for the package #52
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
feat(cli): provide executable script for the package #52
Conversation
I like the idea. @asopian would that benefit from being written in TypeScript ? |
@springcomp Thanks. Not sure if Typescript would be beneficial, but don't mind either way. This PR was just following the established pattern and enhance the existing script. Feel free to let me know if prefer Typescript and I can update the script. |
@asopian well I like the type safety that TypeScript brings, even though it might not provide a lot of value for a single script. Speaking of which, I have tried to propose a simple conversion to TypeScript as a pull request to your contribution and I uncovered a bug 🙈. function printResult(inputJSON: string, expression: string, compact: boolean = false) {
try {
var parsedInput = JSON.parse(inputJSON);
- console.log(JSON.stringify(jmespath.search(parsedInput, expression, null, compact), null, compact ? 0 : 2));
+ console.log(JSON.stringify(jmespath.search(parsedInput, expression, null), null, compact ? 0 : 2));
} catch (e) {
console.error('Error parsing JSON input:', e.message);
process.exit(1);
}
} Please, let me know what you think. |
Changed to TypeScript
@springcomp Indeed it is good to have type-safety. Your proposed change/fix is looking good to me and have merged it. The build config and package.json will need updating, due to the use of Typescript on scripts directory. I will update it through a new commit later this week. |
@springcomp Updated the package.json with the new binary path. Also improved the script error message, so that can differentiate if the error is coming from the JSON input or from the JMESPath expression. For your review. |
@asopian That looks all right to me. I have submitted more contributions as another pull request to enforce lint rules and format according to the project configuration. I also have moved the Thanks for your contributions. |
Addressed lint warnings
@springcomp Thank you for more contribution. Also thanks for pointing out about formatting/linting. Learn something new about Biome :) |
@cawalch that looks good to me. |
Make the package to be executable from the CLI.
And allows transforming input from stdin or from a file (option -f).
Also allows jmespath expression to be given as param or from file (option -e).
Example:
Assuming jp_input.json :
And jp_query :
Later on this can be scripted or used with nodemon for continuous exploratory working with JSON transformation.
For example: