Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Unhandled Promise Rejections #217

Merged
merged 4 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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