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

#86c0b8vp3: Impement Sentry generator using ast #50

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

RuslanAktaev
Copy link

No description provided.

@RuslanAktaev RuslanAktaev changed the title 86c0b8vp3 sentry generator with ast #86c0b8vp3: Impement Sentry generator using ast Oct 31, 2024
@RuslanAktaev
Copy link
Author

@dmitryusenko review please!

FYI @ipakhomov

"withSentry": {
"type": "boolean",
"default": false,
"x-prompt": "Do you want to use sentry in your app?"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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?"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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 %>',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dsn: '<%= DSN %>',
dsn: '<%= dsn %>',

import * as Sentry from '@sentry/nextjs';

Sentry.init({
dsn: '<%= DSN %>',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dsn: '<%= DSN %>',
dsn: '<%= dsn %>',

import * as Sentry from '@sentry/nextjs';

Sentry.init({
dsn: '<%= DSN %>',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dsn: '<%= DSN %>',
dsn: '<%= dsn %>',

export interface SentryGeneratorSchema {
name: string;
directory: string;
DSN: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DSN: string;
dsn: string;

},
"x-prompt": "Enter the name of the directory in the 'apps/' folder (e.g: web)"
},
"DSN": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"DSN": {
"dsn": {

},
);

const updateExtraConfig = (content: string, DSN: string): string =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const updateExtraConfig = (content: string, DSN: string): string =>
const updateExtraConfig = (content: string, dsn: string): string =>

initializer: factory.createObjectLiteralExpression([
factory.createPropertyAssignment(
'dsn',
factory.createStringLiteral(DSN),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
factory.createStringLiteral(DSN),
factory.createStringLiteral(dsn),


const updatedAppConfigContent = updateExtraConfig(
addSentryPluginToAppConfig(appConfigContent),
options.DSN,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
options.DSN,
options.dsn,

Comment on lines +109 to +117
const nextConfigContent = tree
.read(`${projectRoot}/next.config.js`)
.toString();

const updatedNextConfigContent = wrapIntoSentryConfig(
modifyNextConfig(addRequiredImports(nextConfigContent)),
);

tree.write(`${projectRoot}/next.config.js`, updatedNextConfigContent);
Copy link
Contributor

@dmitryusenko dmitryusenko Nov 1, 2024

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.

Copy link
Contributor

@dmitryusenko dmitryusenko left a 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants