This package has been deprecated

Author message:

Use @technician/source-fs for Technician >= 2.0.0

@technician/fs-config-source
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

@technician/fs-config-source

npm version npm downloads npm license

dependencies Build Status GitKraken

A config source for accessing config stored on the filesystem.

The FSConfigSource accesses the contents of an entire directory, allowing access to several config files stored in the same location. It useable as both an async and sync config source.

This package provides the FSConfigSource for use with the Technician manager.

Technician

Installation

npm i @technician/fs-config-source

This package is compatible with Node 10 LTS and up.

Usage Examples

The Basics

import {Technician, DefaultInterpreters} from 'technician';
import {FSConfigSource} from '@technician/fs-config-source'

const technician = new Technician(DefaultInterpreters.asText('utf8'));
technician.addSource(new FSConfigSource());

// By default, FSConfigSource reads from process.cwd();
await technician.read('.myapprc');
await technician.read('something-else.json');

Working With JSON

import {Technician, DefaultInterpreters} from 'technician';
import {FSConfigSource} from '@technician/fs-config-source'

const technician = new Technician(DefaultInterpreters.asJSON('utf8'));
technician.addSource(new FSConfigSource());

const config = await technician.read('config.json');

// The default asJSON interpreter can read and return JSON files as a js object.
// Non-JSON will be ignored with `asJSON`.
// You can use `asTextOrJSON` to optionally parse only valid JSON.
db.connect(config.dbUsername, config.dbPassword);

Specifying Directories

// ...

// Provide an absolute path to a directory.
technician.addSource(new FSConfigSource('/home/me/my-config-dir'));

// The relativeRootPath option will look inside process.cwd() for your custom path.
technician.addSource(new FSConfigSource('app-config-dir', {relativeRootPath: true}));

// ...

Recursive Reading

// ...

// Allows recursive access to subdirectories.
technician.addSource(new FSConfigSource(), {recurse: true});

// Read a file at the top level...
await technician.read('top-level-file.txt');
// ... or within nested subdirectories
await technician.read('subdirectory/another-file.txt');

// Note that subdirectories are not expanded into objects with readAll(),
// but instead keep the same flat key structure used by read().

// Ex: {"top-level-file.txt": "contents", "subdirectory/another-file.txt": "contents"}

Errors

By default, the FSConfigSource suppresses all filesystem errors (except in the case that the rootPath passed to the constructor is invalid), instead treating any unreadable files as simply nonexistent.

To throw these errors instead, use the {throwErrors: true} option. Note that this will cause readAll() to throw an error if the target directory contains any inaccessible files, even if others are valid.

Contributions

Contributions and pull requests are always welcome. Please be sure your code passes all existing tests and linting.

Pull requests with full code coverage are strongly encouraged.

License

Apache-2.0

Package Sidebar

Install

npm i @technician/fs-config-source

Weekly Downloads

1

Version

1.0.3

License

Apache-2.0

Unpacked Size

36.5 kB

Total Files

15

Last publish

Collaborators

  • carriejv