allow template hot reload

pull/92/head
undefined 4 years ago
parent a29c4ebf77
commit 32df811bfa

@ -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\""
},

@ -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,

Loading…
Cancel
Save