|
| 1 | +/* eslint-disable max-len, max-lines-per-function */ |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +const path = require('path'); |
| 5 | +const { execSync } = require('child_process'); |
| 6 | +const BasePlugin = require('ember-cli-deploy-plugin'); |
| 7 | + |
| 8 | +module.exports = { |
| 9 | + name: require('./package').name, |
| 10 | + |
| 11 | + createDeployPlugin(options) { |
| 12 | + const DeployPlugin = BasePlugin.extend({ |
| 13 | + name: options.name, |
| 14 | + |
| 15 | + defaultConfig: { |
| 16 | + assetsDir(context) { |
| 17 | + return path.join(context.distDir, 'assets'); |
| 18 | + }, |
| 19 | + |
| 20 | + revisionKey(context) { |
| 21 | + return context.revisionData && context.revisionData.revisionKey; |
| 22 | + }, |
| 23 | + |
| 24 | + environment(context) { |
| 25 | + return context.deployTarget; |
| 26 | + } |
| 27 | + }, |
| 28 | + |
| 29 | + requiredConfig: ['appName', 'orgName', 'authToken'], |
| 30 | + |
| 31 | + didPrepare() { |
| 32 | + const releaseName = `${this.readConfig('appName')}@${this.readConfig('revisionKey')}`; |
| 33 | + const assetsDir = this.readConfig('assetsDir'); |
| 34 | + |
| 35 | + this.log('SENTRY: Creating release...'); |
| 36 | + this.sentryCliExec(`releases new ${releaseName}`); |
| 37 | + |
| 38 | + this.log('SENTRY: Assigning commits...'); |
| 39 | + this.sentryCliExec(`releases set-commits --auto ${releaseName}`); |
| 40 | + |
| 41 | + this.log('SENTRY: Uploading source maps...'); |
| 42 | + this.sentryCliExec(`releases files ${releaseName} upload-sourcemaps --rewrite ${assetsDir}`); |
| 43 | + |
| 44 | + this.log('SENTRY: Finalizing release...'); |
| 45 | + this.sentryCliExec(`releases finalize ${releaseName}`); |
| 46 | + |
| 47 | + this.log('SENTRY: Release published!...'); |
| 48 | + }, |
| 49 | + |
| 50 | + didDeploy() { |
| 51 | + const appName = this.readConfig('appName'); |
| 52 | + const releaseName = `${appName}@${this.readConfig('revisionKey')}`; |
| 53 | + const environment = this.readConfig('environment'); |
| 54 | + |
| 55 | + this.log('SENTRY: Deploying release...'); |
| 56 | + this.sentryCliExec(`releases deploys ${releaseName} new -e ${environment}`); |
| 57 | + this.log('SENTRY: Deployed!'); |
| 58 | + }, |
| 59 | + |
| 60 | + didFail() { |
| 61 | + const appName = this.readConfig('appName'); |
| 62 | + const releaseName = `${appName}@${this.readConfig('revisionKey')}`; |
| 63 | + |
| 64 | + this.log('SENTRY: Deleting release...'); |
| 65 | + this.sentryCliExec(`releases delete ${releaseName}`); |
| 66 | + this.log('SENTRY: Release deleted!'); |
| 67 | + }, |
| 68 | + |
| 69 | + sentryCliExec(command) { |
| 70 | + const authToken = this.readConfig('authToken'); |
| 71 | + const orgName = this.readConfig('orgName'); |
| 72 | + const appName = this.readConfig('appName'); |
| 73 | + |
| 74 | + return this._exec( |
| 75 | + `SENTRY_ORG=${orgName} ` + |
| 76 | + `SENTRY_AUTH_TOKEN=${authToken} ` + |
| 77 | + `SENTRY_PROJECT=${appName} ` + |
| 78 | + `node_modules/.bin/sentry-cli ${command}` |
| 79 | + ); |
| 80 | + }, |
| 81 | + |
| 82 | + _exec(command = '') { |
| 83 | + return execSync(command, { cwd: this.project.root }); |
| 84 | + } |
| 85 | + }); |
| 86 | + |
| 87 | + return new DeployPlugin(); |
| 88 | + } |
| 89 | +}; |
0 commit comments