-
Notifications
You must be signed in to change notification settings - Fork 64
Add Codama CLI #425
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
Add Codama CLI #425
Conversation
🦋 Changeset detectedLatest commit: dcf0aa2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
2ec7616 to
1159ce7
Compare
1159ce7 to
bce00d1
Compare
3b77810 to
14a98bb
Compare
febo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great – just found a tiny typo.
14a98bb to
3e80075
Compare
73e21de to
9d6b686
Compare
3e80075 to
dcf0aa2
Compare

This PR adds a brand new
@codama/clipackage which is then imported (not re-exported) by the maincodamalibrary in order to use thecodamakeyword as CLI binary.The CLI currently supports the following two commands:
codama init: which initialises a Codama configuration file by using prompts and selected script presets.codama run: which runs any script defined in your configuration file.You can learn more about the CLI commands and the Codama config file from the
@codama/cliREADME copy/pasted below:This package provides a CLI for the Codama library that can be used to run scripts on Codama IDLs.
Note that, whilst the CLI code is located in the
@codama/clipackage, the CLI binary is directly provided by the maincodamalibrary.Getting started
To get started with Codama, simply install
codamato your project and run theinitcommand like so:You will be prompted for the path of your IDL and asked to select any script presets you would like to use.
codama runOnce you have your codama config file, you can run your Codama scripts using the
codama runcommand as follows:The configuration file
The codama config file defines an object containing the following fields:
idl(string): The path to the IDL file. This can be a Codama IDL or an Anchor IDL which will be automatically converted to a Codama IDL.before(array): An array of visitors that will run before every script.scripts(object): An object defining the available Codama scripts. The keys identify the scripts and the values are arrays of visitors that make up the script.Whether it is in the
beforearray or in thescriptsvalues, when defining a visitor you may either provide:from(string): The import path to the visitor.args(array): An array of arguments to pass to the visitor.fromfield and an emptyargsarray.Visitor import paths can either be local paths (pointing to JavaScript files exporting visitors) or npm package names. By default, the
defaultexport will be used but you may specify a nammed export by appending a#followed by the export name. When resolved, the imported element inside the module should either be aVisitor<any, 'rootNode'>or a function that returns aVisitor<any, 'rootNode'>given the arguments provided. Here are some examples of valid visitor import paths:Here is an example of what a Codama configuration file might look like:
{ "idl": "path/to/idl", "before": [ "./my-before-visitor.js", { "from": "some-library#removeTypes", "args": [["internalFoo", "internalBar"]] } ], "scripts": { "js": [ { "from": "@codama/renderers-js", "args": ["clients/js/src/generated"] } ] } }Note that you can use the
--jsflag to generate a.jsconfiguration file when running theinitcommand.