Skip to content

Commit

Permalink
Merge pull request #36 from imLymei/master
Browse files Browse the repository at this point in the history
update beta
  • Loading branch information
imLymei authored Oct 4, 2024
2 parents 73d8c23 + 350d900 commit fb6781e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ export const USER_DIRECTORY = os.homedir();
export const CONFIG_DIRECTORY = path.join(USER_DIRECTORY, '.config');
export const CONFIG_FILE_NAME = 'foji.json';
export const CONFIG_FILE_PATH = path.join(CONFIG_DIRECTORY, CONFIG_FILE_NAME);
export const HAS_CONFIGURATION = fs.existsSync(
path.join(CONFIG_DIRECTORY, 'foji.json')
);
export const HAS_CONFIGURATION =
fs.existsSync(path.join(CONFIG_DIRECTORY, 'foji.json')) &&
typeof (JSON.parse(fs.readFileSync(CONFIG_FILE_PATH, 'utf-8')) as Config)
.commands === 'object';

export function createConfig(
newConfig: Config = { commands: {} },
useLettersSaved = false
): Config {
if (!HAS_CONFIGURATION) fs.mkdirSync(CONFIG_DIRECTORY, { recursive: true });

if (!useLettersSaved) newConfig.lettersSaved = getConfig().lettersSaved;
if (!useLettersSaved)
newConfig.lettersSaved = HAS_CONFIGURATION ? getConfig().lettersSaved : 0;

fs.writeFileSync(CONFIG_FILE_PATH, JSON.stringify(newConfig, null, 2));
return newConfig;
Expand Down

0 comments on commit fb6781e

Please sign in to comment.