Enhanced file system handler for nodejs.
This was made originally for the cardinal framework and dust-cli
It helps handle config folder for storing data related to the app. You don't always wanna have a database running for cli tools.
This will help you create and write content to ~/.fluct
for instance.
To install with yarn:
yarn add https://github.com/argus-inc/fluct
To install with npm:
npm install @argus-inc/fluct
To use fluct in your project simply do the following:
import {FileHandler} from '@argus-inc/fluct';
const fs = new FileHandler();
You can find a example of usage here: https://github.com/crimson-med/dust-cli/blob/master/src/commands/init.ts
if (fs.doesTempDirExist()) {
log(`Config directory: ${configDirectoryPath} was created ${chalk.green("successfully")}`, LogType.Success);
if (fs.isTempDirWritable()) {
log(`Config directory: ${configDirectoryPath} is ${chalk.green("writable")}`, LogType.Success);
const pathGuide = fs.create_path(["guides"], true);
if (fs.createDir(pathGuide)) {
log(`Guide directory: ${pathGuide} was ${chalk.green("created")}`, LogType.Success);
} else {
log(`Guide directory: ${configDirectoryPath} was ${chalk.red("not created")}`, LogType.Error);
}
} else {
log(`Config directory: ${configDirectoryPath} is ${chalk.red("not writable")}`, LogType.Error);
}
} else {
log(`Config directory: ${configDirectoryPath} was created ${chalk.red("unsuccessfully")}`, LogType.Error);
}
Returns an instance of the FileHandler class.
-
@param
tempDirectoryName: string
- The name of the temp directory defaults to.fluct
-
@returns
FileHandler
- The initiated class of file handler
Returns if the temp directory exists.
- @returns
boolean
- True if the folder exists
Returns if the temp directory is writable.
- @returns
boolean
- True if the folder is writable
Returns if the given directory is writable.
-
@param
path: string
- Astring
of the path to the directory -
@returns
boolean
- True if the folder is writable
Creates the temp directory
- @returns
boolean
- True if the folder was created
Creates an empty file at the given path
-
@param
path: string
- Astring
of the path to the file -
@returns
boolean
- True if the file was created
Deletes a file at the given path
- @param
path: string
- Astring
of the path to the file
Reads the content of a file in sync
-
@param
path: string
- Astring
of the path to the file -
@returns
string
- The content in utf8 format
Saves content to a file at a given path in sync
-
@remark
objects
are automatically saved as JSON -
@param
path: string
- Astring
of the path to the file -
@returns
boolean
- True if the file was saved with desired content
Checks if the given path exists in sync
-
@param
path: string
- Astring
of the path to check -
@returns
boolean
- True if the given path exists
Creates a directpry at the given path in sync
-
@param
path: string
- Astring
of the path to the directory -
@returns
boolean
- True if the directory was created
Builds proper paths
-
@param
paths: string
- Astring[]
of the path to merge file -
@param
fromAppTempDir
- Aboolean
to know if the said path should be from the temp directory -
@param
fromRunningDir
- Aboolean
to know if the said path should be from the running directory -
@returns
string
- True if the file was created
example:
Here's an example with fromAppTempDir
:
// returns `~/.fluct/mypath/myFile.md`
createPath([`mypath`, `myFile.md`], true)
Author: Argus
Developer: Mederic Burlet
Licence: GPL-3-0-only