This repository has been archived by the owner on Apr 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
dangerfile.js
65 lines (51 loc) · 1.56 KB
/
dangerfile.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
const { message, danger } = require('danger');
const { exec } = require('shelljs');
const R = require('ramda');
const STDOUT = R.lensProp('stdout');
const NAME = 'styled-material-components';
const PR_URL = /https:\/\/styled-material-components-(?:[^-]*)-([^.]+)\.now\.sh/;
const getDeployUrl = R.compose(
R.head,
R.match(PR_URL),
R.view(STDOUT),
targetApp => exec(`yarn now -n ${targetApp} -d docs/ -t ${process.env.NOW_TOKEN}`),
);
const branch = process.env.CIRCLE_BRANCH || danger.github.pr.head.label;
const appName = branch === 'master' ? NAME : `${NAME}-pr-${danger.github.pr.number || 0}`;
// Get the modified components in the PR
const getModifiedComponents = R.compose(
R.uniq,
R.map(
R.compose(
R.replace('.js', ''),
R.nth(1),
R.match(/\/components\/([^/]+)/)
),
),
R.filter(R.test(/\/components\//))
);
const modifiedComponents = getModifiedComponents(danger.git.modified_files);
// Build the app
exec('yarn export');
// Deploy the app
const deployURL = getDeployUrl(appName);
let link = `https://${appName}.now.sh`;
// Alias the link
if (branch === 'master') {
exec(`yarn now alias ${deployURL} styled-material-components.com -t ${process.env.NOW_TOKEN}`);
link = 'https://styled-material-components.com';
} else {
exec(`yarn now alias ${deployURL} ${appName} -t ${process.env.NOW_TOKEN}`);
}
let markdown = '';
if (modifiedComponents.length > 0) {
markdown += `
### Modified Components
* ${modifiedComponents.join('\n * ')}
`;
}
markdown += `
### PR Application
* [${appName}](${link})
`;
message(markdown);