utilities

Exports an object, which contains utility methods for validation and managing files

Source:

module:utilities

Source:

Exports the an object containing the utility functions.

Returns:
Type
Object

Methods

(async, inner) createFile(data, filePath) → {undefined}

Source:

Given data, and a file path, asynchronously creates a new file with that data inserted. Will overwrite the file if it already exists.

Parameters:
Name Type Description
data String

the data that you want in the file

filePath String

the path and filename that you want to write to

Returns:
Type
undefined

(inner) fileExists(filePath) → {Boolean}

Source:

Checks if a given file exists

Parameters:
Name Type Description
filePath String

a path and file name

Returns:
Type
Boolean

(inner) getContentType(extension) → {String}

Source:

Takes a string and outputs a string for use as a content-type value.

Parameters:
Name Type Description
extension String

a file's extension name

Returns:

a content type in the form of "text/extension". Returns undefined if it is an invalid extension

Type
String

(inner) getFilePaths(dir) → {Array}

Source:

Looks inside of a directory, then recursively searches for the paths of all files nested inside of the given directory. Returns an array of file paths.

Example
const path = require("path");
const { getFilePaths } = require('./utilities')
const dirPath = path.join(__dirname, "..", "..", "dirName");
const filePaths = getFilePaths(dirPath);
// [
//  '/path/to/file1.js',
//  '/path/to/file2.jpg',
//  '/path/to/file3.md'
// ]
Parameters:
Name Type Description
dir String

a path to a directory

Returns:

an array of file paths

Type
Array

(async, inner) readFile(filePath) → {String}

Source:

Asynchronously reads the contents of a file, and returns the contents of that file

Parameters:
Name Type Description
filePath String

a path and filename

Returns:

returns text from the file in utf8 format

Type
String

(async, inner) validateInitRan(answersFilePath) → {Boolean}

Source:

Check if user executed beekeeper init before any other commands

Parameters:
Name Type Description
answersFilePath String

a path and file name

Returns:
Type
Boolean

(inner) validateProfileName(profileName, profiles, command) → {Boolean}

Source:

// Check if user provided a valid profile name as part of command

Parameters:
Name Type Description
profileName String

the profile name given during bookeeper init

profiles Object

all of the data stored in user-answers.json

command String

a command given to the CLI

Returns:
Type
Boolean