1.0.0-beta.4 • Published 2 years ago
@liquid-labs/playground-monitor v1.0.0-beta.4
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-monitorUsage
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 newPlaygroundMonitorwatching the playground atrootwhich will look for projects (directories withpackage.jsonfiles)depthlevels 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 thePlaygroundinstance is closed.PlaygroundMonitor.getProjectData(projectName)\ Retrieves the{ pkgJSON, /*and*/ projectPath }for the project wherepkgJSONis the contents of the projectspackage.jsonfile as a JSON data object andprojectPathis the absolute path to the project root (the directory wherepackage.jsonlives).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 thePlaygroundMonitorto function.
1.0.0-beta.4
2 years ago
1.0.0-beta.3
2 years ago
1.0.0-beta.2
2 years ago
1.0.0-beta.1
2 years ago
1.0.0-beta.0
2 years ago