Skip to content

Commit

Permalink
Merge pull request #217 from andreban/small-fixes
Browse files Browse the repository at this point in the history
Fixes Unhandled Promise Rejections
  • Loading branch information
andreban authored Jul 1, 2020
2 parents aff70af + e38ea22 commit 10a6666
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
5 changes: 5 additions & 0 deletions packages/cli/src/lib/Cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export class Cli {
command = parsedArgs._[0];
}

// If no command is given, default to 'help'.
if (!command) {
command = 'help';
}

switch (command) {
case 'help':
return await help(parsedArgs);
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ 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_NAME = 'bubblewrap-config.json';
const DEFAULT_CONFIG_FOLDER = join(homedir(), '.bubblewrap');
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';
Expand Down Expand Up @@ -58,14 +58,14 @@ async function renameConfigIfNeeded(log = new Log('config')): Promise<void> {
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<Config> {
export async function loadOrCreateConfig(path = DEFAULT_CONFIG_FILE_PATH): Promise<Config> {
await renameConfigIfNeeded();
const existingConfig = await Config.loadConfig(path);
if (existingConfig) return existingConfig;
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/spec/configSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ 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_NAME = 'bubblewrap-config.json';
const DEFAULT_CONFIG_FOLDER = join(homedir(), '.bubblewrap');
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';
Expand All @@ -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': '{}',
Expand Down Expand Up @@ -83,15 +83,15 @@ 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]: {
'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.
Expand Down

0 comments on commit 10a6666

Please sign in to comment.