Skip to content

Commit 03c5d93

Browse files
committed
[tools][s]: a function to check if data-cli was installed via NPM - refs #321
1 parent 6c5c166 commit 03c5d93

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/utils/tools.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const marked = require('marked')
33
const TerminalRenderer = require('marked-terminal')
44
// ProgressBar
55
const ProgressBar = require('progress')
6+
// Global packages
7+
const globalPackages = require('global-packages')
68

79
const {elephant} = require('./logo')
810

@@ -19,3 +21,31 @@ const bar = new ProgressBar(':download [:bar] :percent :etas', {
1921
total: 100
2022
})
2123
module.exports.bar = bar
24+
25+
const installedWithNPM = async () => {
26+
let packages
27+
28+
try {
29+
packages = await globalPackages()
30+
} catch (err) {
31+
console.log(err)
32+
return false
33+
}
34+
35+
if (!Array.isArray(packages)) {
36+
return false
37+
}
38+
39+
const related = packages.find(item => item.name === 'now')
40+
41+
if (!related || related.linked === true) {
42+
return false
43+
}
44+
45+
if (related.linked === false) {
46+
return true
47+
}
48+
49+
return false
50+
}
51+
module.exports.installedWithNPM = installedWithNPM

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"clipboardy": "^1.1.4",
7575
"data.js": "^0.11.1",
7676
"datahub-client": "^0.4.2",
77+
"global-packages": "^1.0.2",
7778
"human-readable-ids": "^1.0.3",
7879
"inquirer": "^5.1.0",
7980
"inquirer-test": "^2.0.1",

0 commit comments

Comments
 (0)