@dimerapp/fs-client

The file system client for Dimer offers the API to convert the docs into a tree of versions and docs content

Stats

StarsIssuesVersionUpdatedCreatedSize
@dimerapp/fs-client
302.0.13 years ago3 years agoMinified + gzip package size for @dimerapp/fs-client in KB

Readme

Dimer App

Dimer is an open source project and CMS to help you publish your documentation online.


We believe every project/product is incomplete without documentation.
We want to help you publish user facing documentation, without worrying about tools or code to write.


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.

Event Data Description
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:config undefined Config file created
change:config undefined Config file changed
unlink:config undefined Config file removed
error Error There 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.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.