Skip to content

Commit 6023b14

Browse files
committed
feat: return raw nodes from .travis.yml
1 parent 56abd46 commit 6023b14

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ const result = {
6464
// the current time when the result is returned
6565
timestamp: 1577115956099,
6666

67-
// git commit hash of the repository HEAD at the time of scanning
67+
// git commit hash of the repository HEAD at the time of scanning `path` / `repository`
68+
// git commit hash for git tag of the `version` when used with `package`
6869
// will be left out when no git repository detected
6970
commit: "2de28c8c4ab8ac998d403509123736929131908c",
7071

lib/index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
'use strict';
22

3-
module.exports = () => {
3+
const Fs = require('fs');
4+
const Path = require('path');
5+
const Yaml = require('js-yaml');
46

5-
throw new Error('Not implemented');
7+
8+
module.exports.detect = ({ path }) => {
9+
10+
const packageJson = require(Path.join(path, 'package.json'));
11+
12+
const { name, version } = packageJson;
13+
14+
const travisYaml = Yaml.safeLoad(Fs.readFileSync(Path.join(path, '.travis.yml')), { schema: Yaml.FAILSAFE_SCHEMA });
15+
16+
return {
17+
name,
18+
version,
19+
travis: {
20+
raw: travisYaml.node_js
21+
}
22+
};
623
};

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
"@hapi/lab": "^21.0.0",
2222
"allow-scripts": "^1.5.2",
2323
"semantic-release": "^15.14.0"
24+
},
25+
"dependencies": {
26+
"js-yaml": "^3.13.1"
2427
}
2528
}

test/index.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const Path = require('path');
4+
35
const NodeSupport = require('..');
46

57

@@ -8,8 +10,24 @@ const { expect } = require('@hapi/code');
810

911
describe('node-support', () => {
1012

11-
it('is not implemented', () => {
13+
describe('detect()', () => {
14+
15+
describe('path', () => {
16+
17+
it('returns node versions from .travis.yml at the path', async () => {
18+
19+
const path = Path.join(__dirname, '..');
20+
21+
const result = await NodeSupport.detect({ path });
1222

13-
expect(NodeSupport).to.throw('Not implemented');
23+
expect(result).to.equal({
24+
name: 'node-support',
25+
version: '0.0.0-development',
26+
travis: {
27+
raw: ['10', '12', '13']
28+
}
29+
});
30+
});
31+
});
1432
});
1533
});

0 commit comments

Comments
 (0)