generator-jhipster-sentry-module 1.0.0 → 1.0.2

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.
package/README.md CHANGED
@@ -44,6 +44,40 @@ To update this module:
44
44
  yarn global upgrade generator-jhipster-sentry-module
45
45
  ```
46
46
 
47
+ ## Using the module locally (development)
48
+
49
+ To use your local clone of this module without publishing to npm (e.g. for development or testing):
50
+
51
+ **Step 1 – Link from the module directory:**
52
+
53
+ ```bash
54
+ cd d:\code\jhipster_sentry # or your module path
55
+ npm link
56
+ ```
57
+
58
+ This makes your local module available globally.
59
+
60
+ **Step 2 – Link in your JHipster project:**
61
+
62
+ ```bash
63
+ cd /path/to/your/jhipster-app
64
+ npm link generator-jhipster-sentry-module
65
+ ```
66
+
67
+ Then run the generator as usual:
68
+
69
+ ```bash
70
+ yo jhipster-sentry-module
71
+ ```
72
+
73
+ **Alternative – install from folder:** In your JHipster project you can instead run:
74
+
75
+ ```bash
76
+ npm install /path/to/jhipster_sentry
77
+ ```
78
+
79
+ For more detail and troubleshooting, see [LINKING_GUIDE.md](LINKING_GUIDE.md).
80
+
47
81
  # Usage
48
82
 
49
83
  After installing the module, run it in your JHipster project:
@@ -1,211 +1,193 @@
1
+ const path = require('path');
1
2
  const chalk = require('chalk');
2
3
  const semver = require('semver');
3
- const BaseGenerator = require('generator-jhipster/generators/generator-base');
4
- const jhipsterConstants = require('generator-jhipster/generators/generator-constants');
5
- const packagejs = require('../../package.json');
6
-
7
- module.exports = class extends BaseGenerator {
8
- get initializing() {
9
- return {
10
- init(args) {
11
- if (args === 'default') {
12
- this.message = 'default message';
13
- }
14
- },
15
-
16
- readConfig() {
17
- this.jhipsterAppConfig = this.getAllJhipsterConfig();
18
- if (!this.jhipsterAppConfig) {
19
- this.error('Cannot read .yo-rc.json');
20
- }
21
- },
22
-
23
- displayLogo() {
24
- this.printJHipsterLogo();
25
- this.log(
26
- `\nWelcome to the ${chalk.bold.yellow(
27
- 'JHipster Sentry Module'
28
- )} generator! ${chalk.yellow(`v${packagejs.version}\n`)}`
29
- );
30
- },
31
-
32
- checkJhipster() {
33
- const currentJhipsterVersion = this.jhipsterAppConfig.jhipsterVersion;
34
- const minimumJhipsterVersion = packagejs.dependencies['generator-jhipster'];
35
-
36
- if (!semver.satisfies(currentJhipsterVersion, minimumJhipsterVersion)) {
37
- this.warning(
38
- `\nYour generated project uses JHipster ${currentJhipsterVersion}. ` +
39
- `Minimum required is ${minimumJhipsterVersion}\n`
40
- );
41
- }
42
- }
43
- };
44
- }
45
-
46
- prompting() {
47
- const prompts = [
48
- {
49
- type: 'confirm',
50
- name: 'enableSentry',
51
- message: 'Do you want to enable Sentry error tracking?',
52
- default: true
53
- },
54
- {
55
- when: answers => answers.enableSentry,
56
- type: 'input',
57
- name: 'sentryDsn',
58
- message: 'Enter your Sentry DSN'
59
- }
60
- ];
61
-
62
- const done = this.async();
63
- this.prompt(prompts).then(answers => {
64
- this.promptAnswers = answers;
65
- done();
66
- });
67
- }
68
-
69
- writing() {
70
- /* -------------------------------
71
- * Read JHipster config
72
- * ----------------------------- */
73
- this.baseName = this.jhipsterAppConfig.baseName;
74
- this.packageName = this.jhipsterAppConfig.packageName;
75
- this.packageFolder = this.jhipsterAppConfig.packageFolder;
76
- this.clientFramework = this.jhipsterAppConfig.clientFramework;
77
- this.clientPackageManager = this.jhipsterAppConfig.clientPackageManager;
78
- this.buildTool = this.jhipsterAppConfig.buildTool;
79
-
80
- this.angularAppName = this.getAngularAppName();
81
-
82
- const javaDir = `${jhipsterConstants.SERVER_MAIN_SRC_DIR}${this.packageFolder}/`;
83
- const resourceDir = jhipsterConstants.SERVER_MAIN_RES_DIR;
84
- const webappDir = jhipsterConstants.CLIENT_MAIN_SRC_DIR;
85
-
86
- /* -------------------------------
87
- * Persist config (regen safe)
88
- * ----------------------------- */
89
- this.jhipsterAppConfig.sentry = {
90
- enabled: this.promptAnswers.enableSentry,
91
- dsn: this.promptAnswers.sentryDsn
92
- };
93
-
94
- // Save config back to .yo-rc.json
95
- const configPath = this.destinationPath('.yo-rc.json');
96
- const fs = require('fs');
97
- if (fs.existsSync(configPath)) {
98
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
99
- if (!config['generator-jhipster']) {
100
- config['generator-jhipster'] = {};
101
- }
102
- config['generator-jhipster'].sentry = this.jhipsterAppConfig.sentry;
103
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
104
- }
105
4
 
106
- /* -------------------------------
107
- * Logging
108
- * ----------------------------- */
109
- this.log('\n--- JHipster Config ---');
110
- this.log(`baseName=${this.baseName}`);
111
- this.log(`packageName=${this.packageName}`);
112
- this.log(`clientFramework=${this.clientFramework}`);
113
- this.log(`buildTool=${this.buildTool}`);
114
-
115
- this.log('\n--- Directories ---');
116
- this.log(`javaDir=${javaDir}`);
117
- this.log(`resourceDir=${resourceDir}`);
118
- this.log(`webappDir=${webappDir}`);
119
-
120
- this.log('\n--- Sentry ---');
121
- this.log(`enabled=${this.promptAnswers.enableSentry}`);
122
- this.log('----------------------\n');
123
-
124
- if (!this.promptAnswers.enableSentry) {
125
- this.log(chalk.yellow('Sentry is disabled — skipping integration'));
126
- return;
5
+ // Resolve generator-jhipster so the module works when installed globally (peer dependency
6
+ // is not under this package's node_modules). Prefer project cwd, then global npm.
7
+ function resolveGeneratorJhipster() {
8
+ // When installed globally, __dirname is .../node_modules/generator-jhipster-sentry-module/generators/app.
9
+ // The folder that contains node_modules (sibling of our package) is one level up from module root = 3 levels from __dirname.
10
+ const globalNodeModulesParent = path.resolve(__dirname, '..', '..', '..', '..');
11
+ const searchPaths = [
12
+ process.cwd(),
13
+ path.join(process.cwd(), 'node_modules'),
14
+ globalNodeModulesParent
15
+ ];
16
+ try {
17
+ const pkgPath = require.resolve('generator-jhipster/package.json', { paths: searchPaths });
18
+ return path.dirname(pkgPath);
19
+ } catch (e) {
20
+ throw new Error(
21
+ 'Could not find generator-jhipster. Install it in your project (npm install generator-jhipster) or globally (npm install -g generator-jhipster).'
22
+ );
23
+ }
24
+ }
25
+
26
+ const jhipsterRoot = resolveGeneratorJhipster();
27
+ const GeneratorBase = require(path.join(jhipsterRoot, 'generators', 'generator-base'));
28
+ const jhipsterConstants = require(path.join(jhipsterRoot, 'generators', 'generator-constants'));
29
+ const packageJson = require('../../package.json');
30
+
31
+ module.exports = class extends GeneratorBase {
32
+ get initializing() {
33
+ return {
34
+ init(args) {
35
+ if (args === 'default') {
36
+ this.message = 'default message';
127
37
  }
38
+ },
128
39
 
129
- /* -------------------------------
130
- * Backend (Spring Boot)
131
- * ----------------------------- */
132
- if (this.buildTool === 'maven') {
133
- this.addMavenDependency(
134
- 'io.sentry',
135
- 'sentry-spring-boot-starter',
136
- '7.3.0'
137
- );
40
+ readConfig() {
41
+ this.jhipsterAppConfig = this.getAllJhipsterConfig();
42
+ if (!this.jhipsterAppConfig) {
43
+ this.error('Cannot read .yo-rc.json');
138
44
  }
139
-
140
- if (this.buildTool === 'gradle') {
141
- this.addGradleDependency(
142
- 'implementation',
143
- 'io.sentry:sentry-spring-boot-starter:7.3.0'
144
- );
145
- }
146
-
147
- this.template(
148
- 'server/sentry-application.yml.ejs',
149
- `${resourceDir}config/sentry.yml`
45
+ },
46
+
47
+ displayLogo() {
48
+ this.printJHipsterLogo();
49
+ this.log(
50
+ `\nWelcome to the ${chalk.bold.yellow('JHipster Sentry Module')} generator! ${chalk.yellow(
51
+ `v${packageJson.version}\n`
52
+ )}`
150
53
  );
54
+ },
151
55
 
152
- /* -------------------------------
153
- * Frontend
154
- * ----------------------------- */
155
- if (this.clientFramework === 'react') {
156
- this.addNpmDependency('@sentry/react', '^7.3.0');
56
+ checkJhipster() {
57
+ const currentJhipsterVersion = this.jhipsterAppConfig.jhipsterVersion;
58
+ const minimumJhipsterVersion = '>=8.0.0';
157
59
 
158
- this.template(
159
- 'client/react/sentry.ts.ejs',
160
- `${webappDir}app/sentry.ts`
161
- );
60
+ if (!semver.satisfies(currentJhipsterVersion, minimumJhipsterVersion)) {
61
+ this.warning(
62
+ `\nYour generated project uses JHipster ${currentJhipsterVersion}. Minimum required is ${minimumJhipsterVersion}\n`
63
+ );
162
64
  }
65
+ }
66
+ };
67
+ }
68
+
69
+ async prompting() {
70
+ const prompts = [
71
+ {
72
+ type: 'confirm',
73
+ name: 'enableSentry',
74
+ message: 'Do you want to enable Sentry error tracking?',
75
+ default: true
76
+ },
77
+ {
78
+ when: answers => answers.enableSentry,
79
+ type: 'input',
80
+ name: 'sentryDsn',
81
+ message: 'Enter your Sentry DSN'
82
+ }
83
+ ];
84
+
85
+ this.promptAnswers = await this.prompt(prompts);
86
+ }
87
+
88
+ writing() {
89
+ // Read JHipster config
90
+ this.baseName = this.jhipsterAppConfig.baseName;
91
+ this.packageName = this.jhipsterAppConfig.packageName;
92
+ this.packageFolder = this.jhipsterAppConfig.packageFolder;
93
+ this.clientFramework = this.jhipsterAppConfig.clientFramework;
94
+ this.clientPackageManager = this.jhipsterAppConfig.clientPackageManager;
95
+ this.buildTool = this.jhipsterAppConfig.buildTool;
96
+
97
+ this.angularAppName = this.getAngularAppName();
98
+
99
+ const javaDir = `${jhipsterConstants.SERVER_MAIN_SRC_DIR}${this.packageFolder}/`;
100
+ const resourceDir = jhipsterConstants.SERVER_MAIN_RES_DIR;
101
+ const webappDir = jhipsterConstants.CLIENT_MAIN_SRC_DIR;
102
+
103
+ // Persist Sentry config
104
+ this.jhipsterAppConfig.sentry = {
105
+ enabled: this.promptAnswers.enableSentry,
106
+ dsn: this.promptAnswers.sentryDsn
107
+ };
108
+
109
+ // Write to .yo-rc.json safely
110
+ const fs = require('fs');
111
+ const configPath = this.destinationPath('.yo-rc.json');
112
+ if (fs.existsSync(configPath)) {
113
+ const config = this.fs.readJSON(configPath, {});
114
+ config['generator-jhipster'] = config['generator-jhipster'] || {};
115
+ config['generator-jhipster'].sentry = this.jhipsterAppConfig.sentry;
116
+ this.fs.writeJSON(configPath, config, null, 2);
117
+ }
163
118
 
164
- if (this.clientFramework === 'angularX') {
165
- this.addNpmDependency('@sentry/angular', '^7.3.0');
119
+ // Logging
120
+ this.log('\n--- JHipster Config ---');
121
+ this.log(`baseName=${this.baseName}`);
122
+ this.log(`packageName=${this.packageName}`);
123
+ this.log(`clientFramework=${this.clientFramework}`);
124
+ this.log(`buildTool=${this.buildTool}`);
125
+
126
+ this.log('\n--- Directories ---');
127
+ this.log(`javaDir=${javaDir}`);
128
+ this.log(`resourceDir=${resourceDir}`);
129
+ this.log(`webappDir=${webappDir}`);
130
+
131
+ this.log('\n--- Sentry ---');
132
+ this.log(`enabled=${this.promptAnswers.enableSentry}`);
133
+ this.log('----------------------\n');
134
+
135
+ if (!this.promptAnswers.enableSentry) {
136
+ this.log(chalk.yellow('Sentry is disabled — skipping integration'));
137
+ return;
138
+ }
166
139
 
167
- this.template(
168
- 'client/angular/sentry.ts.ejs',
169
- `${webappDir}app/sentry.ts`
170
- );
171
- }
140
+ // Backend
141
+ if (this.buildTool === 'maven') {
142
+ this.addMavenDependency('io.sentry', 'sentry-spring-boot-starter', '7.3.0');
143
+ }
144
+ if (this.buildTool === 'gradle') {
145
+ this.addGradleDependency('implementation', 'io.sentry:sentry-spring-boot-starter:7.3.0');
146
+ }
147
+ this.template('server/sentry-application.yml.ejs', `${resourceDir}config/sentry.yml`);
172
148
 
173
- /* -------------------------------
174
- * Register module hook
175
- * ----------------------------- */
176
- try {
177
- this.registerModule(
178
- 'generator-jhipster-sentry-module',
179
- 'app',
180
- 'post',
181
- 'app',
182
- 'Adds Sentry integration'
183
- );
184
- } catch (err) {
185
- this.log(
186
- `${chalk.red.bold('WARN!')} Could not register JHipster hook`
187
- );
188
- }
149
+ // Frontend
150
+ if (this.clientFramework === 'react') {
151
+ this.addNpmDependency('@sentry/react', '^7.3.0');
152
+ this.template('client/react/sentry.ts.ejs', `${webappDir}app/sentry.ts`);
153
+ }
154
+ if (this.clientFramework === 'angularX') {
155
+ this.addNpmDependency('@sentry/angular', '^7.3.0');
156
+ this.template('client/angular/sentry.ts.ejs', `${webappDir}app/sentry.ts`);
189
157
  }
190
158
 
191
- install() {
192
- const logMsg = `To install dependencies manually, run: ${chalk.yellow.bold(
193
- `${this.clientPackageManager} install`
194
- )}`;
159
+ // Register module hook
160
+ try {
161
+ this.registerModule(
162
+ 'generator-jhipster-sentry-module',
163
+ 'app',
164
+ 'post',
165
+ 'app',
166
+ 'Adds Sentry integration'
167
+ );
168
+ } catch (err) {
169
+ this.log(`${chalk.red.bold('WARN!')} Could not register JHipster hook`);
170
+ }
171
+ }
195
172
 
196
- if (this.options['skip-install']) {
197
- this.log(logMsg);
198
- return;
199
- }
173
+ install() {
174
+ const logMsg = `To install dependencies manually, run: ${chalk.yellow.bold(
175
+ `${this.clientPackageManager} install`
176
+ )}`;
200
177
 
201
- this.installDependencies({
202
- npm: this.clientPackageManager === 'npm',
203
- yarn: this.clientPackageManager === 'yarn',
204
- bower: false
205
- });
178
+ if (this.options['skip-install']) {
179
+ this.log(logMsg);
180
+ return;
206
181
  }
207
182
 
208
- end() {
209
- this.log(chalk.green('✔ Sentry module generation complete'));
210
- }
211
- };
183
+ this.installDependencies({
184
+ npm: this.clientPackageManager === 'npm',
185
+ yarn: this.clientPackageManager === 'yarn',
186
+ bower: false
187
+ });
188
+ }
189
+
190
+ end() {
191
+ this.log(chalk.green('✔ Sentry module generation complete'));
192
+ }
193
+ };
@@ -1,6 +1,6 @@
1
- import * as Sentry from '@sentry/angular';
2
-
3
- Sentry.init({
4
- dsn: '<%= jhipsterAppConfig.sentry.dsn %>',
5
- environment: 'dev',
6
- });
1
+ import * as Sentry from '@sentry/angular';
2
+
3
+ Sentry.init({
4
+ dsn: '<%= jhipsterAppConfig.sentry.dsn %>',
5
+ environment: 'dev',
6
+ });
@@ -1,6 +1,6 @@
1
- import * as Sentry from '@sentry/react';
2
-
3
- Sentry.init({
4
- dsn: '<%= jhipsterAppConfig.sentry.dsn %>',
5
- environment: 'dev',
6
- });
1
+ import * as Sentry from '@sentry/react';
2
+
3
+ Sentry.init({
4
+ dsn: '<%= jhipsterAppConfig.sentry.dsn %>',
5
+ environment: 'dev',
6
+ });
@@ -1,4 +1,4 @@
1
- sentry:
2
- dsn: "<%= jhipsterAppConfig.sentry.dsn %>"
3
- environment: dev
4
- traces-sample-rate: 0.2
1
+ sentry:
2
+ dsn: "<%= jhipsterAppConfig.sentry.dsn %>"
3
+ environment: dev
4
+ traces-sample-rate: 0.2
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "generator-jhipster-sentry-module",
3
- "version": "1.0.0",
4
- "description": "adding sentry to jhipster generator",
3
+ "version": "1.0.2",
4
+ "description": "Adding Sentry integration to JHipster projects",
5
5
  "keywords": [
6
6
  "yeoman-generator",
7
7
  "jhipster-module",
8
+ "jhipster-generator",
8
9
  "jhipster",
9
10
  "jhipster-6",
10
11
  "jhipster-blueprint",
@@ -20,32 +21,36 @@
20
21
  "files": [
21
22
  "generators"
22
23
  ],
24
+ "engines": {
25
+ "node": ">=18.0.0"
26
+ },
23
27
  "main": "generators/app/index.js",
24
28
  "repository": {
25
29
  "type": "git",
26
30
  "url": "git+https://github.com/Sara/generator-jhipster-sentry-module.git"
27
31
  },
28
32
  "dependencies": {
29
- "chalk": "3.0.0",
30
- "generator-jhipster": ">=6.0.0",
31
- "mkdirp": "0.5.1",
32
- "semver": "7.1.1",
33
- "shelljs": "0.8.3",
34
- "yeoman-generator": "4.4.0"
33
+ "chalk": "^5.3.0",
34
+ "mkdirp": "^1.0.4",
35
+ "semver": "^7.5.4",
36
+ "shelljs": "^0.8.5",
37
+ "yeoman-generator": "^5.10.0"
38
+ },
39
+ "peerDependencies": {
40
+ "generator-jhipster": ">=8.0.0"
35
41
  },
36
42
  "devDependencies": {
37
- "eslint": "6.8.0",
38
- "eslint-config-airbnb-base": "14.0.0",
39
- "eslint-config-prettier": "6.9.0",
40
- "eslint-plugin-import": "2.19.1",
41
- "eslint-plugin-prettier": "3.1.2",
42
- "fs-extra": "8.1.0",
43
- "husky": "3.1.0",
44
- "lint-staged": "9.5.0",
45
- "mocha": "6.2.2",
46
- "prettier": "1.19.1",
47
- "yeoman-assert": "3.1.1",
48
- "yeoman-test": "2.0.0"
43
+ "eslint": "^8.57.0",
44
+ "eslint-config-airbnb-base": "^15.0.0",
45
+ "eslint-config-prettier": "^9.1.0",
46
+ "eslint-plugin-import": "^2.29.1",
47
+ "eslint-plugin-prettier": "^5.1.3",
48
+ "fs-extra": "^11.2.0",
49
+ "mocha": "^10.4.0",
50
+ "prettier": "^3.2.5",
51
+ "yeoman-assert": "^3.1.1",
52
+ "husky": "^8.0.2",
53
+ "lint-staged": "^13.2.1"
49
54
  },
50
55
  "scripts": {
51
56
  "prettier:format": "prettier --write \"{,**/}*.{js,json,md,yml}\"",