Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return function (cz, commit) {
const scope = '@instructure'
const allPackages = getPackages()
const changedPackages = getChangedPackages('--cached', allPackages).map(pkg => pkg.name.replace(`${scope}/`, ''))
const packageNames = allPackages.map(pkg => pkg.name.replace(`${scope}/`, ''))
const questions = makeDefaultQuestions(packageNames, changedPackages)
// eslint-disable-next-line no-console
console.info('\n\nLine 1 will be cropped at 100 characters. All other lines will be wrapped after 100 characters.\n')
cz.registerPrompt('autocomplete', autocomplete)
cz.prompt(autocompleteQuestions(questions))
.then((answers) => {
const {
body,
footer,
...rest
} = answers
async function deprecate (versionToDeprecate, fixVersion, config) {
const message = fixVersion ? `A critical bug was fixed in ${fixVersion}` : ''
createNPMRCFile(config)
info(`📦 Version to deprecate: ${versionToDeprecate}`)
const reply = await confirm('Continue? [y/n]\n')
if (!['Y', 'y'].includes(reply.trim())) {
process.exit(0)
}
return Promise.all(getPackages().map(async pkg => {
if (pkg.private) {
info(`${pkg.name} is private.`)
} else {
const toDeprecate = `${pkg.name}@${versionToDeprecate}`
info(`📦 Deprecating ${toDeprecate}...`)
try {
await runCommandAsync('npm', ['deprecate', toDeprecate, message])
} catch (err) {
error(err)
}
info(`📦 ${toDeprecate} was successfully deprecated!`)
}
}))
}
async function distTag (command, versionToTag, tag, config) {
createNPMRCFile(config)
info(`📦 Version to tag as ${tag}: ${versionToTag}`)
const reply = await confirm('Continue? [y/n]\n')
if (!['Y', 'y'].includes(reply.trim())) {
process.exit(0)
}
return Promise.all(getPackages().map(async pkg => {
if (pkg.private) {
info(`${pkg.name} is private.`)
} else {
const toTag = `${pkg.name}@${versionToTag}`
info(`📦 Running 'dist-tag ${command} ${toTag} ${tag}'...`)
try {
await runCommandAsync('npm', ['dist-tag', command, toTag, tag])
} catch (err) {
error(err)
}
info(`📦 ${toTag} tags were successfully updated!`)
}
}))
}
async function getUsedPackages() {
const usedPackages = (await Promise.all(
getPackages().map(async pkg => {
let packageIsUsed = false
try {
const { stdout } = await runCommandAsync('yarn', ['why', pkg.name, '--cwd', appDir], [], { stdio: 'pipe'})
info(stdout)
packageIsUsed = stdout.includes(' Found')
} catch (err) {
info(`${pkg.name} is not used. ${err}`)
}
if (packageIsUsed) return pkg
})
)).filter(Boolean)
return usedPackages
}