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 new- PlaygroundMonitorwatching the playground at- rootwhich will look for projects (directories with- package.jsonfiles)- depthlevels down.- depth: (opt, int, default: 2) how many levels of directories under root to watch
- root: (req, string) the path to the playground root
 
- PlaygroundMonitor.close():\ Stops the underlying watchers and frees resources. The node process will hang unlesss the- Playgroundinstance is closed.
- PlaygroundMonitor.getProjectData(projectName)\ Retrieves the- { pkgJSON, /*and*/ projectPath }for the project where- pkgJSONis the contents of the projects- package.jsonfile as a JSON data object and- projectPathis the absolute path to the project root (the directory where- package.jsonlives).- projectName: (req, string) the name (from- package.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 the- PlaygroundMonitorto 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