-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·35 lines (28 loc) · 869 Bytes
/
Copy pathindex.js
File metadata and controls
executable file
·35 lines (28 loc) · 869 Bytes
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
#! /usr/bin/env node
'use strict'
const {join} = require('path')
const process = require('process')
const yaml = require('js-yaml')
const {getOwnPropertyDescriptor} = Object
const {exit, argv} = process
const {info, error} = global.console
const success = message => {
info(message)
exit(0)
}
const failure = (message, code = 1) => {
error(message)
exit(code)
}
const getprop = (object, property) => {
if (object === undefined || object === null) return undefined
const descriptor = getOwnPropertyDescriptor(object, property)
if (!descriptor) return undefined
return descriptor.value
}
const dump = x =>
typeof x === 'object' && x ? yaml.dump(x) : String(x)
const [mdlname, ...field] = argv.slice(2)
mdlname || failure('Missing argument')
const pkgobject = require(join(mdlname, 'package.json'))
success(dump(field.reduce(getprop, pkgobject)))