Skip to content

Commit ceb1f05

Browse files
committed
feat: add basic cli
1 parent f1b2b2d commit ceb1f05

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

bin/node-support

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
const Fs = require('fs');
6+
const NodeSupport = require('..');
7+
const { URL } = require('url');
8+
9+
10+
const internals = {};
11+
12+
13+
internals.autoDetect = (what) => {
14+
15+
if (!what) {
16+
return NodeSupport.detect({ path: '.' });
17+
}
18+
19+
try {
20+
var url = new URL(what);
21+
}
22+
catch (err) {
23+
if (err.code !== 'ERR_INVALID_URL') {
24+
throw err;
25+
}
26+
}
27+
28+
if (url) {
29+
return NodeSupport.detect({ repository: url.href });
30+
}
31+
32+
if (Fs.existsSync(what)) {
33+
return NodeSupport.detect({ path: what });
34+
}
35+
36+
if (what.includes('/') && !what.startsWith('@')) {
37+
return NodeSupport.detect({ repository: `https://github.com/${what}` });
38+
}
39+
40+
return NodeSupport.detect({ packageName: what });
41+
};
42+
43+
exports.main = async (nodeBin, thisBin, what) => {
44+
45+
const result = await internals.autoDetect(what);
46+
47+
console.log(result);
48+
};
49+
50+
exports.main(...process.argv)
51+
.catch((err) => {
52+
53+
console.error(err);
54+
process.exit(1);
55+
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "List the Node.js versions supported by the package/repository",
55
"main": "lib/index.js",
66
"scripts": {
7+
"test-cli": " while read p; do echo \"./bin/node-support $p\"; ./bin/node-support $p; done < ./test/cli-test.txt",
78
"test": "lab -a @hapi/code -L -p 1 -t 100"
89
},
910
"repository": {

test/cli-test.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
.
3+
node-support
4+
@hapi/hapi
5+
pkgjs/node-support
6+
https://github.com/pkgjs/node-support
7+
git+https://github.com/pkgjs/node-support.git

0 commit comments

Comments
 (0)