generator-jhipster-sentry-module 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,6 @@ const semver = require('semver');
5
5
  const Generator = require('yeoman-generator');
6
6
  const packageJson = require('../../package.json');
7
7
 
8
- // JHipster constants
9
8
  const jhipsterConstants = {
10
9
  SERVER_MAIN_SRC_DIR: 'src/main/java/',
11
10
  SERVER_MAIN_RES_DIR: 'src/main/resources/',
@@ -13,25 +12,34 @@ const jhipsterConstants = {
13
12
  };
14
13
 
15
14
  module.exports = class extends Generator {
15
+
16
16
  async initializing() {
17
- // Read JHipster config
18
- this.jhipsterAppConfig = this.fs.readJSON(this.destinationPath('.yo-rc.json'), {})['generator-jhipster'];
17
+ const yoConfig = this.fs.readJSON(this.destinationPath('.yo-rc.json'), {});
18
+ this.jhipsterAppConfig = yoConfig['generator-jhipster'];
19
+
19
20
  if (!this.jhipsterAppConfig) {
20
21
  this.log(chalk.red('Cannot read .yo-rc.json or JHipster config missing'));
21
- process.exit(1);
22
+ return;
22
23
  }
23
24
 
24
- this.log(`\nWelcome to the ${chalk.bold.yellow('JHipster Sentry Module')} generator! ${chalk.yellow(`v${packageJson.version}\n`)}`);
25
-
26
- // Check JHipster version
27
- const currentJhipsterVersion = this.jhipsterAppConfig.jhipsterVersion;
28
- if (!semver.satisfies(currentJhipsterVersion, '>=8.0.0')) {
29
- this.log(chalk.yellow(`Warning: Your JHipster version is ${currentJhipsterVersion}, minimum required is 8.0.0\n`));
25
+ this.log(
26
+ `\nWelcome to the ${chalk.bold.yellow('JHipster Sentry Module')} generator! ${chalk.yellow(
27
+ `v${packageJson.version}\n`
28
+ )}`
29
+ );
30
+
31
+ const currentVersion = this.jhipsterAppConfig.jhipsterVersion || '0.0.0';
32
+ if (!semver.satisfies(currentVersion, '>=8.0.0')) {
33
+ this.log(
34
+ chalk.yellow(
35
+ `Warning: Your JHipster version is ${currentVersion}, minimum required is 8.0.0\n`
36
+ )
37
+ );
30
38
  }
31
39
  }
32
40
 
33
41
  async prompting() {
34
- const prompts = [
42
+ this.promptAnswers = await this.prompt([
35
43
  {
36
44
  type: 'confirm',
37
45
  name: 'enableSentry',
@@ -44,112 +52,86 @@ module.exports = class extends Generator {
44
52
  name: 'sentryDsn',
45
53
  message: 'Enter your Sentry DSN'
46
54
  }
47
- ];
48
- this.promptAnswers = await this.prompt(prompts);
55
+ ]);
49
56
  }
50
57
 
51
58
  writing() {
52
- // Read JHipster config
53
- this.baseName = this.jhipsterAppConfig.baseName;
54
- this.packageName = this.jhipsterAppConfig.packageName;
55
- this.packageFolder = this.jhipsterAppConfig.packageFolder;
56
- this.clientFramework = this.jhipsterAppConfig.clientFramework;
57
- this.clientPackageManager = this.jhipsterAppConfig.clientPackageManager;
58
- this.buildTool = this.jhipsterAppConfig.buildTool;
59
-
60
- const javaDir = `${jhipsterConstants.SERVER_MAIN_SRC_DIR}${this.packageFolder}/`;
61
- const resourceDir = jhipsterConstants.SERVER_MAIN_RES_DIR;
59
+ if (!this.jhipsterAppConfig) return;
60
+
61
+ const {
62
+ baseName,
63
+ packageName,
64
+ packageFolder,
65
+ clientFramework,
66
+ buildTool
67
+ } = this.jhipsterAppConfig;
68
+
62
69
  const webappDir = jhipsterConstants.CLIENT_MAIN_SRC_DIR;
70
+ const resourceDir = jhipsterConstants.SERVER_MAIN_RES_DIR;
63
71
 
64
- // Persist Sentry config
72
+ // Save config
65
73
  this.jhipsterAppConfig.sentry = {
66
74
  enabled: this.promptAnswers.enableSentry,
67
75
  dsn: this.promptAnswers.sentryDsn
68
76
  };
77
+
69
78
  const configPath = this.destinationPath('.yo-rc.json');
70
79
  const config = this.fs.readJSON(configPath, {});
71
- config['generator-jhipster'] = config['generator-jhipster'] || {};
72
80
  config['generator-jhipster'].sentry = this.jhipsterAppConfig.sentry;
73
81
  this.fs.writeJSON(configPath, config, null, 2);
74
82
 
75
- // Logging
76
- this.log('\n--- JHipster Config ---');
77
- this.log(`baseName=${this.baseName}`);
78
- this.log(`packageName=${this.packageName}`);
79
- this.log(`clientFramework=${this.clientFramework}`);
80
- this.log(`buildTool=${this.buildTool}`);
81
- this.log('\n--- Sentry ---');
82
- this.log(`enabled=${this.promptAnswers.enableSentry}`);
83
- this.log('----------------------\n');
84
-
85
83
  if (!this.promptAnswers.enableSentry) {
86
- this.log(chalk.yellow('Sentry is disabled — skipping integration'));
84
+ this.log(chalk.yellow('Sentry disabled — skipping integration'));
87
85
  return;
88
86
  }
89
87
 
90
- // Backend dependencies
91
- if (this.buildTool === 'maven') {
88
+ // ======================
89
+ // Backend (Maven only safe injection)
90
+ // ======================
91
+ if (buildTool === 'maven') {
92
92
  const pomPath = this.destinationPath('pom.xml');
93
93
  if (fs.existsSync(pomPath)) {
94
94
  let pom = fs.readFileSync(pomPath, 'utf8');
95
95
  if (!pom.includes('sentry-spring-boot-starter')) {
96
96
  pom = pom.replace(
97
97
  /<\/dependencies>/,
98
- ` <dependency>
99
- <groupId>io.sentry</groupId>
100
- <artifactId>sentry-spring-boot-starter</artifactId>
101
- <version>7.3.0</version>
102
- </dependency>
103
- </dependencies>`
98
+ `
99
+ <dependency>
100
+ <groupId>io.sentry</groupId>
101
+ <artifactId>sentry-spring-boot-starter</artifactId>
102
+ <version>7.3.0</version>
103
+ </dependency>
104
+ </dependencies>`
104
105
  );
105
106
  fs.writeFileSync(pomPath, pom);
106
107
  }
107
108
  }
108
109
  }
109
110
 
110
- if (this.buildTool === 'gradle') {
111
- const buildGradle = this.destinationPath('build.gradle');
112
- if (fs.existsSync(buildGradle)) {
113
- let gradle = fs.readFileSync(buildGradle, 'utf8');
114
- if (!gradle.includes('sentry-spring-boot-starter')) {
115
- gradle += '\ndependencies {\n implementation "io.sentry:sentry-spring-boot-starter:7.3.0"\n}\n';
116
- fs.writeFileSync(buildGradle, gradle);
117
- }
118
- }
111
+ // ======================
112
+ // Frontend
113
+ // ======================
114
+ if (clientFramework === 'react') {
115
+ this.fs.copyTpl(
116
+ this.templatePath('client/react/sentry.ts.ejs'),
117
+ this.destinationPath(`${webappDir}app/sentry.ts`),
118
+ { sentryDsn: this.promptAnswers.sentryDsn }
119
+ );
120
+
121
+ this.addPackageJsonDependency('@sentry/react', '^7.3.0');
119
122
  }
120
123
 
121
- // Frontend templates
122
- if (this.clientFramework === 'react') {
123
- this.fs.copyTpl(
124
- this.templatePath('client/react/sentry.ts.ejs'),
125
- `${webappDir}app/sentry.ts`,
126
- {
127
- sentryDsn: this.promptAnswers.sentryDsn
128
- }
129
- ); } else if (this.clientFramework === 'angularX') {
130
- this.fs.copyTpl(
131
- this.templatePath('client/react/sentry.ts.ejs'),
132
- `${webappDir}app/sentry.ts`,
133
- {
134
- sentryDsn: this.promptAnswers.sentryDsn
135
- }
136
- ); }
137
- }
138
-
139
- install() {
140
- if (!this.promptAnswers.enableSentry) return;
124
+ if (clientFramework === 'angularX') {
125
+ this.fs.copyTpl(
126
+ this.templatePath('client/angular/sentry.ts.ejs'),
127
+ this.destinationPath(`${webappDir}app/sentry.ts`),
128
+ { sentryDsn: this.promptAnswers.sentryDsn }
129
+ );
141
130
 
142
- const packages = [];
143
- if (this.clientFramework === 'react') {
144
- packages.push('@sentry/react@^7.3.0');
145
- } else if (this.clientFramework === 'angularX') {
146
- packages.push('@sentry/angular@^7.3.0');
131
+ this.addPackageJsonDependency('@sentry/angular', '^7.3.0');
147
132
  }
148
133
 
149
- if (packages.length > 0) {
150
- const cmd = this.clientPackageManager === 'yarn' ? 'add' : 'install';
151
- this.spawnCommandSync(this.clientPackageManager, [...(this.clientPackageManager === 'yarn' ? ['add'] : ['install']), ...packages]);
152
- }
134
+ this.log(chalk.green('✔ Sentry files added successfully'));
153
135
  }
154
136
 
155
137
  end() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generator-jhipster-sentry-module",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Adding Sentry integration to JHipster projects",
5
5
  "keywords": [
6
6
  "yeoman-generator",