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.
- package/generators/app/index.js +121 -83
- package/package.json +1 -1
package/generators/app/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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];
|
|
28
|
+
|
|
19
29
|
if (!this.jhipsterAppConfig) {
|
|
20
|
-
this.log(chalk.red('
|
|
30
|
+
this.log(chalk.red('❌ JHipster configuration missing inside .yo-rc.json'));
|
|
21
31
|
process.exit(1);
|
|
22
32
|
}
|
|
23
33
|
|
|
24
|
-
this.log(
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
65
|
-
this.
|
|
66
|
-
|
|
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
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
105
|
+
/* ============================
|
|
106
|
+
Backend Dependency Injection
|
|
107
|
+
============================= */
|
|
89
108
|
|
|
90
|
-
|
|
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
|
-
|
|
98
|
-
`
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
</
|
|
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 (
|
|
111
|
-
const
|
|
112
|
-
if (fs.existsSync(
|
|
113
|
-
let gradle = fs.readFileSync(
|
|
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 +=
|
|
116
|
-
|
|
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
|
-
|
|
122
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
|
143
|
-
|
|
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 (
|
|
150
|
-
|
|
151
|
-
|
|
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
|
};
|