Skip to content

Commit

Permalink
Added config exists check
Browse files Browse the repository at this point in the history
Requires additional input cleansing
  • Loading branch information
MitchPierias committed May 12, 2019
1 parent d064540 commit 12627e4
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface LamingtonConfig {
eos: string;
keepAlive?: boolean;
outDir?: string;
exclude?: string | RegExp | Array<string | RegExp>;
exclude?: Array<string>;
}

/**
Expand Down Expand Up @@ -101,28 +101,36 @@ export class ConfigManager {
// Save cached configuration
await writeFile(
CONFIG_FILE_PATH,
JSON.stringify(
{
JSON.stringify({
...existingConfig,
...userConfig,
},
null,
4
}, null, 4
),
ENCODING
);
// Load existing configuration
await ConfigManager.loadConfigFromDisk();
}

public static async createConfigWhenMissing() {
const atPath = path.join(process.cwd(),'.lamingtonrc');
if (await ConfigManager.configExists(atPath)) return;
ConfigManager.initWithDefaults();
await writeFile(atPath, JSON.stringify(ConfigManager.config, null, 4), ENCODING);
}

/**
* Checks the existence of the configuration
* file at the default [[CONFIG_FILE_PATH]]
* file at the default [[CONFIG_FILE_PATH]] or
* optional path
* @author Mitch Pierias <github.com/MitchPierias>
* @param atPath Optional file path for lookup
* @returns Config exists determiner
*/
public static async configExists() {
return await exists(CONFIG_FILE_PATH);
public static async configExists(atPath:string = CONFIG_FILE_PATH) {
// Should filter out any trailing filename and concatonate
// the default filename
return await exists(atPath);
}

/**
Expand Down

0 comments on commit 12627e4

Please sign in to comment.