diff --git a/.eslintrc.cjs b/.eslintrc.cjs index f8cf0f0a8..29e8f4633 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -18,6 +18,7 @@ module.exports = { '**/dist/*', '**/coverage/**', '**/node_modules/**', + '**/release/**', // ESLint does not understand `import ... with { ... }`. // See: https://github.com/eslint/eslint/discussions/15305. diff --git a/package.json b/package.json index 21acee2ff..a0c3ff283 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,8 @@ "@ckeditor/ckeditor5-dev-ci": "^44.0.0", "@ckeditor/ckeditor5-dev-release-tools": "^44.0.0", "@ckeditor/ckeditor5-dev-bump-year": "^44.0.0", + "@inquirer/prompts": "^6.0.0", + "@listr2/prompt-adapter-inquirer": "^2.0.16", "eslint": "^8.21.0", "eslint-config-ckeditor5": "^7.0.0", "fs-extra": "^11.0.0", diff --git a/scripts/preparepackages.js b/scripts/preparepackages.js index a6607c080..6aeea866e 100644 --- a/scripts/preparepackages.js +++ b/scripts/preparepackages.js @@ -8,7 +8,10 @@ /* eslint-env node */ import upath from 'upath'; +import fs from 'fs-extra'; import { Listr } from 'listr2'; +import { ListrInquirerPromptAdapter } from '@listr2/prompt-adapter-inquirer'; +import { confirm } from '@inquirer/prompts'; import { globSync } from 'glob'; import * as releaseTools from '@ckeditor/ckeditor5-dev-release-tools'; import parseArguments from './utils/parsearguments.js'; @@ -48,6 +51,38 @@ const tasks = new Listr( [ return false; } }, + { + title: 'Check the release directory.', + task: async ( ctx, task ) => { + const isAvailable = await fs.exists( RELEASE_DIRECTORY ); + + if ( !isAvailable ) { + return fs.ensureDir( RELEASE_DIRECTORY ); + } + + const isEmpty = ( await fs.readdir( RELEASE_DIRECTORY ) ).length === 0; + + if ( isEmpty ) { + return Promise.resolve(); + } + + // Do not ask when running on CI. + if ( cliArguments.ci ) { + return fs.emptyDir( RELEASE_DIRECTORY ); + } + + const shouldContinue = await task.prompt( ListrInquirerPromptAdapter ) + .run( confirm, { + message: 'The release directory must be empty. Continue and remove all files?' + } ); + + if ( !shouldContinue ) { + return Promise.reject( 'Aborting as requested.' ); + } + + return fs.emptyDir( RELEASE_DIRECTORY ); + } + }, { title: 'Updating the `#version` field.', task: () => { diff --git a/scripts/publishpackages.js b/scripts/publishpackages.js index 75fa01eaa..d7439bc3e 100644 --- a/scripts/publishpackages.js +++ b/scripts/publishpackages.js @@ -8,6 +8,8 @@ /* eslint-env node */ import { Listr } from 'listr2'; +import { ListrInquirerPromptAdapter } from '@listr2/prompt-adapter-inquirer'; +import { confirm } from '@inquirer/prompts'; import * as releaseTools from '@ckeditor/ckeditor5-dev-release-tools'; import parseArguments from './utils/parsearguments.js'; import getListrOptions from './utils/getlistroptions.js'; @@ -37,7 +39,8 @@ const tasks = new Listr( [ return true; } - return task.prompt( { type: 'Confirm', message: 'Do you want to continue?' } ); + return task.prompt( ListrInquirerPromptAdapter ) + .run( confirm, { message: 'Do you want to continue?' } ); } } ); },