sourcebit-source-filesystem
Advanced tools
Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "sourcebit-source-filesystem", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Sourcebit filesystem source plugin", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -34,2 +34,3 @@ const chokidar = require('chokidar'); | ||
if (stackbitYamlExists) { | ||
log('loading stackbit.yaml and models...'); | ||
const { models, stackbitYaml } = await loadStackbitYaml(stackbitYamlPath) | ||
@@ -56,10 +57,22 @@ setPluginContext({ models, stackbitYaml }); | ||
if (watch) { | ||
const update = async (eventName, path) => { | ||
log(`file '${path}' has been ${eventName}, reloading files...`); | ||
let changedFilePaths = []; | ||
if (path === stackbitYamlFileName) { | ||
const { models, stackbitYaml } = loadStackbitYaml(stackbitYamlPath) | ||
// don't call refresh on every file change, as multiple files could be written at once. | ||
// instead, debounce the update function for 50ms, up to 200ms | ||
const debouncedUpdate = _.debounce(async () => { | ||
log(`reload files and refresh sourcebit plugins...`); | ||
const filePathsCopy = changedFilePaths.slice(); | ||
changedFilePaths = []; | ||
if (filePathsCopy.includes(stackbitYamlFileName)) { | ||
log('reloading stackbit.yaml and models...'); | ||
const { models, stackbitYaml } = await loadStackbitYaml(stackbitYamlPath) | ||
setPluginContext({ models, stackbitYaml }); | ||
} else { | ||
} | ||
if (_.some(filePathsCopy, filePath => filePath !== stackbitYamlFileName)) { | ||
log('reloading content files...'); | ||
const files = await readFiles(sources); | ||
log(`loaded ${files.length} files`); | ||
setPluginContext({ files }); | ||
@@ -69,2 +82,8 @@ } | ||
refresh(); | ||
}, 50, {maxWait: 200}); | ||
const update = async (eventName, filePath) => { | ||
log(`file '${filePath}' has been ${eventName}, reloading files...`); | ||
changedFilePaths.push(filePath); | ||
await debouncedUpdate(); | ||
}; | ||
@@ -71,0 +90,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16544
315