diff --git a/packages/@romejs/cli-reporter/Reporter.ts b/packages/@romejs/cli-reporter/Reporter.ts index a2e8b2e6ae8..a24b175923d 100644 --- a/packages/@romejs/cli-reporter/Reporter.ts +++ b/packages/@romejs/cli-reporter/Reporter.ts @@ -501,7 +501,7 @@ export default class Reporter { ): Promise { const set = await this.select(message, {...arg, radio: true}); - // Should always have at least one elemet + // Should always have at least one element return Array.from(set)[0]; } @@ -527,6 +527,16 @@ export default class Reporter { let prompt = ` ${message}`; this.logAll(prompt); + if (radio) { + this.info( + 'Use arrow keys and then enter to select an option', + ); + } else { + this.info( + 'Use arrow keys and space to select or deselect options and then enter to confirm', + ); + } + const selectedOptions: Set = new Set(defaults); let activeOption = 0; @@ -605,6 +615,10 @@ export default class Reporter { const finish = () => { cleanup(); + // Remove initial help message + this.writeAll(escapes.cursorUp()); + this.writeAll(escapes.eraseLine); + // Remove initial log message this.writeAll(escapes.cursorUp()); this.writeAll(escapes.eraseLine); @@ -651,11 +665,18 @@ export default class Reporter { case 'c': if (key.ctrl) { + this.spacer(); + this.warn('Cancelled by user'); process.exit(1); } return; case 'escape': + this.spacer(); + this.warn('Cancelled by user'); + process.exit(1); + return; + case 'return': finish(); return; diff --git a/packages/@romejs/core/client/commands.ts b/packages/@romejs/core/client/commands.ts index 34257e66d93..549aad19c56 100644 --- a/packages/@romejs/core/client/commands.ts +++ b/packages/@romejs/core/client/commands.ts @@ -13,7 +13,7 @@ import executeMain from '../common/utils/executeMain'; import {createSingleDiagnosticError} from '@romejs/diagnostics'; import {createAbsoluteFilePath} from '@romejs/path'; import {Dict} from '@romejs/typescript-helpers'; -import {writeFile} from '@romejs/fs'; +import {writeFile, exists} from '@romejs/fs'; import {VERSION} from '../common/constants'; export const localCommands: Map> = new Map(); @@ -37,10 +37,18 @@ localCommands.set('init', { const config: Dict = {}; + const configPath = req.client.flags.cwd.append('rome.json'); + if (await exists(configPath)) { + reporter.error( + `rome.json file already exists`, + ); + reporter.info( + 'Use rome config to update an existing config', + ); + return false; + } + reporter.heading('Welcome to Rome!'); - reporter.info( - 'Press space to select an option and enter to confirm', - ); if (flags.defaults === false) { const useDefaults = await reporter.radioConfirm( @@ -67,6 +75,9 @@ localCommands.set('init', { format: { label: 'Format', }, + tests: { + label: 'Testing', + }, }, defaults: ['lint'], }); @@ -76,8 +87,10 @@ localCommands.set('init', { if (enabledComponents.has('format')) { config.format = {enabled: true}; } + if (enabledComponents.has('tests')) { + config.tests = {enabled: true}; + } - const configPath = req.client.flags.cwd.append('rome.json'); await writeFile(configPath, `${JSON.stringify(config, null, ' ')}\n`); reporter.success(