|
| 1 | +// eslint-disable-next-line @typescript-eslint/triple-slash-reference |
| 2 | +/// <reference path="../typings/wontache/wontache.d.ts" /> |
1 | 3 | /*
|
2 | 4 | * Copyright 2011 Twitter, Inc.
|
3 | 5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
|
16 | 18 | import * as path from 'path';
|
17 | 19 | import * as fs from 'fs';
|
18 | 20 |
|
19 |
| -import * as hogan from 'hogan.js'; |
| 21 | +import mustache from 'wontache'; |
20 | 22 | import nopt from 'nopt';
|
21 | 23 | import * as mkderp from 'mkdirp';
|
22 | 24 |
|
@@ -107,25 +109,20 @@ function removeByteOrderMark(text: string): string {
|
107 | 109 | }
|
108 | 110 |
|
109 | 111 | // 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; |
112 | 114 |
|
113 | 115 | const objectName = options.variable || 'templates';
|
114 | 116 | const objectAccessor = `${objectName}["${name}"]`;
|
115 |
| -const objectStmt = `${objectAccessor} = ${hoganTemplateString};`; |
| 117 | +const objectStmt = `${objectAccessor} = ${templateString};`; |
116 | 118 |
|
117 | 119 | 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 |
| - |
123 | 120 | case 'node':
|
124 | 121 | // If we have a template per file the export will expose the template directly
|
125 | 122 | return options.outputdir ? `global.${objectStmt};\nmodule.exports = ${objectAccessor};` : `global.${objectStmt}`;
|
126 | 123 |
|
127 | 124 | case 'ts':
|
128 |
| -return `// @ts-ignore\n${objectStmt}`; |
| 125 | +return `// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\n${objectStmt}`; |
129 | 126 | default:
|
130 | 127 | return objectStmt;
|
131 | 128 | }
|
@@ -137,16 +134,18 @@ function prepareOutput(content: string): string {
|
137 | 134 | case 'amd':
|
138 | 135 | return content;
|
139 | 136 | case 'node':
|
140 |
| -return `(function() { |
| 137 | +return `const mustache = require('wontache'); |
| 138 | +(function() { |
141 | 139 | if (!!!global.${variableName}) global.${variableName} = {};
|
142 |
| -var Hogan = require("hogan.js"); |
143 | 140 | ${content}
|
144 | 141 | ${!options.outputdir ? `module.exports = global.${variableName};\n` : ''})();`;
|
145 | 142 |
|
146 | 143 | 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 } = {}; |
150 | 149 | ${content}`;
|
151 | 150 |
|
152 | 151 | default:
|
@@ -172,7 +171,7 @@ const templates = extractFiles(options.argv.remain)
|
172 | 171 | if (!timmedFileContents) return;
|
173 | 172 |
|
174 | 173 | const name = namespace(path.basename(file).replace(/\..*$/, ''));
|
175 |
| -const cleanFileContents = wrap(file, name, removeByteOrderMark(timmedFileContents)); |
| 174 | +const cleanFileContents = wrap(name, removeByteOrderMark(timmedFileContents)); |
176 | 175 |
|
177 | 176 | if (!options.outputdir) return cleanFileContents;
|
178 | 177 |
|
|
0 commit comments