generator-jhipster-sentry-module 1.0.8 → 1.0.10

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,8 @@ const semver = require('semver');
5
5
  const Generator = require('yeoman-generator');
6
6
  const packageJson = require('../../package.json');
7
7
 
8
- // JHipster constants
8
+ const JHIPSTER_CONFIG_KEY = 'generator-jhipster';
9
+
9
10
  const jhipsterConstants = {
10
11
  SERVER_MAIN_SRC_DIR: 'src/main/java/',
11
12
  SERVER_MAIN_RES_DIR: 'src/main/resources/',
@@ -13,25 +14,42 @@ const jhipsterConstants = {
13
14
  };
14
15
 
15
16
  module.exports = class extends Generator {
17
+
16
18
  async initializing() {
17
- // Read JHipster config
18
- this.jhipsterAppConfig = this.fs.readJSON(this.destinationPath('.yo-rc.json'), {})['generator-jhipster'];
19
+ const yoRcPath = this.destinationPath('.yo-rc.json');
20
+
21
+ if (!fs.existsSync(yoRcPath)) {
22
+ this.log(chalk.red('❌ Not a JHipster project (.yo-rc.json not found)'));
23
+ process.exit(1);
24
+ }
25
+
26
+ const yoRc = this.fs.readJSON(yoRcPath, {});
27
+ this.jhipsterAppConfig = yoRc[JHIPSTER_CONFIG_KEY];
28
+
19
29
  if (!this.jhipsterAppConfig) {
20
- this.log(chalk.red('Cannot read .yo-rc.json or JHipster config missing'));
30
+ this.log(chalk.red(' JHipster configuration missing inside .yo-rc.json'));
21
31
  process.exit(1);
22
32
  }
23
33
 
24
- this.log(`\nWelcome to the ${chalk.bold.yellow('JHipster Sentry Module')} generator! ${chalk.yellow(`v${packageJson.version}\n`)}`);
34
+ this.log(
35
+ `\nWelcome to the ${chalk.bold.yellow('JHipster Sentry Module')} generator! ${chalk.yellow(
36
+ `v${packageJson.version}\n`
37
+ )}`
38
+ );
39
+
40
+ const currentVersion = this.jhipsterAppConfig.jhipsterVersion;
25
41
 
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`));
42
+ if (currentVersion && !semver.satisfies(currentVersion, '>=8.0.0')) {
43
+ this.log(
44
+ chalk.yellow(
45
+ `⚠ Your JHipster version is ${currentVersion}. Recommended >= 8.0.0\n`
46
+ )
47
+ );
30
48
  }
31
49
  }
32
50
 
33
51
  async prompting() {
34
- const prompts = [
52
+ this.promptAnswers = await this.prompt([
35
53
  {
36
54
  type: 'confirm',
37
55
  name: 'enableSentry',
@@ -44,115 +62,135 @@ module.exports = class extends Generator {
44
62
  name: 'sentryDsn',
45
63
  message: 'Enter your Sentry DSN'
46
64
  }
47
- ];
48
- this.promptAnswers = await this.prompt(prompts);
65
+ ]);
49
66
  }
50
67
 
51
68
  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;
69
+ if (!this.promptAnswers.enableSentry) {
70
+ this.log(chalk.yellow('Sentry disabled — skipping integration'));
71
+ return;
72
+ }
73
+
74
+ const {
75
+ baseName,
76
+ packageName,
77
+ packageFolder,
78
+ clientFramework,
79
+ buildTool
80
+ } = this.jhipsterAppConfig;
81
+
62
82
  const webappDir = jhipsterConstants.CLIENT_MAIN_SRC_DIR;
63
83
 
64
- // Persist Sentry config
65
- this.jhipsterAppConfig.sentry = {
66
- enabled: this.promptAnswers.enableSentry,
84
+ this.log('\n--- JHipster Config ---');
85
+ this.log(`baseName=${baseName}`);
86
+ this.log(`packageName=${packageName}`);
87
+ this.log(`clientFramework=${clientFramework}`);
88
+ this.log(`buildTool=${buildTool}`);
89
+ this.log('------------------------\n');
90
+
91
+ /* ============================
92
+ Persist config in .yo-rc.json
93
+ ============================= */
94
+
95
+ const yoRcPath = this.destinationPath('.yo-rc.json');
96
+ const yoRc = this.fs.readJSON(yoRcPath, {});
97
+ yoRc[JHIPSTER_CONFIG_KEY] = yoRc[JHIPSTER_CONFIG_KEY] || {};
98
+ yoRc[JHIPSTER_CONFIG_KEY].sentry = {
99
+ enabled: true,
67
100
  dsn: this.promptAnswers.sentryDsn
68
101
  };
69
- const configPath = this.destinationPath('.yo-rc.json');
70
- const config = this.fs.readJSON(configPath, {});
71
- config['generator-jhipster'] = config['generator-jhipster'] || {};
72
- config['generator-jhipster'].sentry = this.jhipsterAppConfig.sentry;
73
- this.fs.writeJSON(configPath, config, null, 2);
74
102
 
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');
103
+ this.fs.writeJSON(yoRcPath, yoRc, null, 2);
84
104
 
85
- if (!this.promptAnswers.enableSentry) {
86
- this.log(chalk.yellow('Sentry is disabled — skipping integration'));
87
- return;
88
- }
105
+ /* ============================
106
+ Backend Dependency Injection
107
+ ============================= */
89
108
 
90
- // Backend dependencies
91
- if (this.buildTool === 'maven') {
109
+ if (buildTool === 'maven') {
92
110
  const pomPath = this.destinationPath('pom.xml');
93
111
  if (fs.existsSync(pomPath)) {
94
112
  let pom = fs.readFileSync(pomPath, 'utf8');
95
113
  if (!pom.includes('sentry-spring-boot-starter')) {
96
114
  pom = pom.replace(
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>`
115
+ '</dependencies>',
116
+ `
117
+ <dependency>
118
+ <groupId>io.sentry</groupId>
119
+ <artifactId>sentry-spring-boot-starter</artifactId>
120
+ <version>7.3.0</version>
121
+ </dependency>
122
+ </dependencies>`
104
123
  );
105
124
  fs.writeFileSync(pomPath, pom);
106
125
  }
107
126
  }
108
127
  }
109
128
 
110
- if (this.buildTool === 'gradle') {
111
- const buildGradle = this.destinationPath('build.gradle');
112
- if (fs.existsSync(buildGradle)) {
113
- let gradle = fs.readFileSync(buildGradle, 'utf8');
129
+ if (buildTool === 'gradle') {
130
+ const gradlePath = this.destinationPath('build.gradle');
131
+ if (fs.existsSync(gradlePath)) {
132
+ let gradle = fs.readFileSync(gradlePath, 'utf8');
114
133
  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);
134
+ gradle += `
135
+ dependencies {
136
+ implementation "io.sentry:sentry-spring-boot-starter:7.3.0"
137
+ }
138
+ `;
139
+ fs.writeFileSync(gradlePath, gradle);
117
140
  }
118
141
  }
119
142
  }
120
143
 
121
- // Frontend templates
122
- if (this.clientFramework === 'react') {
144
+ /* ============================
145
+ Frontend Dependency Injection
146
+ ============================= */
147
+
148
+ const packagePath = this.destinationPath('package.json');
149
+ if (fs.existsSync(packagePath)) {
150
+ const pkg = this.fs.readJSON(packagePath, {});
151
+ pkg.dependencies = pkg.dependencies || {};
152
+
153
+ if (clientFramework === 'react') {
154
+ pkg.dependencies['@sentry/react'] = '^7.3.0';
155
+
123
156
  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
- ); }
157
+ this.templatePath('client/react/sentry.ts.ejs'),
158
+ `${webappDir}app/sentry.ts`,
159
+ { sentryDsn: this.promptAnswers.sentryDsn }
160
+ );
161
+ }
162
+
163
+ if (clientFramework === 'angularX') {
164
+ pkg.dependencies['@sentry/angular'] = '^7.3.0';
165
+
166
+ this.fs.copyTpl(
167
+ this.templatePath('client/angular/sentry.ts.ejs'),
168
+ `${webappDir}app/sentry.ts`,
169
+ { sentryDsn: this.promptAnswers.sentryDsn }
170
+ );
171
+ }
172
+
173
+ this.fs.writeJSON(packagePath, pkg, null, 2);
174
+ }
137
175
  }
138
176
 
139
177
  install() {
140
178
  if (!this.promptAnswers.enableSentry) return;
141
179
 
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');
147
- }
180
+ const clientPackageManager =
181
+ this.jhipsterAppConfig.clientPackageManager || 'npm';
148
182
 
149
- if (packages.length > 0) {
150
- const cmd = this.clientPackageManager === 'yarn' ? 'add' : 'install';
151
- this.spawnCommandSync(this.clientPackageManager, [...(this.clientPackageManager === 'yarn' ? ['add'] : ['install']), ...packages]);
183
+ if (this.options['skip-install']) {
184
+ this.log(
185
+ `Run ${clientPackageManager} install manually to install dependencies`
186
+ );
187
+ return;
152
188
  }
189
+
190
+ this.spawnCommandSync(clientPackageManager, ['install']);
153
191
  }
154
192
 
155
193
  end() {
156
- this.log(chalk.green('✔ Sentry module generation complete'));
194
+ this.log(chalk.green('\n✔ Sentry module generation complete\n'));
157
195
  }
158
196
  };
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.10",
4
4
  "description": "Adding Sentry integration to JHipster projects",
5
5
  "keywords": [
6
6
  "yeoman-generator",