Skip to content
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 output-type flag to cli of ccd-js-gen tool #322

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/ccd-js-gen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Add output-type flag to cli.
- Fix the executable version of the package on Windows.

## 1.0.1
Expand Down
2 changes: 1 addition & 1 deletion packages/ccd-js-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"build-dev": "yarn build",
"clean": "rm -r lib",
"lint": "eslint src/** bin/** --cache --ext .ts,.js --max-warnings 0",
"lint-fix": "yarn --silent lint --fix; exit 0",
"lint-fix": "yarn lint --fix; exit 0",
DOBEN marked this conversation as resolved.
Show resolved Hide resolved
"test": "jest",
"test-ci": "yarn test"
},
Expand Down
23 changes: 23 additions & 0 deletions packages/ccd-js-gen/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type Options = {
module: string;
/** The output directory for the generated code */
outDir: string;
/** The output file types for the generated code */
outputType: lib.OutputOptions;
};

// Main function, which is called in the executable script in `bin`.
Expand All @@ -28,12 +30,33 @@ export async function main(): Promise<void> {
'-o, --out-dir <directory>',
'The output directory for the generated code'
)
.option<lib.OutputOptions>(
'-t, --output-type <TypeScript|JavaScript|TypedJavaScript|Everything>',
'The output file types for the generated code.',
(value: string) => {
switch (value) {
case 'TypeScript':
case 'JavaScript':
case 'TypedJavaScript':
case 'Everything':
return value;
default:
// Exit in case `value` is not a valid OutputOptions.
console.error(
`Invalid '--output-type' flag: ${value}. Use 'TypeScript', 'JavaScript', 'TypedJavaScript', or 'Everything'.`
);
process.exit(1);
}
},
'Everything'
)
.parse(process.argv);
const options = program.opts<Options>();
console.log('Generating smart contract clients...');

const startTime = Date.now();
await lib.generateContractClientsFromFile(options.module, options.outDir, {
output: options.outputType,
onProgress(update) {
if (update.type === 'Progress') {
console.log(
Expand Down