2.0.1 • Published 6 years ago

@dimerapp/fs-client v2.0.1

Weekly downloads
21
License
MIT
Repository
github
Last release
6 years ago

Dimer FsClient

The file system client for Dimer offers the API to convert the docs into a tree of versions and docs content. Later you can use this with the combination of datastore to store it with the database.

Installation

npm i @dimerapp/fs-client

# yarn
yarn add @dimerapp/fs-client

Usage

const FsClient = require('@dimerapp/fs-client')
const ConfigParser = require('@dimerapp/config-parser')
const Context = require('@dimerapp/context')

const basePath = process.cwd()
const ctx = new Context(basePath)

const { errors, config } = await (new (new ConfigParser(ctx))).parse()

const client = new FsClient(ctx, config.zones)
const tree = await client.tree()

You can pass markdownOptions to dfile by setting them on the ctx.

ctx.set('lib-name', 'markdownOptions', {
  async onUrl () {
  }
})

Allowed files

The files must have .md, .markdown, .mkd and .mkdown extensions, otherwise they will be ignored.

Watch for changes

client.watch(async (event, arg) => {
  if (event === 'add:doc' || event === 'change:doc') {
    console.log(arg)
  }

  if (event === 'unlink:doc') {
    console.log(arg)
  }

  if (event === 'unlink:version') {
    console.log('removed directory for a given version')
  }

  if (event === 'change:config' || event === 'add:config') {
    console.log('config file changed')
  }

  if (event === 'unlink:config') {
    console.log('config file removed, stop watcher')
  }
})

Fs client API

Following is the API for the watcher.

constructor

const FsClient = require('@dimerapp/fs-client')
const client = new FsClient(ctx, zones)

// or with markdown options
ctx.set('markdownOptions', {
})
const client = new FsClient(ctx, zones)

filesTree

Returns an array of files path tree for all the versions. Only files ending with .md and .markdown are picked.

const tree = await client.filesTree()

tree

Returns a content tree of all the files mapped with their versions.

const tree = await client.tree()

watch

Watch for changes in the docs or the config file. dimer.json.

client.watch(() => {
})

watchVersion(zoneSlug, version)

Tell watcher to start watching a new version when it is added to the config file.

client.watchVersion('guides', {
  no: '1.0.0',
  location: 'docs/1.0.0'
})

unwatchVersion(zoneSlug, location)

Tell watcher to stop watching files for a given version, when it is removed from the config file.

client.unwatchVersion('guides', docs/master')

travis-image npm-image

Events

Following is the list of events and data associated with them.

The versions inside the events will have additional property called zoneSlug attached on them. You can use that property to add data to the datastore.

EventDataDescription
add:doc{ versions: [], file }Data includes an array of versions and the Dfile object for that given file.
change:doc{ versions: [], file }Data includes an array of versions and the Dfile object for that given file.
unlink:doc{ versions: [], baseName }Data includes an array of versions and baseName of the file that was removed.
unlink:version[{ no: '1.0.0' }]Data includes an array of versions that shares the directory which was removed.
add:configundefinedConfig file created
change:configundefinedConfig file changed
unlink:configundefinedConfig file removed
errorErrorThere was an error

Change log

The change log can be found in the CHANGELOG.md file.

Contributing

Everyone is welcome to contribute. Please take a moment to review the contributing guidelines.

Authors & License

thetutlage and contributors.

MIT License, see the included MIT file.

2.0.1

6 years ago

2.0.0

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.0

6 years ago