Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
],
"scripts": {
"test": "node --test nuxt/server/lib/*.test.mjs nuxt/lib/*.test.mjs",
"dev": "concurrently \"npm run dev:eleventy\" \"npm run dev:postcss\" \"npm run dev:postcss-nuxt\" \"dotenv -- npm run dev --workspace=nuxt\"",
"dev": "concurrently \"npm run dev:eleventy\" \"npm run dev:docs\" \"npm run dev:postcss\" \"npm run dev:postcss-nuxt\" \"dotenv -- npm run dev --workspace=nuxt\"",
"start": "npm-run-all2 clean:dev build:js blueprints --parallel dev:*",
"build:js": "terser -c -m -o _site/js/cc.min.js node_modules/vanilla-cookieconsent/dist/cookieconsent.umd.js src/js/cookieconsent-config.js && cp node_modules/@flowfuse/flow-renderer/index.min.js _site/js/flowrenderer.min.js",
"build": "dotenv -v NODE_ENV=production -- npm-run-all2 clean build:js --parallel prod:*",
"build:skip-images": "dotenv -v SKIP_IMAGES=true -- npm run build",
"clean:dev": "dotenv -- npx del-cli '_site/!(img)' 'src/blueprints/**/!(*submit.njk)' && dotenv -- npx mkdirp '_site/js/flows'",
"clean": "dotenv -- npx del-cli '_site/!(img)' && dotenv -- mkdir -p '_site/js'",
"dev:blueprints": "node scripts/watch_blueprints.js",
"dev:docs": "node scripts/watch_docs.mjs",
"dev:netlify": "npx netlify dev -c \"dotenv -- npx @11ty/eleventy --serve --quiet --incremental\"",
"dev:postcss": "dotenv -v TAILWIND_MODE=watch -- npx postcss ./src/css/style.css -o ./_site/css/style.css --config ./postcss.config.js -w",
"dev:postcss-nuxt": "dotenv -v TAILWIND_MODE=watch -- npx postcss ./src/css/style.css -o ./nuxt/public/css/style.css --config ./postcss.config.js -w",
Expand Down
41 changes: 41 additions & 0 deletions scripts/watch_docs.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env node
// Re-runs the docs sync whenever the resolved docs change, so editing a page in a local
// flowfuse checkout shows up without restarting the dev server. The docs-source Nuxt
// module syncs once during setup and never again, which is what made a restart necessary.
// Mirrors scripts/watch_blueprints.js.

import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'

import nodemon from 'nodemon'

import { resolveSource } from '../nuxt/lib/docs-sync.mjs'

const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..')

// Same precedence the build uses, rather than a second hardcoded path that could drift
// from it: FLOWFUSE_DOCS_LOCAL, then a sibling checkout, then a clone.
const source = resolveSource({ repoRoot })

if (source.kind === 'clone') {
console.log(`Docs resolve to a clone of ${source.ref} - no local checkout to watch, skipping`)
process.exit(0)
}

console.log(`Watching ${source.docsDir} for docs changes`)

// Options object rather than a command string: docsDir comes from the environment and
// would need shell quoting if it contained a space.
nodemon({
watch: [source.docsDir],
ext: 'md,png,jpg,jpeg,gif,svg',
exec: 'npm run docs',
// The Nuxt module already synced on startup, so only react to actual edits.
runOnChangeOnly: true,
})

nodemon.on('restart', (files) => {
console.log(`Docs change detected (${files?.join(', ') || 'unknown'}) - syncing`)
}).on('exit', () => {
console.log('Docs sync complete')
})
Loading