@liquid-labs/playground-monitor
v1.0.0-beta.4
Published
A file-watching utility to track changes to a developers "playground".
Downloads
9
Maintainers
Readme
playground-monitor
A file-watching utility to track changes to a developers "playground". Specifically, creates a manifest of projects and watches for the introduction, removal, or changes in project directories and package.json
files and updates the project manifest accordingly. Built on top of chokidar.
Installation
npm i @liquid-labs/playground-monitor
Usage
import * as path from 'node:path'
import { PlaygroundMonitor } from '@liquid-labs/playground-monitor' // ESM
// const { PlaygroundMonitor } = require('@liquid-labs/playground-monitor') // CJS
const playgroundPath = fsPath.join(process.env.HOME, 'playground')
const playground = new PlaygroundMonitor({ root: playgroundPath})
try {
await playground.refreshProjects() // must be called to initalize the PlaygroundMonitor
const { pkgJSON, projectPath } = playground.getProjectData('@liquid-labs/playground-monitor')
}
finally {
playground.close() // must call to stop watchers and end process
}
Reference
PlaygroundMonitor.constructor({ depth = 2, root })
Creates a newPlaygroundMonitor
watching the playground atroot
which will look for projects (directories withpackage.json
files)depth
levels down.depth
: (opt, int, default: 2) how many levels of directories under root to watchroot
: (req, string) the path to the playground root
PlaygroundMonitor.close()
:
Stops the underlying watchers and frees resources. The node process will hang unlesss thePlayground
instance is closed.PlaygroundMonitor.getProjectData(projectName)
Retrieves the{ pkgJSON, /*and*/ projectPath }
for the project wherepkgJSON
is the contents of the projectspackage.json
file as a JSON data object andprojectPath
is the absolute path to the project root (the directory wherepackage.json
lives).projectName
: (req, string) the name (frompackage.json
) of the project/package.
getWatched()
Returns an object representing all the paths on the file system being watched. The object's keys are all the directories (using absolute paths unless the cwd option was used), and the values are arrays of the names of the items contained in each directory.PlaygroundMonitor.listProjects()
Lists the known project names alphabetically as an array of strings.async PlaygroundMonitor.refreshProjects()
Asynchronously initializes the playground. This method must be called for thePlaygroundMonitor
to function.