Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib/node_mod.../npm/lib
File: team.js
/* eslint-disable standard/no-callback-literal */
[0] Fix | Delete
[1] Fix | Delete
const columns = require('cli-columns')
[2] Fix | Delete
const figgyPudding = require('figgy-pudding')
[3] Fix | Delete
const libteam = require('libnpm/team')
[4] Fix | Delete
const npmConfig = require('./config/figgy-config.js')
[5] Fix | Delete
const output = require('./utils/output.js')
[6] Fix | Delete
const otplease = require('./utils/otplease.js')
[7] Fix | Delete
const usage = require('./utils/usage')
[8] Fix | Delete
[9] Fix | Delete
module.exports = team
[10] Fix | Delete
[11] Fix | Delete
team.subcommands = ['create', 'destroy', 'add', 'rm', 'ls', 'edit']
[12] Fix | Delete
[13] Fix | Delete
team.usage = usage(
[14] Fix | Delete
'team',
[15] Fix | Delete
'npm team create <scope:team> [--otp <otpcode>]\n' +
[16] Fix | Delete
'npm team destroy <scope:team> [--otp <otpcode>]\n' +
[17] Fix | Delete
'npm team add <scope:team> <user> [--otp <otpcode>]\n' +
[18] Fix | Delete
'npm team rm <scope:team> <user> [--otp <otpcode>]\n' +
[19] Fix | Delete
'npm team ls <scope>|<scope:team>\n' +
[20] Fix | Delete
'npm team edit <scope:team>'
[21] Fix | Delete
)
[22] Fix | Delete
[23] Fix | Delete
const TeamConfig = figgyPudding({
[24] Fix | Delete
json: {},
[25] Fix | Delete
loglevel: {},
[26] Fix | Delete
parseable: {},
[27] Fix | Delete
silent: {}
[28] Fix | Delete
})
[29] Fix | Delete
[30] Fix | Delete
function UsageError () {
[31] Fix | Delete
throw Object.assign(new Error(team.usage), {code: 'EUSAGE'})
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
team.completion = function (opts, cb) {
[35] Fix | Delete
var argv = opts.conf.argv.remain
[36] Fix | Delete
if (argv.length === 2) {
[37] Fix | Delete
return cb(null, team.subcommands)
[38] Fix | Delete
}
[39] Fix | Delete
switch (argv[2]) {
[40] Fix | Delete
case 'ls':
[41] Fix | Delete
case 'create':
[42] Fix | Delete
case 'destroy':
[43] Fix | Delete
case 'add':
[44] Fix | Delete
case 'rm':
[45] Fix | Delete
case 'edit':
[46] Fix | Delete
return cb(null, [])
[47] Fix | Delete
default:
[48] Fix | Delete
return cb(new Error(argv[2] + ' not recognized'))
[49] Fix | Delete
}
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
function team ([cmd, entity = '', user = ''], cb) {
[53] Fix | Delete
// Entities are in the format <scope>:<team>
[54] Fix | Delete
otplease(npmConfig(), opts => {
[55] Fix | Delete
opts = TeamConfig(opts).concat({description: null})
[56] Fix | Delete
entity = entity.replace(/^@/, '')
[57] Fix | Delete
switch (cmd) {
[58] Fix | Delete
case 'create': return teamCreate(entity, opts)
[59] Fix | Delete
case 'destroy': return teamDestroy(entity, opts)
[60] Fix | Delete
case 'add': return teamAdd(entity, user, opts)
[61] Fix | Delete
case 'rm': return teamRm(entity, user, opts)
[62] Fix | Delete
case 'ls': {
[63] Fix | Delete
const match = entity.match(/[^:]+:.+/)
[64] Fix | Delete
if (match) {
[65] Fix | Delete
return teamListUsers(entity, opts)
[66] Fix | Delete
} else {
[67] Fix | Delete
return teamListTeams(entity, opts)
[68] Fix | Delete
}
[69] Fix | Delete
}
[70] Fix | Delete
case 'edit':
[71] Fix | Delete
throw new Error('`npm team edit` is not implemented yet.')
[72] Fix | Delete
default:
[73] Fix | Delete
UsageError()
[74] Fix | Delete
}
[75] Fix | Delete
}).then(
[76] Fix | Delete
data => cb(null, data),
[77] Fix | Delete
err => err.code === 'EUSAGE' ? cb(err.message) : cb(err)
[78] Fix | Delete
)
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
function teamCreate (entity, opts) {
[82] Fix | Delete
return libteam.create(entity, opts).then(() => {
[83] Fix | Delete
if (opts.json) {
[84] Fix | Delete
output(JSON.stringify({
[85] Fix | Delete
created: true,
[86] Fix | Delete
team: entity
[87] Fix | Delete
}))
[88] Fix | Delete
} else if (opts.parseable) {
[89] Fix | Delete
output(`${entity}\tcreated`)
[90] Fix | Delete
} else if (!opts.silent && opts.loglevel !== 'silent') {
[91] Fix | Delete
output(`+@${entity}`)
[92] Fix | Delete
}
[93] Fix | Delete
})
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
function teamDestroy (entity, opts) {
[97] Fix | Delete
return libteam.destroy(entity, opts).then(() => {
[98] Fix | Delete
if (opts.json) {
[99] Fix | Delete
output(JSON.stringify({
[100] Fix | Delete
deleted: true,
[101] Fix | Delete
team: entity
[102] Fix | Delete
}))
[103] Fix | Delete
} else if (opts.parseable) {
[104] Fix | Delete
output(`${entity}\tdeleted`)
[105] Fix | Delete
} else if (!opts.silent && opts.loglevel !== 'silent') {
[106] Fix | Delete
output(`-@${entity}`)
[107] Fix | Delete
}
[108] Fix | Delete
})
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
function teamAdd (entity, user, opts) {
[112] Fix | Delete
return libteam.add(user, entity, opts).then(() => {
[113] Fix | Delete
if (opts.json) {
[114] Fix | Delete
output(JSON.stringify({
[115] Fix | Delete
added: true,
[116] Fix | Delete
team: entity,
[117] Fix | Delete
user
[118] Fix | Delete
}))
[119] Fix | Delete
} else if (opts.parseable) {
[120] Fix | Delete
output(`${user}\t${entity}\tadded`)
[121] Fix | Delete
} else if (!opts.silent && opts.loglevel !== 'silent') {
[122] Fix | Delete
output(`${user} added to @${entity}`)
[123] Fix | Delete
}
[124] Fix | Delete
})
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
function teamRm (entity, user, opts) {
[128] Fix | Delete
return libteam.rm(user, entity, opts).then(() => {
[129] Fix | Delete
if (opts.json) {
[130] Fix | Delete
output(JSON.stringify({
[131] Fix | Delete
removed: true,
[132] Fix | Delete
team: entity,
[133] Fix | Delete
user
[134] Fix | Delete
}))
[135] Fix | Delete
} else if (opts.parseable) {
[136] Fix | Delete
output(`${user}\t${entity}\tremoved`)
[137] Fix | Delete
} else if (!opts.silent && opts.loglevel !== 'silent') {
[138] Fix | Delete
output(`${user} removed from @${entity}`)
[139] Fix | Delete
}
[140] Fix | Delete
})
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
function teamListUsers (entity, opts) {
[144] Fix | Delete
return libteam.lsUsers(entity, opts).then(users => {
[145] Fix | Delete
users = users.sort()
[146] Fix | Delete
if (opts.json) {
[147] Fix | Delete
output(JSON.stringify(users, null, 2))
[148] Fix | Delete
} else if (opts.parseable) {
[149] Fix | Delete
output(users.join('\n'))
[150] Fix | Delete
} else if (!opts.silent && opts.loglevel !== 'silent') {
[151] Fix | Delete
output(`\n@${entity} has ${users.length} user${users.length === 1 ? '' : 's'}:\n`)
[152] Fix | Delete
output(columns(users, {padding: 1}))
[153] Fix | Delete
}
[154] Fix | Delete
})
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
function teamListTeams (entity, opts) {
[158] Fix | Delete
return libteam.lsTeams(entity, opts).then(teams => {
[159] Fix | Delete
teams = teams.sort()
[160] Fix | Delete
if (opts.json) {
[161] Fix | Delete
output(JSON.stringify(teams, null, 2))
[162] Fix | Delete
} else if (opts.parseable) {
[163] Fix | Delete
output(teams.join('\n'))
[164] Fix | Delete
} else if (!opts.silent && opts.loglevel !== 'silent') {
[165] Fix | Delete
output(`\n@${entity} has ${teams.length} team${teams.length === 1 ? '' : 's'}:\n`)
[166] Fix | Delete
output(columns(teams.map(t => `@${t}`), {padding: 1}))
[167] Fix | Delete
}
[168] Fix | Delete
})
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function