This repository has been archived by the owner on Jul 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
access.jsx
107 lines (92 loc) · 2.74 KB
/
access.jsx
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict'
const figgyPudding = require('figgy-pudding')
const libnpm = require('libnpm')
const ConfigOpts = figgyPudding({
entity: {},
json: {},
loglevel: {},
parseable: {},
permissions: {},
silent: {},
spec: {},
team: {},
user: {}
})
const render = (opts, content = {}) => {
const { h, renderToString } = require('ink') // eslint-disable-line
const Table = require('ink-table').default
if (opts.json) {
console.log(JSON.stringify(content, null, 2))
} else if (opts.parseable) {
console.log(['collaborator', 'access'].join('\t'))
Object.keys(content).forEach(collab => {
console.log([collab, content[collab]].join('\t'))
})
} else if (!opts.silent && opts.loglevel !== 'silent') {
const data = Object.keys(content).map(collab => {
return { collab, role: content[collab] }
})
console.log(renderToString(<Table data={data} />))
}
}
module.exports.public = accessPublic
async function accessPublic (argv, opts) {
opts = ConfigOpts(opts)
await libnpm.access.public(opts.spec, opts)
}
module.exports.restricted = accessRestricted
async function accessRestricted (argv, opts) {
opts = ConfigOpts(opts)
await libnpm.access.restricted(opts.spec, opts)
}
module.exports.grant = accessGrant
async function accessGrant (argv, opts) {
opts = ConfigOpts(opts)
await access.grant(opts.spec, opts.team, opts.permissions, opts) // eslint-disable-line
}
module.exports.revoke = accessRevoke
async function accessRevoke (argv, opts) {
opts = ConfigOpts(opts)
await libnpm.access.revoke(opts.spec, opts.team, opts)
}
module.exports.lsPackages = accessLsPackages
async function accessLsPackages (argv, opts) {
opts = ConfigOpts(opts)
const getPackagesByCurrentUser = async () => {
const whoami = require('./whoami.js')
return whoami([], opts.concat({ silent: true }))
}
const entity = opts.entity
? opts.entity
: await getPackagesByCurrentUser()
const packages =
await libnpm.access.lsPackages(entity, opts)
render(opts, packages)
}
module.exports.lsCollaborators = accessLsCollaborators
async function accessLsCollaborators (argv, opts) {
opts = ConfigOpts(opts)
if (opts.spec) {
const collaborators =
await libnpm.access.lsCollaborators(opts.spec, opts.user, opts)
render(opts, collaborators)
} else {
const prefix = await libnpm.getPrefix(process.cwd())
if (prefix) {
const data = await libnpm.readJSON(
`${prefix}/package.json`,
console.error,
false
)
if (data) {
const collaborators =
await libnpm.access.lsCollaborators(data.name, opts.user, opts)
render(opts, collaborators)
}
}
}
}
module.exports.edit = accessEdit
async function accessEdit (argv, opts) {
// TODO: stub
}