Skip to content

Commit

Permalink
Merge pull request #3848 from soulsands/auto-reload
Browse files Browse the repository at this point in the history
chore: dev auto reload
  • Loading branch information
zadam authored Apr 16, 2023
2 parents aaf6e3b + d2d2a28 commit 447b8f0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
13 changes: 13 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"restartable": "rs",
"ignore": [".git", "node_modules/**/node_modules", "src/public/"],
"verbose": false,
"execMap": {
"js": "node --harmony"
},
"watch": ["src/"],
"env": {
"NODE_ENV": "development"
},
"ext": "js,json"
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"url": "https://github.com/zadam/trilium.git"
},
"scripts": {
"start-server": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 node ./src/www",
"start-server-no-dir": "cross-env TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 node ./src/www",
"start-server": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon ./src/www",
"start-server-no-dir": "cross-env TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon ./src/www",
"start-electron": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron --inspect=5858 .",
"start-electron-no-dir": "cross-env TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 electron --inspect=5858 .",
"switch-server": "rm -rf ./node_modules/better-sqlite3 && npm install",
Expand Down Expand Up @@ -104,6 +104,7 @@
"jasmine": "4.6.0",
"jsdoc": "4.0.2",
"lorem-ipsum": "2.0.8",
"nodemon": "^2.0.22",
"rcedit": "3.0.1",
"webpack": "5.78.0",
"webpack-cli": "5.0.1"
Expand Down
12 changes: 12 additions & 0 deletions src/services/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ const protectedSessionService = require('./protected_session');
const becca = require("../becca/becca");
const AbstractBeccaEntity = require("../becca/entities/abstract_becca_entity");

const env = require('./env');
if (env.isDev()) {
const chokidar = require('chokidar');
const debounce = require('debounce');
const debouncedReloadFrontend = debounce(reloadFrontend, 200);
chokidar
.watch('src/public')
.on('add', debouncedReloadFrontend)
.on('change', debouncedReloadFrontend)
.on('unlink', debouncedReloadFrontend);
}

let webSocketServer;
let lastSyncedPush = null;

Expand Down

0 comments on commit 447b8f0

Please sign in to comment.