-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtExtractor.ts
40 lines (34 loc) · 1.28 KB
/
rtExtractor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// extract results from command line utility "rt" (react-templates)
//
import rt = require("react-templates/src/reactTemplates");
import { Context } from "./context";
import { CommandLineOptions } from "./options";
import { wrapCodeCommonJs, wrapCodeTypeScript } from "./wrapCode";
export function extract(rtHtml: string, tagName: string, context: Context): string
{
const rtOptions = {
modules: context.options.typescript ? 'typescript' : 'commonjs',
version: false,
format: 'stylish',
native: false,
targetVersion: context.options.targetVersion,
reactImportPath: context.options.reactImportPath,
lodashImportPath: context.options.lodashImportPath,
normalizeHtmlWhitespace: context.options.normalizeHtmlWhitespace,
createElementAlias: context.options.createElementAlias,
externalHelpers: context.options.externalHelpers,
};
var jsCode;
try
{
jsCode = rt.convertTemplateToReact(rtHtml, rtOptions);
}
catch(ex)
{
console.log(ex);
//console.log(rtHtml);
return "";
}
return context.options.typescript ? wrapCodeTypeScript(jsCode, context.options.trace, tagName, context.isStateless) : wrapCodeCommonJs(jsCode, context.options.trace, tagName, context.isStateless);
}