Created
November 27, 2019 07:40
-
-
Save PezCoder/05b195a5e788ffd4c3717bb5ec3909cc to your computer and use it in GitHub Desktop.
Upload source maps to sentry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Credit: https://github.com/supriya-raj | |
var spawn = require('child_process').spawnSync; | |
var sentryHost, sentryAuthToken, sentryProjectName, sentryOrg, release; | |
/* | |
Change based on your requirement: | |
sourceMapsPath: relative path to the folder that contains your minified scripts & source maps | |
jsUrlPrefix: ~ (tilde) -> Acts as your domain. Ex: if the source maps are hosted on domain.com/js/file.js.map | |
this should be '~/js' | |
release: source maps will be pushed under this release name | |
sentryConfig: { | |
org: 'dummyorg' | |
project: 'my-js-project' | |
host: 'https://sentry9.dummyorg.com' | |
auth_token: ~ | |
} | |
^ Example configuration for the sentry url: https://sentry9.dummyorg.com/dummyorg/my-js-project | |
*/ | |
var sourceMapsPath = 'web/js'; | |
var jsUrlPrefix = '~/js'; | |
var sentryConfig = require('./sentry-config.js') | |
if(sentryConfig) { | |
sentryHost = sentryConfig['host']; | |
sentryProjectName = sentryConfig['project']; | |
sentryOrg = sentryConfig['org']; | |
sentryAuthToken = sentryConfig['auth_token']; | |
} | |
release = process.env.COMMIT_HASH; | |
if (!sentryAuthToken || !sentryHost || !sentryProjectName || !sentryOrg) { | |
console.log(console.log('[Error] One or more config parameters required for source map upload are missing!')); | |
process.exit(1); | |
} | |
if (!release) { | |
console.log(console.log('[Error] Environment variable COMMIT_HASH does not exist!')); | |
process.exit(1); | |
} | |
spawn( | |
'./node_modules/.bin/sentry-cli', | |
[ | |
'--auth-token', sentryAuthToken, '--url', sentryHost, 'releases', | |
'--org', sentryOrg, '--project', sentryProjectName, | |
'files', release, 'upload-sourcemaps', sourceMapsPath, | |
'--url-prefix', jsUrlPrefix, "--no-sourcemap-reference" | |
], | |
{stdio: "inherit"} | |
); | |
spawn( | |
'find', | |
[sourceMapsPath, '-type' ,'f', '-iname', '\*.js.map', '-delete'], | |
{stdio: "inherit"} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment