Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.

Commit 4f894b0

Browse files
feat: add support for TS in templates
1 parent a1fe8c0 commit 4f894b0

File tree

5 files changed

+217
-25
lines changed

5 files changed

+217
-25
lines changed

package-lock.json

Lines changed: 193 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@babel/core": "7.12.9",
3535
"@babel/preset-env": "^7.12.7",
3636
"@babel/preset-react": "^7.12.7",
37+
"@babel/preset-typescript": "^7.13.0",
3738
"@rollup/plugin-babel": "^5.2.1",
3839
"babel-plugin-source-map-support": "^2.1.3",
3940
"prop-types": "^15.7.2",
@@ -58,8 +59,7 @@
5859
"jsdoc-to-markdown": "^6.0.1",
5960
"markdown-toc": "^1.2.0",
6061
"semantic-release": "^17.3.0",
61-
"ts-jest": "^26.4.4",
62-
"typescript": "^4.1.2"
62+
"ts-jest": "^26.4.4"
6363
},
6464
"scripts": {
6565
"start": "tsc --watch",

src/renderer/template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { isJsFile } from "../utils";
55
import { TemplateContext, TemplateFunction, TemplateRenderResult } from "../types";
66

77
/**
8-
* render a file with react. This function automatically transforms jsx to js before importing the component.
8+
* Render a file with React.
99
*
1010
* @param filepath the path to file to render
1111
*/

src/transpiler/transpiler.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { TranspileFilesOptions } from '../types';
99
const ROOT_DIR = Path.resolve(__dirname, '../..');
1010

1111
/**
12-
* Transpile files in a given directory (and sub directory if recursive option are passed) and write it to an output directory, if no errors are thrown it completed successfully.
12+
* Transpile files in a given directory (and sub directory if recursive option are passed) and write it to an output directory,
13+
* if no errors are thrown it completed successfully.
1314
*
1415
* @param directory to transpile.
1516
* @param outputDir to write the transpiled files to.
@@ -46,19 +47,22 @@ export async function transpileFiles(directory: string, outputDir: string, optio
4647
})
4748
]
4849
})
49-
await bundles.write({
50-
format: "commonjs",
51-
sourcemap: true,
52-
dir: outputDir,
53-
exports: "auto"
54-
})
55-
}
50+
]
51+
});
52+
53+
await bundles.write({
54+
format: "commonjs",
55+
sourcemap: true,
56+
dir: outputDir,
57+
exports: "auto"
58+
});
59+
}
5660

57-
// Check if we should transpile all subdirs
58-
if (options?.recursive === true && dirs.length > 0) {
59-
for (const subdir of dirs) {
60-
const subdirPath = Path.parse(subdir);
61-
await transpileFiles(subdir, Path.resolve(outputDir, subdirPath.base), options);
62-
}
61+
// Check if we should transpile all subdirs
62+
if (options?.recursive === true && dirs.length > 0) {
63+
for (const subdir of dirs) {
64+
const subdirPath = Path.parse(subdir);
65+
await transpileFiles(subdir, Path.resolve(outputDir, subdirPath.base), options);
6366
}
67+
}
6468
}

src/utils/isJsFile.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const ALLOWED_EXTS = ['js', 'jsx', 'cjs'];
1+
const ALLOWED_EXTS = ['js', 'jsx', 'cjs', 'tsx'];
22

33
/**
4-
* Function which checks if file is JS file
4+
* Function which checks if file is JS file that supports JSX syntax
5+
*
56
* @private
67
* @param {string} filename
78
* @returns {boolean}

0 commit comments

Comments
 (0)