From 1ac946d0ab5da9847d9da9a6b149fb468fc5fdf5 Mon Sep 17 00:00:00 2001 From: Andre Bandarra Date: Tue, 30 Jun 2020 21:19:05 +0100 Subject: [PATCH 1/4] Fixes Unhandled Promise Rejections - Added missing `await` calls to fix Unhandled Promis Rejections when renaming the old config name to the new config name. - Defaults CLI to the `help` command --- packages/cli/src/lib/Cli.ts | 2 +- packages/cli/src/lib/config.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/lib/Cli.ts b/packages/cli/src/lib/Cli.ts index 1a8a2f8d..53135aa9 100644 --- a/packages/cli/src/lib/Cli.ts +++ b/packages/cli/src/lib/Cli.ts @@ -44,7 +44,7 @@ export class Cli { command = 'help'; } } else { - command = parsedArgs._[0]; + command = parsedArgs._[0] || 'help'; } switch (command) { diff --git a/packages/cli/src/lib/config.ts b/packages/cli/src/lib/config.ts index 84ceba49..a9e2f63d 100644 --- a/packages/cli/src/lib/config.ts +++ b/packages/cli/src/lib/config.ts @@ -22,7 +22,7 @@ import * as inquirer from 'inquirer'; import {existsSync} from 'fs'; import {promises as fsPromises} from 'fs'; -const DEFAULT_CONFIG_FOLDER = join(homedir(), '.bubblewrap-config'); +const DEFAULT_CONFIG_FOLDER = join(homedir(), '.bubblewrap'); const DEFAULT_CONFIG_NAME = 'bubblewrap-config.json'; const DEFAULT_CONFIG_FILE_PATH = join(DEFAULT_CONFIG_FOLDER, DEFAULT_CONFIG_NAME); const LEGACY_CONFIG_FOLDER = join(homedir(), '.llama-pack'); @@ -58,14 +58,14 @@ async function renameConfigIfNeeded(log = new Log('config')): Promise { await fsPromises.mkdir(DEFAULT_CONFIG_FOLDER); await fsPromises.rename(LEGACY_CONFIG_FILE_PATH, DEFAULT_CONFIG_FILE_PATH); } else { - fsPromises.rename(LEGACY_CONFIG_FOLDER, DEFAULT_CONFIG_FOLDER); - fsPromises.rename(join(DEFAULT_CONFIG_FOLDER, LEGACY_CONFIG_NAME), DEFAULT_CONFIG_FILE_PATH); + await fsPromises.rename(LEGACY_CONFIG_FOLDER, DEFAULT_CONFIG_FOLDER); + await fsPromises + .rename(join(DEFAULT_CONFIG_FOLDER, LEGACY_CONFIG_NAME), DEFAULT_CONFIG_FILE_PATH); } } -export async function loadOrCreateConfig(path = -join(DEFAULT_CONFIG_FOLDER, DEFAULT_CONFIG_NAME)): Promise { +export async function loadOrCreateConfig(path = DEFAULT_CONFIG_FILE_PATH): Promise { await renameConfigIfNeeded(); const existingConfig = await Config.loadConfig(path); if (existingConfig) return existingConfig; From 1deb3e0e9a2f01e27c0d49872d4ddcae4ca8bad4 Mon Sep 17 00:00:00 2001 From: Andre Bandarra Date: Tue, 30 Jun 2020 21:49:08 +0100 Subject: [PATCH 2/4] Fixes test --- packages/cli/src/spec/configSpec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/spec/configSpec.ts b/packages/cli/src/spec/configSpec.ts index a7faa340..9e6e951b 100644 --- a/packages/cli/src/spec/configSpec.ts +++ b/packages/cli/src/spec/configSpec.ts @@ -22,7 +22,7 @@ import {loadOrCreateConfig} from '../lib/config'; import * as mock from 'mock-fs'; import * as inquirer from 'inquirer'; -const DEFAULT_CONFIG_FOLDER = join(homedir(), '.bubblewrap-config'); +const DEFAULT_CONFIG_FOLDER = join(homedir(), '.bubblewrap'); const DEFAULT_CONFIG_NAME = 'bubblewrap-config.json'; const DEFAULT_CONFIG_FILE_PATH = join(DEFAULT_CONFIG_FOLDER, DEFAULT_CONFIG_NAME); const LEGACY_CONFIG_FOLDER = join(homedir(), '.llama-pack'); @@ -41,7 +41,7 @@ beforeAll(() => { describe('config', () => { describe('#loadOrCreateConfig', () => { it('checks if the file\'s name was changed in case it has the old name', async () => { - // Creates a mock file systes. + // Creates a mock file system. mock({ [LEGACY_CONFIG_FOLDER]: { 'llama-pack-config.json': '{}', @@ -83,8 +83,8 @@ describe('config', () => { mock.restore(); }); - it('checks if both of the files exists in case there are old and new config files' - , async () => { + it('checks if both of the files exists in case there are old and new config files', + async () => { // Creates a mock file systes. mock({ [LEGACY_CONFIG_FOLDER]: { From 3c2b4b0699a51293659133e2c44ea1d0f4639cbb Mon Sep 17 00:00:00 2001 From: Andre Bandarra Date: Tue, 30 Jun 2020 22:03:40 +0100 Subject: [PATCH 3/4] Improves undefined command check --- packages/cli/src/lib/Cli.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/lib/Cli.ts b/packages/cli/src/lib/Cli.ts index 53135aa9..8f562cea 100644 --- a/packages/cli/src/lib/Cli.ts +++ b/packages/cli/src/lib/Cli.ts @@ -44,7 +44,12 @@ export class Cli { command = 'help'; } } else { - command = parsedArgs._[0] || 'help'; + command = parsedArgs._[0]; + } + + // If no command is given, default to 'help'. + if (!command) { + command = 'help'; } switch (command) { From e38ea223a5f2b2b6a29ddc875502fb5275116460 Mon Sep 17 00:00:00 2001 From: Andre Bandarra Date: Wed, 1 Jul 2020 12:12:58 +0100 Subject: [PATCH 4/4] Renames config file - Renames `bubblewrap-config.json` to `config.json`, as the config already sits in the `~/.bubblewrap` directory. --- packages/cli/src/lib/config.ts | 2 +- packages/cli/src/spec/configSpec.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/lib/config.ts b/packages/cli/src/lib/config.ts index a9e2f63d..7a650bb3 100644 --- a/packages/cli/src/lib/config.ts +++ b/packages/cli/src/lib/config.ts @@ -23,7 +23,7 @@ import {existsSync} from 'fs'; import {promises as fsPromises} from 'fs'; const DEFAULT_CONFIG_FOLDER = join(homedir(), '.bubblewrap'); -const DEFAULT_CONFIG_NAME = 'bubblewrap-config.json'; +const DEFAULT_CONFIG_NAME = 'config.json'; const DEFAULT_CONFIG_FILE_PATH = join(DEFAULT_CONFIG_FOLDER, DEFAULT_CONFIG_NAME); const LEGACY_CONFIG_FOLDER = join(homedir(), '.llama-pack'); const LEGACY_CONFIG_NAME = 'llama-pack-config.json'; diff --git a/packages/cli/src/spec/configSpec.ts b/packages/cli/src/spec/configSpec.ts index 9e6e951b..e49a2334 100644 --- a/packages/cli/src/spec/configSpec.ts +++ b/packages/cli/src/spec/configSpec.ts @@ -23,7 +23,7 @@ import * as mock from 'mock-fs'; import * as inquirer from 'inquirer'; const DEFAULT_CONFIG_FOLDER = join(homedir(), '.bubblewrap'); -const DEFAULT_CONFIG_NAME = 'bubblewrap-config.json'; +const DEFAULT_CONFIG_NAME = 'config.json'; const DEFAULT_CONFIG_FILE_PATH = join(DEFAULT_CONFIG_FOLDER, DEFAULT_CONFIG_NAME); const LEGACY_CONFIG_FOLDER = join(homedir(), '.llama-pack'); const LEGACY_CONFIG_NAME = 'llama-pack-config.json'; @@ -91,7 +91,7 @@ describe('config', () => { 'llama-pack-config.json': '{"content":"some old content"}', }, [DEFAULT_CONFIG_FOLDER]: { - 'bubblewrap-config.json': '{"content":"some new content"}', + 'config.json': '{"content":"some new content"}', }}); await loadOrCreateConfig(); // Checks if both of the files exists.