11'use strict'
22
3- const Access = module . exports = {
4- command : 'access' ,
5- describe : 'access-related subcommands' ,
6- builder ( y ) {
7- return y . help ( ) . alias ( 'help' , 'h' )
8- . options ( Access . options )
9- . demandCommand ( 1 , 'Access subcommand is required' )
10- . recommendCommands ( )
11- . command (
12- 'public <spec>' ,
13- 'Set a package to be publicly accessible' ,
14- Access . options ,
15- async argv => accessPublic ( argv )
16- )
17- . command (
18- 'restricted <spec>' ,
19- 'Set a package to be restricted' ,
20- Access . options ,
21- async argv => accessRestricted ( argv )
22- )
23- . command (
24- 'grant <permissions> <team> <spec>' ,
25- 'Add the ability of users and teams to have read-only or ' +
26- 'read-write access to a package' ,
27- Access . options ,
28- async argv => accessGrant ( argv )
29- )
30- . command (
31- 'revoke <team> <spec>' ,
32- 'Remove the ability of users and teams to have read-only or ' +
33- 'read-write access to a package' ,
34- Access . options ,
35- async argv => accessRevoke ( argv )
36- )
37- . command (
38- 'ls-packages [<entity>]' ,
39- 'Show all of the packages a user or a team is able to access, along ' +
40- 'with the access level, except for read-only public packages' ,
41- Access . options ,
42- async argv => accessLsPackages ( argv )
43- )
44- . command (
45- 'ls-collaborators [<spec> [<user>]]' ,
46- 'Show all of the access privileges for a package. Will only show ' +
47- 'permissions for packages to which you have at least read access. ' +
48- 'If <user> is passed in, the list is filtered only to teams that ' +
49- 'user happens to belong to' ,
50- Access . options ,
51- async argv => accessLsCollaborators ( argv )
52- )
53- . command (
54- 'edit <package>' ,
55- 'Set the access privileges for a package at once using $EDITOR' ,
56- Access . options ,
57- async argv => accessEdit ( argv )
58- )
59- } ,
60- options : Object . assign ( require ( '../common-opts.js' , { } ) )
61- }
62-
633const figgyPudding = require ( 'figgy-pudding' )
64- const npmConfig = require ( '../config.js' )
654const libnpm = require ( 'libnpm' )
665
67- const Config = figgyPudding ( {
6+ const ConfigOpts = figgyPudding ( {
7+ entity : { } ,
688 json : { } ,
699 loglevel : { } ,
7010 parseable : { } ,
71- silent : { }
11+ permissions : { } ,
12+ silent : { } ,
13+ spec : { } ,
14+ team : { } ,
15+ user : { }
7216} )
7317
74- const parseOpts = argv => Config ( npmConfig ( argv ) )
75-
7618const render = ( opts , content = { } ) => {
7719 const { h, renderToString } = require ( 'ink' ) // eslint-disable-line
7820 const Table = require ( 'ink-table' ) . default
@@ -92,45 +34,54 @@ const render = (opts, content = {}) => {
9234 }
9335}
9436
95- async function accessPublic ( argv ) {
96- await libnpm . access . public ( argv . spec , parseOpts ( argv ) )
37+ module . exports . public = accessPublic
38+ async function accessPublic ( argv , opts ) {
39+ opts = ConfigOpts ( opts )
40+ await libnpm . access . public ( opts . spec , opts )
9741}
9842
99- async function accessRestricted ( argv ) {
100- await libnpm . access . restricted ( argv . spec , parseOpts ( argv ) )
43+ module . exports . restricted = accessRestricted
44+ async function accessRestricted ( argv , opts ) {
45+ opts = ConfigOpts ( opts )
46+ await libnpm . access . restricted ( opts . spec , opts )
10147}
10248
103- async function accessGrant ( argv ) {
104- await access . grant ( argv . spec , argv . team , argv . permissions , parseOpts ( argv ) ) // eslint-disable-line
49+ module . exports . grant = accessGrant
50+ async function accessGrant ( argv , opts ) {
51+ opts = ConfigOpts ( opts )
52+ await access . grant ( opts . spec , opts . team , opts . permissions , opts ) // eslint-disable-line
10553}
10654
107- async function accessRevoke ( argv ) {
108- await libnpm . access . revoke ( argv . spec , argv . team , parseOpts ( argv ) )
55+ module . exports . revoke = accessRevoke
56+ async function accessRevoke ( argv , opts ) {
57+ opts = ConfigOpts ( opts )
58+ await libnpm . access . revoke ( opts . spec , opts . team , opts )
10959}
11060
111- async function accessLsPackages ( argv ) {
61+ module . exports . lsPackages = accessLsPackages
62+ async function accessLsPackages ( argv , opts ) {
63+ opts = ConfigOpts ( opts )
11264 const getPackagesByCurrentUser = async ( ) => {
113- const whoami = require ( './whoami' )
114- return whoami . handler ( parseOpts ( argv ) . concat ( { silent : true } ) )
65+ const whoami = require ( './whoami.js ' )
66+ return whoami ( [ ] , opts . concat ( { silent : true } ) )
11567 }
11668
117- const entity = argv . entity
118- ? argv . entity
69+ const entity = opts . entity
70+ ? opts . entity
11971 : await getPackagesByCurrentUser ( )
12072
121- const opts = parseOpts ( argv )
122- // TODO: error when opts is used as 2nd param in .lsPackages
12373 const packages =
124- await libnpm . access . lsPackages ( entity )
74+ await libnpm . access . lsPackages ( entity , opts )
12575 render ( opts , packages )
12676}
12777
128- async function accessLsCollaborators ( argv ) {
129- const opts = parseOpts ( argv )
78+ module . exports . lsCollaborators = accessLsCollaborators
79+ async function accessLsCollaborators ( argv , opts ) {
80+ opts = ConfigOpts ( opts )
13081
131- if ( argv . spec ) {
82+ if ( opts . spec ) {
13283 const collaborators =
133- await libnpm . access . lsCollaborators ( argv . spec , argv . user , opts )
84+ await libnpm . access . lsCollaborators ( opts . spec , opts . user , opts )
13485 render ( opts , collaborators )
13586 } else {
13687 const prefix = await libnpm . getPrefix ( process . cwd ( ) )
@@ -143,13 +94,14 @@ async function accessLsCollaborators (argv) {
14394
14495 if ( data ) {
14596 const collaborators =
146- await libnpm . access . lsCollaborators ( data . name , argv . user , opts )
97+ await libnpm . access . lsCollaborators ( data . name , opts . user , opts )
14798 render ( opts , collaborators )
14899 }
149100 }
150101 }
151102}
152103
153- async function accessEdit ( argv ) {
104+ module . exports . edit = accessEdit
105+ async function accessEdit ( argv , opts ) {
154106 // TODO: stub
155107}
0 commit comments