-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlib.js
36 lines (29 loc) · 897 Bytes
/
lib.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
const finder = require('find-root')
const path = require('path')
const logger = require('semafor')()
const chalk = require('chalk')
function getScripts (cwd) {
try {
const root = finder(cwd)
const dotJSON = require(path.join(root, 'package.json'))
return dotJSON['scripts']
} catch (e) {
logger.fail(e)
process.exit(1)
}
}
function list (cwd) {
let scripts = getScripts(cwd)
const lengthOfLongestScript = (Object.keys(scripts).sort((a, b) => b.length - a.length)[0]).length
logger.log(chalk.green('Available scripts'))
for (let i in scripts) {
let padding = ''
for (let x = 0; x <= (lengthOfLongestScript - i.length); x++) {
padding += ' '
}
logger.log(` ${chalk.gray('└─')} ${chalk.blue(i)}${padding}${chalk.gray(':')} ${scripts[i]}`)
}
logger.log('\n')
}
module.exports.getScripts = getScripts
module.exports.default = list