1+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
2+ /// <reference path="../typings/wontache/wontache.d.ts" />
13/*
24 * Copyright 2011 Twitter, Inc.
35 * Licensed under the Apache License, Version 2.0 (the "License");
1618import * as path from 'path' ;
1719import * as fs from 'fs' ;
1820
19- import * as hogan from 'hogan.js ' ;
21+ import mustache from 'wontache ' ;
2022import nopt from 'nopt' ;
2123import * as mkderp from 'mkdirp' ;
2224
@@ -107,25 +109,20 @@ function removeByteOrderMark(text: string): string {
107109}
108110
109111// Wrap templates
110- function wrap ( file : string , name : string , openedFile : string ) : string {
111- const hoganTemplateString = `new Hogan.Template( ${ hogan . compile ( openedFile , { asString : true } ) } )` ;
112+ function wrap ( name : string , openedFile : string ) : string {
113+ const templateString = mustache ( openedFile ) . source ;
112114
113115 const objectName = options . variable || 'templates' ;
114116 const objectAccessor = `${ objectName } ["${ name } "]` ;
115- const objectStmt = `${ objectAccessor } = ${ hoganTemplateString } ;` ;
117+ const objectStmt = `${ objectAccessor } = ${ templateString } ;` ;
116118
117119 switch ( options . wrapper ) {
118- case 'amd' :
119- return `define(${
120- ! options . outputdir ? `"${ path . join ( path . dirname ( file ) , name ) } ", ` : ''
121- } ["hogan.js"], function(Hogan) { return ${ hoganTemplateString } ; });`;
122-
123120 case 'node' :
124121 // If we have a template per file the export will expose the template directly
125122 return options . outputdir ? `global.${ objectStmt } ;\nmodule.exports = ${ objectAccessor } ;` : `global.${ objectStmt } ` ;
126123
127124 case 'ts' :
128- return `// @ts-ignore\n${ objectStmt } ` ;
125+ return `// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\n${ objectStmt } ` ;
129126 default :
130127 return objectStmt ;
131128 }
@@ -137,16 +134,18 @@ function prepareOutput(content: string): string {
137134 case 'amd' :
138135 return content ;
139136 case 'node' :
140- return `(function() {
137+ return `const mustache = require('wontache');
138+ (function() {
141139if (!!!global.${ variableName } ) global.${ variableName } = {};
142- var Hogan = require("hogan.js");
143140${ content }
144141${ ! options . outputdir ? `module.exports = global.${ variableName } ;\n` : '' } )();`;
145142
146143 case 'ts' :
147- return `import * as Hogan from "hogan.js";
148- type CompiledTemplates = { [name: string]: Hogan.Template };
149- export const ${ variableName } : CompiledTemplates = {};
144+ return `/* eslint-disable @typescript-eslint/no-unused-vars */
145+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
146+ // @ts-nocheck
147+ import mustache, { CompiledTemplate } from 'wontache';
148+ export const defaultTemplates: { [_: string]: CompiledTemplate } = {};
150149${ content } `;
151150
152151 default :
@@ -172,7 +171,7 @@ const templates = extractFiles(options.argv.remain)
172171 if ( ! timmedFileContents ) return ;
173172
174173 const name = namespace ( path . basename ( file ) . replace ( / \. .* $ / , '' ) ) ;
175- const cleanFileContents = wrap ( file , name , removeByteOrderMark ( timmedFileContents ) ) ;
174+ const cleanFileContents = wrap ( name , removeByteOrderMark ( timmedFileContents ) ) ;
176175
177176 if ( ! options . outputdir ) return cleanFileContents ;
178177
0 commit comments