-
Notifications
You must be signed in to change notification settings - Fork 1
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
#86c0b8vp3: Impement Sentry generator using ast #50
base: main
Are you sure you want to change the base?
Conversation
@dmitryusenko review please! FYI @ipakhomov |
"withSentry": { | ||
"type": "boolean", | ||
"default": false, | ||
"x-prompt": "Do you want to use sentry in your app?" |
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.
"x-prompt": "Do you want to use sentry in your app?" | |
"x-prompt": "Do you want to use Sentry in your app?" |
"withSentry": { | ||
"type": "boolean", | ||
"default": false, | ||
"x-prompt": "Do you want to use sentry in your app?" |
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.
"x-prompt": "Do you want to use sentry in your app?" | |
"x-prompt": "Do you want to use Sentry in your app?" |
import * as Sentry from '@sentry/nextjs'; | ||
|
||
Sentry.init({ | ||
dsn: '<%= DSN %>', |
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.
dsn: '<%= DSN %>', | |
dsn: '<%= dsn %>', |
import * as Sentry from '@sentry/nextjs'; | ||
|
||
Sentry.init({ | ||
dsn: '<%= DSN %>', |
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.
dsn: '<%= DSN %>', | |
dsn: '<%= dsn %>', |
import * as Sentry from '@sentry/nextjs'; | ||
|
||
Sentry.init({ | ||
dsn: '<%= DSN %>', |
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.
dsn: '<%= DSN %>', | |
dsn: '<%= dsn %>', |
export interface SentryGeneratorSchema { | ||
name: string; | ||
directory: string; | ||
DSN: string; |
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.
DSN: string; | |
dsn: string; |
}, | ||
"x-prompt": "Enter the name of the directory in the 'apps/' folder (e.g: web)" | ||
}, | ||
"DSN": { |
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.
"DSN": { | |
"dsn": { |
}, | ||
); | ||
|
||
const updateExtraConfig = (content: string, DSN: string): string => |
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.
const updateExtraConfig = (content: string, DSN: string): string => | |
const updateExtraConfig = (content: string, dsn: string): string => |
initializer: factory.createObjectLiteralExpression([ | ||
factory.createPropertyAssignment( | ||
'dsn', | ||
factory.createStringLiteral(DSN), |
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.
factory.createStringLiteral(DSN), | |
factory.createStringLiteral(dsn), |
|
||
const updatedAppConfigContent = updateExtraConfig( | ||
addSentryPluginToAppConfig(appConfigContent), | ||
options.DSN, |
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.
options.DSN, | |
options.dsn, |
const nextConfigContent = tree | ||
.read(`${projectRoot}/next.config.js`) | ||
.toString(); | ||
|
||
const updatedNextConfigContent = wrapIntoSentryConfig( | ||
modifyNextConfig(addRequiredImports(nextConfigContent)), | ||
); | ||
|
||
tree.write(`${projectRoot}/next.config.js`, updatedNextConfigContent); |
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.
We could implement some utility function to shorten the code that performs such file updates. Very rough idea:
// UTILITY DEFINITION
function updateFile(tree, filePath, updater) {
// 1. Call tree.read to get file contents
// 2. Call updater over the file contents
// 3. Call tree.write to write the updated file contents
}
// USAGE
updateFile(
tree,
`${projectRoot}/next.config.js`,
(content) => wrapIntoSentryConfig(modifyNextConfig(addRequiredImports(content)))
);
This way we eliminate some code duplication, and also get rid of unnecessary variable declarations.
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.
@RuslanAktaev Looks good to me overall! I've provided the feedback above. Could you please address it?
No description provided.