-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
index.js
54 lines (42 loc) · 1.21 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
// @ts-check
'use strict';
const gitUsername = require('git-username');
const { MrmError, yaml, markdown, packageJson } = require('mrm-core');
const uploadCommand = 'bash <(curl -s https://codecov.io/bash)';
const coverageScript = 'test:coverage';
function task(config) {
const { readme, github } = config
.defaults({ readmeFile: 'Readme.md', github: gitUsername() })
.require('github')
.values();
const travisYml = yaml('.travis.yml');
// Require .travis.yml
if (!travisYml.exists()) {
throw new MrmError(
`Run travis task first:
mrm travis`
);
}
const pkg = packageJson();
// Require coverage npm script
if (!pkg.getScript(coverageScript)) {
throw new MrmError(
`${coverageScript} npm script not found. To add Jest run:
mrm jest`
);
}
// .travis.yml
if (!travisYml.get('after_success', []).includes(uploadCommand)) {
travisYml
.merge({
script: [`npm run ${coverageScript}`],
after_success: [uploadCommand],
})
.save();
}
// Add Codecov badge to Readme
const url = `https://codecov.io/gh/${github}/${pkg.get('name')}`;
markdown(readme).addBadge(`${url}/branch/master/graph/badge.svg`, url, 'Codecov').save();
}
task.description = 'Adds Codecov';
module.exports = task;