Skip to content

Commit

Permalink
fix: better messaging when entering simulator mode
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed May 10, 2022
1 parent b46c1c4 commit 8e4129a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/config/config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,28 @@ const configPath = `${homeDir}/.chia/climate-warehouse/config.yaml`;
const getConfig = _.memoize(() => {
logger.info(`Reading config file at ${configPath}`);

const configFile = path.resolve(
configPath,
);
const configFile = path.resolve(configPath);

// First write it to chia home
if (!fs.existsSync(configFile)) {
try {
fs.writeFileSync(configFile, yaml.dump(defaultConfig), 'utf8');
fs.mkdir(
`${homeDir}/.chia/climate-warehouse`,
{ recursive: true },
(err) => {
if (err) {
throw err;
}

fs.writeFileSync(configFile, yaml.dump(defaultConfig), 'utf8');
},
);
} catch (err) {
// if it still doesnt exist that means we are in an env without write permissions
// so just load the default en
if (typeof process.env.USE_SIMULATOR === 'string') {
defaultConfig.APP.USE_SIMULATOR = true;
logger.info(`ENV FILE OVERRIDE: RUNNING IN SIMULATOR MODE`);
}

logger.error('Cant write config file, falling back to defaults');
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/sync-default-organizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { USE_SIMULATOR } = getConfig().APP;
import dotenv from 'dotenv';
dotenv.config();

logger.info('climate-warehouse:task:default-organizations');
logger.info('climate-warehouse:task:sync-default-organizations');

const task = new Task('sync-default-organizations', async () => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/sync-governance-body.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { GOVERANCE_BODY_ID, GOVERNANCE_BODY_IP, GOVERNANCE_BODY_PORT } =
import dotenv from 'dotenv';
dotenv.config();

logger.info('climate-warehouse:task:governance');
logger.info('climate-warehouse:task:sync-governance');

const task = new Task('sync-governance-meta', async () => {
try {
Expand Down
14 changes: 13 additions & 1 deletion src/utils/config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@ export const getConfig = _.memoize(() => {
try {
if (!fs.existsSync(configFile)) {
try {
fs.writeFileSync(configFile, yaml.dump(defaultConfig), 'utf8');
fs.mkdir(
`${homeDir}/.chia/climate-warehouse`,
{ recursive: true },
(err) => {
if (err) {
throw err;
}

fs.writeFileSync(configFile, yaml.dump(defaultConfig), 'utf8');
},
);
} catch (err) {
// if it still doesnt exist that means we are in an env without write permissions
// so just load the default env
if (process.env.USE_SIMULATOR) {
defaultConfig.APP.USE_SIMULATOR = true;
defaultConfig.APP.CHIA_NETWORK = 'testnet';
logger.info(`ENV FILE OVERRIDE: RUNNING IN SIMULATOR MODE`);
}

return yaml.load(yaml.dump(defaultConfig));
Expand All @@ -35,6 +46,7 @@ export const getConfig = _.memoize(() => {

if (typeof process.env.USE_SIMULATOR === 'string') {
yml.APP.USE_SIMULATOR = true;
logger.info(`ENV FILE OVERRIDE: RUNNING IN SIMULATOR MODE`);
}

return yml;
Expand Down

0 comments on commit 8e4129a

Please sign in to comment.