UNPKG

@communities-webruntime/services

Version:

If you would like to run Lightning Web Runtime without the CLI, we expose some of our programmatic APIs available in Node.js. If you're looking for the CLI documentation [you can find that here](https://www.npmjs.com/package/@communities-webruntime/cli).

43 lines 1.39 kB
/** @hidden */ /** * Copyright (c) 2019, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ import path from 'path'; import chokidar from 'chokidar'; import { hashElement } from 'folder-hash'; const options = { algo: 'md5', encoding: 'hex', }; async function doHash(target) { return (await hashElement(target, options)).hash; } /** * Gets a folder hash as an observable. * * @param {string} target The directory to compute the version key for * @returns An observable that will notify observers when the folder hash changes */ export default async function folderHash(target) { // Chokidar/picomatch don't like relative paths starting with `./`, see #857 const absoluteTarget = path.resolve(target); const hash = await doHash(absoluteTarget); return { subscribe(observer) { observer.next(hash); const watcher = chokidar.watch(absoluteTarget).on('change', async () => { const newHash = await doHash(absoluteTarget); observer.next(newHash); }); return { unsubscribe: () => { watcher.close(); }, }; }, }; } //# sourceMappingURL=observable-folder-hash.js.map