generator-jhipster-sentry-module 1.0.9 → 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.
- package/generators/app/index.js +99 -43
- package/package.json +1 -1
package/generators/app/index.js
CHANGED
|
@@ -5,6 +5,8 @@ const semver = require('semver');
|
|
|
5
5
|
const Generator = require('yeoman-generator');
|
|
6
6
|
const packageJson = require('../../package.json');
|
|
7
7
|
|
|
8
|
+
const JHIPSTER_CONFIG_KEY = 'generator-jhipster';
|
|
9
|
+
|
|
8
10
|
const jhipsterConstants = {
|
|
9
11
|
SERVER_MAIN_SRC_DIR: 'src/main/java/',
|
|
10
12
|
SERVER_MAIN_RES_DIR: 'src/main/resources/',
|
|
@@ -14,12 +16,19 @@ const jhipsterConstants = {
|
|
|
14
16
|
module.exports = class extends Generator {
|
|
15
17
|
|
|
16
18
|
async initializing() {
|
|
17
|
-
const
|
|
18
|
-
|
|
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];
|
|
19
28
|
|
|
20
29
|
if (!this.jhipsterAppConfig) {
|
|
21
|
-
this.log(chalk.red('
|
|
22
|
-
|
|
30
|
+
this.log(chalk.red('❌ JHipster configuration missing inside .yo-rc.json'));
|
|
31
|
+
process.exit(1);
|
|
23
32
|
}
|
|
24
33
|
|
|
25
34
|
this.log(
|
|
@@ -28,11 +37,12 @@ module.exports = class extends Generator {
|
|
|
28
37
|
)}`
|
|
29
38
|
);
|
|
30
39
|
|
|
31
|
-
const currentVersion = this.jhipsterAppConfig.jhipsterVersion
|
|
32
|
-
|
|
40
|
+
const currentVersion = this.jhipsterAppConfig.jhipsterVersion;
|
|
41
|
+
|
|
42
|
+
if (currentVersion && !semver.satisfies(currentVersion, '>=8.0.0')) {
|
|
33
43
|
this.log(
|
|
34
44
|
chalk.yellow(
|
|
35
|
-
|
|
45
|
+
`⚠ Your JHipster version is ${currentVersion}. Recommended >= 8.0.0\n`
|
|
36
46
|
)
|
|
37
47
|
);
|
|
38
48
|
}
|
|
@@ -56,7 +66,10 @@ module.exports = class extends Generator {
|
|
|
56
66
|
}
|
|
57
67
|
|
|
58
68
|
writing() {
|
|
59
|
-
if (!this.
|
|
69
|
+
if (!this.promptAnswers.enableSentry) {
|
|
70
|
+
this.log(chalk.yellow('Sentry disabled — skipping integration'));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
60
73
|
|
|
61
74
|
const {
|
|
62
75
|
baseName,
|
|
@@ -67,34 +80,39 @@ module.exports = class extends Generator {
|
|
|
67
80
|
} = this.jhipsterAppConfig;
|
|
68
81
|
|
|
69
82
|
const webappDir = jhipsterConstants.CLIENT_MAIN_SRC_DIR;
|
|
70
|
-
const resourceDir = jhipsterConstants.SERVER_MAIN_RES_DIR;
|
|
71
83
|
|
|
72
|
-
|
|
73
|
-
this.
|
|
74
|
-
|
|
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,
|
|
75
100
|
dsn: this.promptAnswers.sentryDsn
|
|
76
101
|
};
|
|
77
102
|
|
|
78
|
-
|
|
79
|
-
const config = this.fs.readJSON(configPath, {});
|
|
80
|
-
config['generator-jhipster'].sentry = this.jhipsterAppConfig.sentry;
|
|
81
|
-
this.fs.writeJSON(configPath, config, null, 2);
|
|
103
|
+
this.fs.writeJSON(yoRcPath, yoRc, null, 2);
|
|
82
104
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
105
|
+
/* ============================
|
|
106
|
+
Backend Dependency Injection
|
|
107
|
+
============================= */
|
|
87
108
|
|
|
88
|
-
// ======================
|
|
89
|
-
// Backend (Maven only safe injection)
|
|
90
|
-
// ======================
|
|
91
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
|
-
|
|
115
|
+
'</dependencies>',
|
|
98
116
|
`
|
|
99
117
|
<dependency>
|
|
100
118
|
<groupId>io.sentry</groupId>
|
|
@@ -108,33 +126,71 @@ module.exports = class extends Generator {
|
|
|
108
126
|
}
|
|
109
127
|
}
|
|
110
128
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
129
|
+
if (buildTool === 'gradle') {
|
|
130
|
+
const gradlePath = this.destinationPath('build.gradle');
|
|
131
|
+
if (fs.existsSync(gradlePath)) {
|
|
132
|
+
let gradle = fs.readFileSync(gradlePath, 'utf8');
|
|
133
|
+
if (!gradle.includes('sentry-spring-boot-starter')) {
|
|
134
|
+
gradle += `
|
|
135
|
+
dependencies {
|
|
136
|
+
implementation "io.sentry:sentry-spring-boot-starter:7.3.0"
|
|
137
|
+
}
|
|
138
|
+
`;
|
|
139
|
+
fs.writeFileSync(gradlePath, gradle);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
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
|
+
|
|
156
|
+
this.fs.copyTpl(
|
|
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';
|
|
120
165
|
|
|
121
|
-
|
|
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);
|
|
122
174
|
}
|
|
175
|
+
}
|
|
123
176
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.templatePath('client/angular/sentry.ts.ejs'),
|
|
127
|
-
this.destinationPath(`${webappDir}app/sentry.ts`),
|
|
128
|
-
{ sentryDsn: this.promptAnswers.sentryDsn }
|
|
129
|
-
);
|
|
177
|
+
install() {
|
|
178
|
+
if (!this.promptAnswers.enableSentry) return;
|
|
130
179
|
|
|
131
|
-
|
|
180
|
+
const clientPackageManager =
|
|
181
|
+
this.jhipsterAppConfig.clientPackageManager || 'npm';
|
|
182
|
+
|
|
183
|
+
if (this.options['skip-install']) {
|
|
184
|
+
this.log(
|
|
185
|
+
`Run ${clientPackageManager} install manually to install dependencies`
|
|
186
|
+
);
|
|
187
|
+
return;
|
|
132
188
|
}
|
|
133
189
|
|
|
134
|
-
this.
|
|
190
|
+
this.spawnCommandSync(clientPackageManager, ['install']);
|
|
135
191
|
}
|
|
136
192
|
|
|
137
193
|
end() {
|
|
138
|
-
this.log(chalk.green('✔ Sentry module generation complete'));
|
|
194
|
+
this.log(chalk.green('\n✔ Sentry module generation complete\n'));
|
|
139
195
|
}
|
|
140
196
|
};
|