Skip to content

Commit

Permalink
Implimented default config fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchPierias committed Jul 11, 2019
1 parent c15ac07 commit 81f4727
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export enum LamingtonDebugLevel {
* values by specifying them in their `.lamingtonrc`
*/
const DEFAULT_CONFIG = {
eos:'',
cdt:'',
debug:LamingtonDebugLevel.NONE,
debugTransactions: false,
keepAlive: false,
Expand All @@ -66,6 +68,9 @@ export class ConfigManager {
*/
public static async initWithDefaults() {

DEFAULT_CONFIG.cdt = await ConfigManager.getAssetURL('EOSIO', 'eosio.cdt', 'amd64.deb');
DEFAULT_CONFIG.eos = await ConfigManager.getAssetURL('EOSIO', 'eos', 'ubuntu-18.04');

if (!(await ConfigManager.configExists())) {
console.log('Project has not yet been initialized.');
console.log('Please run lamington init before running this command.');
Expand Down Expand Up @@ -108,25 +113,28 @@ export class ConfigManager {
return asset.browser_download_url as string;
}

public static async isValidConfig(config:object) {
return true;
}

/**
* Creates a config file if it's not in the current working directory.
* Creates a default configuration file if it doesn't exist at the specified path.
* @author Mitch Pierias <github.com/MitchPierias>
* @author Kevin Brown <github.com/thekevinbrown>
* @param atPath The path to check for the config file. Defaults to '.lamingtonrc'.
* @param atPath Optional configuration file path. Defaults to `.lamingtonrc`.
*/
public static async createConfigIfMissing(atPath = CONFIGURATION_FILE_NAME) {
if (await ConfigManager.configExists()) return;

// Prevent overwriting existing configuration when valid
if (await ConfigManager.configExists(atPath) && await ConfigManager.isValidConfig(ConfigManager.config)) return;
// Create the config directory
await mkdirp(CACHE_DIRECTORY);

// Fetch the latest repository configuration
const defaultConfig: LamingtonConfig = {
cdt: await ConfigManager.getAssetURL('EOSIO', 'eosio.cdt', 'amd64.deb'),
eos: await ConfigManager.getAssetURL('EOSIO', 'eos', 'ubuntu-18.04'),
...DEFAULT_CONFIG
};

// Cache the configuration file to disk
await writeFile(atPath, JSON.stringify(defaultConfig, null, 4), ENCODING);
}

Expand All @@ -151,11 +159,10 @@ export class ConfigManager {
*/
public static async loadConfigFromDisk(atPath = CONFIGURATION_FILE_NAME) {
// Read existing configuration and store
ConfigManager.config = Object.assign(
{},
DEFAULT_CONFIG,
JSON.parse(await readFile(atPath, ENCODING))
);
ConfigManager.config = {
...DEFAULT_CONFIG,
...JSON.parse(await readFile(atPath, ENCODING))
}
}

/**
Expand Down

0 comments on commit 81f4727

Please sign in to comment.