Skip to content

Commit

Permalink
Project update. [p][robotic]
Browse files Browse the repository at this point in the history
  • Loading branch information
jaswrks committed Jan 25, 2023
1 parent beeacc7 commit 775cf6c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
24 changes: 17 additions & 7 deletions dev/.files/bin/includes/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,12 @@ export default class u {
}

static async isNPMPkgRegistry(registry) {
return registry.replace(/\/+$/, '') === String(await u.spawn('npm', ['config', 'get', 'registry'], { quiet: true })).replace(/\/+$/, '');
return (
registry.replace(/\/+$/, '') ===
String(await u.spawn('npm', ['config', 'get', 'registry'], { quiet: true }))
.trim()
.replace(/\/+$/, '')
);
}

static async isNPMPkgPublishable(opts = { mode: 'prod' }) {
Expand Down Expand Up @@ -922,20 +927,22 @@ export default class u {
}
log(chalk.gray('Configuring npmjs package using org-wide standards.'));

const alwaysOnRequiredTeams = { developers: 'read-write', owners: 'read-write', 'security-managers': 'read-only' }; // No exceptions.
let teams = Object.assign({}, _.get(pkg, 'config.c10n.&.npmjs.teams', _.get(pkg, 'config.c10n.&.github.teams', {})), alwaysOnRequiredTeams);
teams = Object.keys(teams).forEach((team) => (teams[team] = /^(?:read-write|push|maintain|admin)$/iu.test(teams[team]) ? 'read-write' : 'read-only'));
const teamsToDelete = await u._npmjsOrgTeams(org); // Current list of organization’s teams.
const alwaysOnRequiredTeams = { developers: 'read-write', owners: 'read-write', 'security-managers': 'read-only' }; // No exceptions.

const teams = Object.assign({}, _.get(pkg, 'config.c10n.&.npmjs.teams', _.get(pkg, 'config.c10n.&.github.teams', {})), alwaysOnRequiredTeams);
Object.keys(teams).forEach((team) => (teams[team] = /^(?:read-write|push|maintain|admin)$/iu.test(teams[team]) ? 'read-write' : 'read-only'));

for (const [team, permission] of Object.entries(teams)) {
delete teamsToDelete[team]; // Don't delete.

log(chalk.gray('Adding `' + team + '` team to npmjs package with `' + permission + '` permission.'));
if (!opts.dryRun) {
await u.spawn('npm', ['access', 'grant', permission, org + ':' + team], { quiet: true });
}
}
for (const [team, teamData] of Object.entries(teamsToDelete)) {
log(chalk.gray('Deleting `' + team + '` (unused) with `' + teamData.permission + '` permission from npmjs package.'));
for (const [team] of Object.entries(teamsToDelete)) {
log(chalk.gray('Deleting `' + team + '` (unused) from npmjs package.'));
if (!opts.dryRun) {
await u.spawn('npm', ['access', 'revoke', org + ':' + team], { quiet: true }).catch(() => null);
}
Expand Down Expand Up @@ -970,7 +977,10 @@ export default class u {
if (!(teams instanceof Array)) {
throw new Error('u._npmjsOrgTeams: Failed to acquire list of NPM teams for `' + org + '` org.');
}
return teams.map((team) => team.replace(/^[^:]+:/u, '')); // Array of team slugs.
return teams.reduce((o, team) => {
o[team.replace(/^[^:]+:/u, '')] = team;
return o; // Object return.
}, {});
}

/*
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publishConfig": {
"access": "restricted"
},
"version": "1.0.68",
"version": "1.0.71",
"license": "GPL-3.0-or-later",
"name": "@clevercanyon/utilities",
"description": "Another great project by Clever Canyon.",
Expand Down Expand Up @@ -135,7 +135,9 @@
},
"configVersion": "1.0.0"
},
"npmjs": {}
"npmjs": {
"configVersions": "1.0.0,1.0.0"
}
}
}
}
Expand Down

0 comments on commit 775cf6c

Please sign in to comment.