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.
- package/generators/app/index.js +64 -82
- package/package.json +1 -1
package/generators/app/index.js
CHANGED
|
@@ -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
|
-
|
|
18
|
-
this.jhipsterAppConfig =
|
|
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
|
-
|
|
22
|
+
return;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
this.log(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
//
|
|
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
|
|
84
|
+
this.log(chalk.yellow('Sentry disabled — skipping integration'));
|
|
87
85
|
return;
|
|
88
86
|
}
|
|
89
87
|
|
|
90
|
-
//
|
|
91
|
-
|
|
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
|
-
`
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
</
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
this.
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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() {
|