npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dimerapp/fs-client

v2.0.1

Published

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

Downloads

69

Readme

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.