forked from EmberExperts/ember-cli-deploy-sentry-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
124 lines (101 loc) · 3.64 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* eslint-disable comma-dangle */
/* eslint-disable max-len, max-lines-per-function */
// eslint-disable-next-line strict
'use strict';
const path = require('path');
const { execSync } = require('child_process');
const BasePlugin = require('ember-cli-deploy-plugin');
const packageJson = require("./package.json");
// Dynamically resolve `sentry-cli` location
const sentryCliPackagePath = require.resolve("@sentry/cli/package.json");
const { dir: sentryCliDirectory } = path.parse(sentryCliPackagePath);
const sentryCliRelativeBinLocation =
require(sentryCliPackagePath).bin["sentry-cli"];
const sentryCliAbsoluteBinLocation = path.join(
sentryCliDirectory,
sentryCliRelativeBinLocation
);
module.exports = {
name: packageJson.name,
createDeployPlugin(options) {
const DeployPlugin = BasePlugin.extend({
name: options.name,
defaultConfig: {
assetsDir(context) {
return path.join(context.distDir, "assets");
},
revisionKey(context) {
return context.revisionData && context.revisionData.revisionKey;
},
environment(context) {
return context.deployTarget;
},
url: "",
},
requiredConfig: ["appName", "orgName", "authToken"],
didPrepare() {
const releaseName = `${this.readConfig("appName")}@${this.readConfig(
"revisionKey"
)}`;
const assetsDir = this.readConfig("assetsDir");
const urlPrefix = this.readConfig("urlPrefix")
? `--url-prefix ${this.readConfig("urlPrefix")}`
: "";
this.log("SENTRY: Creating release...");
this.sentryCliExec("releases", `new "${releaseName}"`);
this.log("SENTRY: Assigning commits...");
this.sentryCliExec(
"releases",
`set-commits "${releaseName}" --auto --ignore-missing --ignore-empty`
);
this.log("SENTRY: Uploading source maps...");
this.sentryCliExec(
"releases",
`files "${releaseName}" upload-sourcemaps --rewrite ${assetsDir} ${urlPrefix}`
);
this.log("SENTRY: Finalizing release...");
this.sentryCliExec("releases", `finalize "${releaseName}"`);
this.log("SENTRY: Release published!...");
},
didDeploy() {
const appName = this.readConfig("appName");
const releaseName = `${appName}@${this.readConfig("revisionKey")}`;
const environment = this.readConfig("environment");
this.log("SENTRY: Deploying release...");
this.sentryCliExec(
"releases",
`deploys "${releaseName}" new -e ${environment}`
);
this.log("SENTRY: Deployed!");
},
didFail() {
const appName = this.readConfig("appName");
const releaseName = `${appName}@${this.readConfig("revisionKey")}`;
this.log("SENTRY: Deleting release...");
this.sentryCliExec("releases", `delete "${releaseName}"`);
this.log("SENTRY: Release deleted!");
},
sentryCliExec(command, subCommand) {
const authToken = this.readConfig("authToken");
const orgName = this.readConfig("orgName");
const appName = this.readConfig("appName");
const url = this.readConfig("url");
return this._exec(
[
sentryCliAbsoluteBinLocation,
url ? `--url ${url}` : "",
`--auth-token ${authToken}`,
command,
`--org ${orgName}`,
`--project ${appName}`,
subCommand,
].join(" ")
);
},
_exec(command = "") {
return execSync(command, { cwd: this.project.root });
},
});
return new DeployPlugin();
},
};