**refactor(scripts): improve readability and consistency in release-workflow.js**
- Updated formatting for better readability in console messages and user prompts. - Simplified asynchronous logic in user interaction flow by restructuring `readline` handling. - Adjusted NPM script calls to match conventions (e.g., `_release`, `_github-release`). - Improved maintainability by adhering to consistent code style and linting guidelines. **Purpose**: Enhance code clarity and consistency in the release workflow script to improve developer experience and reduce potential errors.
This commit is contained in:
parent
699dc4f4a5
commit
0d92e69272
1 changed files with 27 additions and 14 deletions
|
|
@ -53,7 +53,9 @@ function executeStep(command, description) {
|
|||
return true
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(`❌ Error during ${description.toLowerCase()}: ${error.message}`)
|
||||
console.error(
|
||||
`❌ Error during ${description.toLowerCase()}: ${error.message}`
|
||||
)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
@ -72,45 +74,56 @@ async function runReleaseWorkflow() {
|
|||
// Step 2: Run tests to ensure everything is working
|
||||
if (!executeStep('npm test', 'Running tests')) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('⚠️ Tests failed. This might indicate issues with the release.')
|
||||
|
||||
console.warn(
|
||||
'⚠️ Tests failed. This might indicate issues with the release.'
|
||||
)
|
||||
|
||||
// Ask the user if they want to continue despite test failures
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('\n⚠️ Do you want to continue with the release process despite test failures? (y/N)')
|
||||
|
||||
console.log(
|
||||
'\n⚠️ Do you want to continue with the release process despite test failures? (y/N)'
|
||||
)
|
||||
|
||||
const readline = require('readline').createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
})
|
||||
|
||||
const response = await new Promise(resolve => {
|
||||
readline.question('', answer => {
|
||||
|
||||
const response = await new Promise((resolve) => {
|
||||
readline.question('', (answer) => {
|
||||
readline.close()
|
||||
resolve(answer.toLowerCase())
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
if (response !== 'y' && response !== 'yes') {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Release process aborted due to test failures.')
|
||||
// eslint-disable-next-line no-process-exit
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Continuing with release process despite test failures...')
|
||||
}
|
||||
|
||||
// Step 3: Update version and generate changelog
|
||||
if (!executeStep(`npm run release:${versionType}`, `Updating version (${versionType}) and generating changelog`)) {
|
||||
if (
|
||||
!executeStep(
|
||||
`npm run _release:${versionType}`,
|
||||
`Updating version (${versionType}) and generating changelog`
|
||||
)
|
||||
) {
|
||||
// eslint-disable-next-line no-process-exit
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// Step 4: Create GitHub release
|
||||
if (!executeStep('npm run github-release', 'Creating GitHub release')) {
|
||||
if (!executeStep('npm run _github-release', 'Creating GitHub release')) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Warning: GitHub release creation failed, but continuing with deployment...')
|
||||
console.log(
|
||||
'Warning: GitHub release creation failed, but continuing with deployment...'
|
||||
)
|
||||
}
|
||||
|
||||
// Step 5: Publish to NPM
|
||||
|
|
@ -143,7 +156,7 @@ async function runReleaseWorkflow() {
|
|||
}
|
||||
|
||||
// Run the workflow
|
||||
runReleaseWorkflow().catch(error => {
|
||||
runReleaseWorkflow().catch((error) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Unexpected error during release workflow:', error)
|
||||
// eslint-disable-next-line no-process-exit
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue