Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
#21 - Cleanup todos in AppSettings
Browse files Browse the repository at this point in the history
Signed-off-by: Wright, Christopher R <Christopher.Wright@ca.com>
  • Loading branch information
Wright, Christopher R authored and Wright, Christopher R committed Sep 18, 2018
1 parent 1778053 commit 1788371
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions packages/settings/src/AppSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* *
*/

import {readFileSync, writeFile} from "jsonfile";
import {existsSync} from "fs";
import {ISettingsFile} from "./doc/ISettingsFile";
import {Logger} from "../../logger";
import { readFileSync, writeFile } from "jsonfile";
import { existsSync } from "fs";
import { ISettingsFile } from "./doc/ISettingsFile";
import { Logger } from "../../logger";

/**
* A recovery function to handle when a settings file is missing on an initialization function.
Expand All @@ -26,21 +26,24 @@ export type FileRecovery = (settingsFile: string, defaultSettings: ISettingsFile

/**
* This class represents settings for an Imperative CLI application that can be configured
* by an end user by modifying a settings file. @TODO expand on this doc
* by an end user by modifying a settings file. Settings are stored in {@link AppSettings#settings}
* in a format specified by {@link ISettingsFile}.
*/
export class AppSettings {
/**
*
* @param settingsFile The settings file to load from.
* @param missingFileRecovery A recovery function when the settings file isn't found
*
* @returns A reference to the created instance. This is the same instance returned by {@link AppSettings.instance}
*
* @throws {@link SettingsAlreadyInitialized} When the settings singleton has previously been initialized.
*/
public static initialize(settingsFile: string, missingFileRecovery ?: FileRecovery): AppSettings {
public static initialize(settingsFile: string, missingFileRecovery?: FileRecovery): AppSettings {
if (AppSettings.mInstance) {
// Throw an error imported at runtime so that we minimize file that get included
// on startup.
const { SettingsAlreadyInitialized } = require("./errors/index");
const {SettingsAlreadyInitialized} = require("./errors/index");
throw new SettingsAlreadyInitialized();
}

Expand All @@ -66,16 +69,15 @@ export class AppSettings {
if (AppSettings.mInstance == null) {
// Throw an error imported at runtime so that we minimize file that get included
// on startup.
const { SettingsNotInitialized } = require("./errors/index");
const {SettingsNotInitialized} = require("./errors/index");
throw new SettingsNotInitialized();
}

return AppSettings.mInstance;
}

/**
* Internal reference to the overrides settings. The defaults should
* all be false, indicating that there are no overrides to be done.
* The settings loaded from the file specified in the constructor.
*/
public readonly settings: ISettingsFile;

Expand All @@ -85,7 +87,7 @@ export class AppSettings {
* @param settingsFile The full path to a settings file to load.
* @param missingFileRecovery A recovery function for when the settings file didn't exist
*/
constructor(private readonly settingsFile: string, missingFileRecovery ?: FileRecovery) {
constructor(private readonly settingsFile: string, missingFileRecovery?: FileRecovery) {
let settings: ISettingsFile;
const defaultSettings: ISettingsFile = {
overrides: {
Expand Down Expand Up @@ -139,7 +141,7 @@ export class AppSettings {
*
* @returns A promise of completion
*/
private writeSettingsFile(): Promise<void>{
private writeSettingsFile(): Promise<void> {
return new Promise((resolve, reject) => {
writeFile(this.settingsFile, this.settings, {
spaces: 2
Expand Down

0 comments on commit 1788371

Please sign in to comment.