Skip to content

Commit

Permalink
fix: fixed prettier parser for pre-compiled templates
Browse files Browse the repository at this point in the history
  • Loading branch information
jairmilanes committed Nov 4, 2022
1 parent c88b4dc commit ca755b7
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/lib/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import frontMatter from "front-matter";
import glob from "glob";
import { readFile } from "fs/promises";
import prettify from "prettier";
import prettier from "prettier";
import uglify from "uglify-js";
import { basename } from "../utils/path";
import { HandlebarsWax, InjectionData, SafeObject } from "../types";
import { HandlebarsWax, InjectionData, SafeObject, WatcherChangeType } from "../types";
import { configureHandlebars } from "./handlebars";
import { Config } from "./config";
import { logger } from "./logger";
Expand Down Expand Up @@ -98,8 +98,8 @@ export class Renderer {
const js = await this.preCompile(templates);

if (this.config.env === "development") {
return prettify.format(js, {
parser: "glimmer"
return prettier.format(js, {
parser: "babel"
});
} else {
const ugly = uglify.minify(js);
Expand All @@ -122,19 +122,18 @@ export class Renderer {
private async preCompile(templates: string[]): Promise<string> {
try {
return `(function() {
const template = Handlebars.template;
const templates = Handlebars.templates || {};
Handlebars.templates = {};
${await Promise.all(
templates.map(async (templatePath) => {
const { name, template } = await this.loadTemplate(
templatePath
);
const code = this.hbs?.handlebars.precompile(template);
return `
templates["${name}"] = template(${code});\r\n
`;
return `Handlebars.templates["${name}"] = Handlebars.template(${code});`;
})
)}
).then(rs => rs.join('\r\n'))}
})();`;
} catch (err) {
return `console.error("${(err as Error).message}");`;
Expand Down

0 comments on commit ca755b7

Please sign in to comment.