Skip to content

Commit

Permalink
fix(deps): update dependency chalk to v5 (#2135)
Browse files Browse the repository at this point in the history
* fix(deps): update dependency chalk to v5

* feat(package/cli): graceful user exit

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Vicary A <[email protected]>
  • Loading branch information
renovate[bot] and vicary authored Feb 10, 2025
1 parent f59c607 commit c18a3da
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-roses-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@gqty/cli': patch
---

graceful user exit
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@graphql-tools/utils": "^10.8.0",
"@graphql-tools/wrap": "^10.0.29",
"@inquirer/prompts": "^7.3.1",
"chalk": "^4.1.2",
"chalk": "^5.4.1",
"commander": "^13.1.0",
"cosmiconfig": "^9.0.0",
"cross-fetch": "^4.1.0",
Expand Down
59 changes: 39 additions & 20 deletions packages/cli/src/commands/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,12 @@ export const addCommand = (command: Command) => {
};

const promptEndpoints = async (defaultEndpoint?: string) => {
const endpoints = await inquirer.input({
message: 'Where is your GraphQL endpoint or schema files?',
default: defaultEndpoint,
});
const endpoints = await inquirer
.input({
message: 'Where is your GraphQL endpoint or schema files?',
default: defaultEndpoint,
})
.catch(terminateOnInterrupt);

return endpoints
.split(/[,\s+]/)
Expand All @@ -353,41 +355,58 @@ const promptEndpoints = async (defaultEndpoint?: string) => {
};

const promptTarget = async (defaultTarget: string) => {
const target = await inquirer.input({
message: 'Where should the client be generated?',
default: defaultTarget,
});
const target = await inquirer
.input({
message: 'Where should the client be generated?',
default: defaultTarget,
})
.catch(terminateOnInterrupt);

return target;
};

const promptFrameworks = async () => {
const frameworks = await inquirer.checkbox({
message: `Pick the frontend frameworks in use:`,
choices: [{ value: 'react' }, { value: 'solid-js' }],
});
const frameworks = await inquirer
.checkbox({
message: `Pick the frontend frameworks in use:`,
choices: [{ value: 'react' }, { value: 'solid-js' }],
})
.catch(terminateOnInterrupt);

return frameworks as SupportedFrameworks[];
};

const promptSubscriptions = async (defaultValue?: string) => {
const subscriptions = await inquirer.input({
message: 'Do you need a subscription client? (Enter "-" to skip)',
default: defaultValue?.trim() || undefined,
});
const subscriptions = await inquirer
.input({
message: 'Do you need a subscription client? (Enter "-" to skip)',
default: defaultValue?.trim() || undefined,
})
.catch(terminateOnInterrupt);

return subscriptions?.trim().replace(/^-$/, '') || false;
};

const promptTypescript = async (defaultValue: boolean) => {
const typescript = await inquirer.confirm({
message: 'Do you want a TypeScript client over vanilla.js?',
default: defaultValue,
});
const typescript = await inquirer
.confirm({
message: 'Do you want a TypeScript client over vanilla.js?',
default: defaultValue,
})
.catch(terminateOnInterrupt);

return typescript;
};

const terminateOnInterrupt = (e: unknown) => {
if (e instanceof Error && e.name === 'ExitPromptError') {
logger.info('Goodbye 👋');
process.exit();
}

throw e;
};

const terminateWithError = (e: unknown) => {
if (e instanceof Error) {
logger.error(e.message);
Expand Down
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c18a3da

Please sign in to comment.