From 32df811bfac0163c17b59f666e051dde517590e0 Mon Sep 17 00:00:00 2001 From: undefined Date: Fri, 9 Apr 2021 12:30:21 +0800 Subject: [PATCH] allow template hot reload --- package.json | 3 +-- packages/ui-default/backendlib/template.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index feadcd3f..0261517b 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "build:watch": "node build/build.js --watch", "build:ui": "node packages/ui-default/build", "build:ui:dev": "node packages/ui-default/build --dev", - "build:ui:watch": "node packages/ui-default/build --watch", "build:ui:production": "node packages/ui-default/build --production", "lint": "eslint packages --ext ts --fix", "lint:ci": "eslint packages --ext ts", @@ -19,7 +18,7 @@ "snowpack": "cd packages/ui-default && snowpack dev", "pub": "node build/publish", "jest": "node build/jest", - "debug": "node --async-stack-traces --trace-deprecation --enable-source-maps build/start --debug", + "debug": "node --async-stack-traces --trace-deprecation --enable-source-maps build/start --debug --template", "start": "node build/start", "clean": "zsh -c \"rm -rf tsconfig.build.tsbuildinfo ./packages/*/tsconfig.tsbuildinfo ./packages/*/dist ./.coverage\"" }, diff --git a/packages/ui-default/backendlib/template.js b/packages/ui-default/backendlib/template.js index 2b677e32..5bbc511e 100644 --- a/packages/ui-default/backendlib/template.js +++ b/packages/ui-default/backendlib/template.js @@ -88,9 +88,19 @@ class Loader extends nunjucks.Loader { }; } let fullpath = null; + if (typeof argv.template !== 'string') argv.template = path.resolve(__dirname, '..', 'template'); const p = path.resolve(process.cwd(), argv.template, name); if (fs.existsSync(p)) fullpath = p; - if (!fullpath) throw new Error(`Cannot get template ${name}`); + if (!fullpath) { + if (global.Hydro.ui.template[name]) { + return { + src: global.Hydro.ui.template[name], + path: name, + noCache: true, + }; + } + throw new Error(`Cannot get template ${name}`); + } return { src: fs.readFileSync(fullpath, 'utf-8').toString(), path: fullpath,