Skip to content

Commit

Permalink
MVP for passing in custom config path (#461)
Browse files Browse the repository at this point in the history
* custom config path

* optional argument pattern
  • Loading branch information
toastal authored Feb 11, 2021
1 parent 9b94e85 commit d628122
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/lib/Cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export class Cli {
throw new Error(`Current Node.js version is ${process.versions.node}.` +
' Node.js version 10 or above is required to run bubblewrap.');
}
const config = await loadOrCreateConfig();

const parsedArgs = minimist(args);

const config = await loadOrCreateConfig(undefined, undefined, parsedArgs.config);

let command;
if (parsedArgs._.length === 0) {
// Accept --version and --help alternatives for the help and version commands.
Expand Down
18 changes: 13 additions & 5 deletions packages/cli/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,21 @@ async function renameConfigIfNeeded(log: Log): Promise<void> {
}
}

export async function loadOrCreateConfig(log: Log = new ConsoleLog('config'),
prompt: Prompt = new InquirerPrompt(), path = DEFAULT_CONFIG_FILE_PATH): Promise<Config> {
await renameConfigIfNeeded(log);
const existingConfig = await Config.loadConfig(path);
export async function loadOrCreateConfig(
log: Log = new ConsoleLog('config'),
prompt: Prompt = new InquirerPrompt(),
path?: string): Promise<Config> {
let configPath;
if (path === undefined) {
await renameConfigIfNeeded(log);
configPath = DEFAULT_CONFIG_FILE_PATH;
} else {
configPath = path;
}
const existingConfig = await Config.loadConfig(configPath);
if (existingConfig) return existingConfig;

const config = await createConfig(prompt);
await config.saveConfig(path);
await config.saveConfig(configPath);
return config;
}

0 comments on commit d628122

Please sign in to comment.