Skip to content

Commit 859e82b

Browse files
committed
chore: updated readme
1 parent 86d9a53 commit 859e82b

File tree

1 file changed

+86
-2
lines changed

1 file changed

+86
-2
lines changed

README.md

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,96 @@
99

1010
Be sure to run a new build after adding plugins to avoid any issues.
1111

12-
# Usage
12+
# Configuration
13+
14+
## Webpack
15+
16+
You will need to add something like this to your webpack config so that the source maps gets uploaded. I dont set `auth` or `project` in the options as i use a `.sentryclirc` config file.
17+
* `SOURCEMAP_REL_DIR`: i almost always set it to `../../sourcemaps`
18+
* `SENTRY_PREFIX`: i almost always set it to `app:///`
19+
```javascript
20+
if (!!sentry && !!uploadSentry) {
21+
config.devtool = false;
22+
config.plugins.push(
23+
new webpack.SourceMapDevToolPlugin({
24+
append: `\n//# sourceMappingURL=${process.env.SENTRY_PREFIX}[name].js.map`,
25+
filename: join(process.env.SOURCEMAP_REL_DIR, '[name].js.map')
26+
})
27+
);
28+
let appVersion;
29+
let buildNumber;
30+
if (isAndroid) {
31+
const gradlePath = `${appResourcesPath}/Android/app.gradle`;
32+
const gradleData = readFileSync(gradlePath, 'utf8');
33+
appVersion = gradleData.match(/versionName "((?:[0-9]+\.?)+)"/)[1];
34+
buildNumber = gradleData.match(/versionCode ([0-9]+)/)[1];
35+
} else if (isIOS) {
36+
const plistPath = `${appResourcesPath}/iOS/Info.plist`;
37+
const plistData = readFileSync(plistPath, 'utf8');
38+
appVersion = plistData.match(/<key>CFBundleShortVersionString<\/key>[\s\n]*<string>(.*?)<\/string>/)[1];
39+
buildNumber = plistData.match(/<key>CFBundleVersion<\/key>[\s\n]*<string>([0-9]*)<\/string>/)[1];
40+
}
41+
config.plugins.push(
42+
new SentryCliPlugin({
43+
release: appVersion,
44+
urlPrefix: 'app:///',
45+
rewrite: true,
46+
release: `${nconfig.id}@${appVersion}+${buildNumber}`,
47+
dist: `${buildNumber}.${platform}`,
48+
ignoreFile: '.sentrycliignore',
49+
include: [join(dist, process.env.SOURCEMAP_REL_DIR)]
50+
})
51+
);
52+
}
53+
```
54+
55+
## Fastlane
56+
57+
If you use fastlane you can use it to create release and upload dsyms
58+
To do that you need to install it:
59+
```sh
60+
fastlane add_plugin sentry
61+
```
62+
Also for now you should install `nativescript-set-version` as it is needed to read app version, build number.
63+
```sh
64+
npm install -D nativescript-set-version
65+
```
66+
67+
Now you can setup your `Fastfile`
68+
* create release
69+
```
70+
version = ""
71+
versionCode = ""
72+
73+
Dir.chdir("..") do
74+
version = sh("./node_modules/.bin/get-version", platform, "version").gsub(/\n/,'')
75+
versionCode = sh("./node_modules/.bin/get-version", platform, "code").gsub(/\n/,'')
76+
end
77+
sentry_create_release(
78+
version: version, # release version to create
79+
)
80+
```
81+
82+
* upload dsyms
83+
```
84+
sentry_upload_dsym
85+
```
86+
87+
# Usage in the app
1388

1489
```typescript
1590
import * as Sentry from '@nativescript-community/sentry';
91+
import { getBuildNumber } from '@nativescript-community/extendedinfo';
92+
93+
const buildNumber = await getBuildNumber();
94+
// setting the platform in dist allows to have
95+
// android and ios dist inside the same release
96+
const dist = `${buildNumber}.${global.isAndroid ? 'android' : 'ios'}`;
1697
Sentry.init({
17-
dsn: "__DSN__"
98+
dsn: "__DSN__",
99+
// SENTRY_PREFIX is the same as the one you use in webpack config
100+
appPrefix: SENTRY_PREFIX,
101+
dist
18102
});
19103
```
20104

0 commit comments

Comments
 (0)