-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(npm): Adding script to unpublish package versions (#2964)
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const { execSync } = require('child_process'); | ||
const minimist = require('minimist'); | ||
const axios = require('axios'); | ||
|
||
const excludedPackages = [ | ||
'@ec-europa/ecl-dialogs', | ||
'@hpcc-js/eclwatch', | ||
'@eui/ecl-styles', | ||
'snomed-ecl-builder', | ||
'@eui/ecl', | ||
'@eui/ecl-core', | ||
]; | ||
|
||
async function fetchPackageNames(scope) { | ||
try { | ||
const response = await axios.get( | ||
`https://registry.npmjs.org/-/v1/search?text=${scope}/&size=250`, | ||
); | ||
return response.data.objects | ||
.filter((pkg) => !excludedPackages.includes(pkg.package.name)) | ||
.map((pkg) => pkg.package.name); | ||
} catch (error) { | ||
console.error( | ||
'Error occurred while fetching package names:', | ||
error.message, | ||
); | ||
return []; | ||
} | ||
} | ||
|
||
async function unpublishPackages(scope, version, dryRun = true) { | ||
console.log( | ||
`Running npm unpublish ${dryRun ? 'with dry-run option...' : '...'} `, | ||
); | ||
const packageNames = await fetchPackageNames(scope); | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const packageName of packageNames) { | ||
const npmUnpublishCommand = `npm unpublish ${packageName}@${version}${ | ||
dryRun ? ' --dry-run' : '' | ||
}`; | ||
if (dryRun) { | ||
console.log(`[Dry Run] Would have run: ${npmUnpublishCommand}`); | ||
} else { | ||
console.log(`Unpublishing ${packageName} @${version}`); | ||
execSync(npmUnpublishCommand); | ||
} | ||
} | ||
} | ||
|
||
function printUsage() { | ||
console.log( | ||
'Usage: node unpublish.js --scope <scope> --version <version> [--dry-run]', | ||
); | ||
} | ||
|
||
const args = minimist(process.argv.slice(2), { | ||
string: ['scope', 'version'], | ||
boolean: ['dry-run'], | ||
alias: { s: 'scope', v: 'version', d: 'dry-run' }, | ||
}); | ||
|
||
if (!args.scope || !args.version) { | ||
printUsage(); | ||
process.exit(1); | ||
} | ||
|
||
unpublishPackages(args.scope, args.version, args['dry-run']); |
8623368
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Deployed on https://v3-dev--europa-component-library.netlify.app