confini-js

Javascript adaptation of python-confini
git clone git://git.defalsify.org/confini-js.git
Log | Files | Refs

commit f598a1c33c467910294468a5f701809552b500fa
parent 3edd9517669284e83552a03effb0775217a0222f
Author: nolash <dev@holbrook.no>
Date:   Thu, 10 Dec 2020 16:19:18 +0100

Return bool on create/generate

Diffstat:
MCHANGELOG | 2++
Mpackage.json | 2+-
Msrc/config.ts | 19++++++++++++-------
3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,3 +1,5 @@ +* 0.0.7 + - Return bool whether generate/create config dir/files succeeded * 0.0.6 - Add config dir generation * 0.0.5 diff --git a/package.json b/package.json @@ -1,6 +1,6 @@ { "name": "confini", - "version": "0.0.6", + "version": "0.0.7", "description": "Merge all ini configuration files from a folder", "main": "dist/index.js", "scripts": { diff --git a/src/config.ts b/src/config.ts @@ -81,21 +81,25 @@ class Config { return s; } - public create() { + public create(): boolean { if (fs.existsSync(this.filepath)) { const stat = fs.statSync(this.filepath); if (!stat.isDirectory()) { throw this.filepath + ' is not a directory' } - } else { - fs.mkdirSync(this.filepath, { - recursive: true, - }); + return false; } + fs.mkdirSync(this.filepath, { + recursive: true, + }); + return true; } - public generate(template:object) { - this.create(); + public generate(template:object):boolean { + if (!this.create()) { + console.debug('config directory already exists'); + return false; + } Object.keys(template).forEach((k) => { const fd = fs.openSync(path.join(this.filepath, k + '.ini'), 'w'); fs.writeSync(fd, '[' + k + ']\n'); @@ -104,6 +108,7 @@ class Config { }); fs.closeSync(fd); }); + return true; } }