-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
115 lines (99 loc) · 3.9 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
/* eslint-env node */
/* eslint-disable ember/avoid-leaking-state-in-ember-objects */
'use strict';
const BasePlugin = require('ember-cli-deploy-plugin');
const rp = require('request-promise');
const git = require('git-last-commit');
const Q = require('q');
const path = require('path');
const fs = require('fs');
module.exports = {
name: 'ember-cli-deploy-raygun',
init() {
this._super(...arguments);
},
createDeployPlugin(options) {
let DeployPlugin = BasePlugin.extend({
name: options.name,
requiredConfig: ['key', 'token'],
defaultConfig: {
scmType: 'Github'
},
didDeploy(context) {
this.log('Creating Raygun Deployment');
return Q.ninvoke(git, 'getLastCommit').then((commit) => {
return rp({
method: 'POST',
url: 'https://app.raygun.io/deployments?authToken=' + this.readConfig('token'),
json: true,
body: {
apiKey: this.readConfig('key'),
version: `${context.project.pkg.version}+${commit.hash.substring(0, 8)}`,
ownerName: commit.author.name,
emailAddress: commit.author.email,
comment: commit.notes,
scmIdentifier: commit.hash,
scmType: this.readConfig('scmType')
}
})
.then(() => {
let mapFiles = context.distFiles ? context.distFiles.filter((file) => file.endsWith('.map')) : [];
if (mapFiles.length) {
let prefix = this.readConfig('prefix');
let appId = this.readConfig('appId');
if (!prefix) {
this.log('You must provide prefix config to upload sourcemaps to Raygun - Skipping stage', {
color: 'red'
});
return;
}
if (!appId) {
this.log('You must provide appId config to updload sourcemaps to Raygun - Skipping stage', {
color: 'red'
});
}
this.log('Uploading sourcemaps to Raygun');
let promises = mapFiles.map((file) => {
let matchingDistFile = context.distFiles
.filter((distFile) => !distFile.endsWith('.map'))
.find((distFile) => {
let fingerPrintRegex = /(.*)-[\w]{32}.js/;
if (distFile.match(fingerPrintRegex)) {
let mapFileResults = /(.*)-[\w]{32}.map/.exec(file);
let distFileResults = fingerPrintRegex.exec(distFile);
return distFileResults[1] === mapFileResults[1]
} else if (distFile.endsWith('.js')) {
return file.slice(0, -4) === distFile.slice(0, -3);
}
});
if (!matchingDistFile) {
this.log(`No matching dist file for ${file}`, {
color: 'red'
});
return Q();
}
return rp({
method: 'POST',
url: `https://app.raygun.io/upload/jssymbols/${this.readConfig('appId')}?authToken=${this.readConfig('token')}`,
formData: {
url: this.readConfig('prefix') + file,
file: fs.createReadStream(path.join(context.project.root, context.distDir, file))
}
});
})
return Q.all(promises);
}
})
.then(() => {
this.log('Raygun updated successfully');
}, (err) => {
this.log('Error setting deployment' + err.message, {
color: 'red'
});
});
});
}
});
return new DeployPlugin();
}
};