Skip to content

Commit

Permalink
Incorporate path checks into save util
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroCB committed Aug 1, 2020
1 parent 87dbd5b commit 8f43f4d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,10 @@ function storePrefs(sendEmail, sendPass, recvEmail, recvPass, shouldStore, recvA
config["password"] = sendPass;
}

const configPath = tools.getConfigDir();
if (!fs.existsSync(configPath)) {
fs.mkdirSync(configPath);
}

console.log(`${chalk.green("Login successful.")} ${nameStr}Storing your session in ${chalk.yellow(tools.getConfigDir())}...`);
fs.writeFileSync(tools.getConfigPath(), JSON.stringify(config));
callback(null, sendApi);
tools.saveConfig(config, err => {
callback(err, sendApi);
});
});
});
});
Expand Down
5 changes: 5 additions & 0 deletions src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ exports.loadConfig = () => {
}

exports.saveConfig = (config, callback = () => { }) => {
const configPath = this.getConfigDir();
if (!fs.existsSync(configPath)) {
fs.mkdirSync(configPath);
}

fs.writeFile(this.getConfigPath(), JSON.stringify(config), callback);
}

Expand Down

0 comments on commit 8f43f4d

Please sign in to comment.