From c6728bfb30f3a63b1ebce8ed1c3ab160a398c02d Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Mon, 9 Mar 2020 20:15:45 -0700 Subject: [PATCH 1/2] cli-reporter: Add informative prompts for key usage on all select calls cli-reporter: In select, when pressing escape, kill the process cli-reporter: In select, when we kill the process, also output a warning message local init command: Add support for tests component local init command: Error when a project already exists in the cwd --- packages/@romejs/cli-reporter/Reporter.ts | 21 ++++++++++++++++++++- packages/@romejs/core/client/commands.ts | 23 ++++++++++++++++++----- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/packages/@romejs/cli-reporter/Reporter.ts b/packages/@romejs/cli-reporter/Reporter.ts index a2e8b2e6ae8..7b14c4eafd6 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,16 @@ export default class Reporter { case 'c': if (key.ctrl) { + this.warn('Cancelled by user'); process.exit(1); } return; case 'escape': + 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..b1f277d8a00 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( From 1a7f69c4abd84b3a0d6985ad74a93a47f01a11b7 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 10 Mar 2020 13:53:22 -0700 Subject: [PATCH 2/2] cli-reporter: Fix tag, add spacer before "canceled by user" message" --- packages/@romejs/cli-reporter/Reporter.ts | 2 ++ packages/@romejs/core/client/commands.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/@romejs/cli-reporter/Reporter.ts b/packages/@romejs/cli-reporter/Reporter.ts index 7b14c4eafd6..a24b175923d 100644 --- a/packages/@romejs/cli-reporter/Reporter.ts +++ b/packages/@romejs/cli-reporter/Reporter.ts @@ -665,12 +665,14 @@ 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; diff --git a/packages/@romejs/core/client/commands.ts b/packages/@romejs/core/client/commands.ts index b1f277d8a00..549aad19c56 100644 --- a/packages/@romejs/core/client/commands.ts +++ b/packages/@romejs/core/client/commands.ts @@ -40,7 +40,7 @@ localCommands.set('init', { const configPath = req.client.flags.cwd.append('rome.json'); if (await exists(configPath)) { reporter.error( - `rome.json file already exists`, + `rome.json file already exists`, ); reporter.info( 'Use rome config to update an existing config',