@asyncapi/generator 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/lib/filtersRegistry.js +7 -2
- package/lib/generator.js +0 -2
- package/lib/hooksRegistry.js +4 -1
- package/lib/utils.js +7 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/filtersRegistry.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const xfs = require('fs.extra');
|
|
4
|
-
const { isAsyncFunction } = require('./utils');
|
|
4
|
+
const { isAsyncFunction, registerTypeScript } = require('./utils');
|
|
5
5
|
const nunjucksFilters = require('@asyncapi/nunjucks-filters');
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -38,7 +38,12 @@ function registerLocalFilters(nunjucks, templateDir, filtersDir) {
|
|
|
38
38
|
|
|
39
39
|
walker.on('file', async (root, stats, next) => {
|
|
40
40
|
try {
|
|
41
|
-
const filePath = path.resolve(
|
|
41
|
+
const filePath = path.resolve(
|
|
42
|
+
templateDir,
|
|
43
|
+
path.resolve(root, stats.name)
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
registerTypeScript(filePath);
|
|
42
47
|
// If it's a module constructor, inject dependencies to ensure consistent usage in remote templates in other projects or plain directories.
|
|
43
48
|
delete require.cache[require.resolve(filePath)];
|
|
44
49
|
const mod = require(filePath);
|
package/lib/generator.js
CHANGED
|
@@ -28,7 +28,6 @@ const {
|
|
|
28
28
|
isReactTemplate,
|
|
29
29
|
isJsFile,
|
|
30
30
|
registerSourceMap,
|
|
31
|
-
registerTypeScript,
|
|
32
31
|
getTemplateDetails,
|
|
33
32
|
convertCollectionToObject,
|
|
34
33
|
} = require('./utils');
|
|
@@ -59,7 +58,6 @@ const shouldIgnoreDir = dirPath =>
|
|
|
59
58
|
|| dirPath.startsWith(`.git${path.sep}`);
|
|
60
59
|
|
|
61
60
|
registerSourceMap();
|
|
62
|
-
registerTypeScript();
|
|
63
61
|
|
|
64
62
|
class Generator {
|
|
65
63
|
/**
|
package/lib/hooksRegistry.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const xfs = require('fs.extra');
|
|
3
|
-
const { exists } = require('./utils');
|
|
3
|
+
const { exists, registerTypeScript } = require('./utils');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Registers all template hooks.
|
|
@@ -37,6 +37,9 @@ async function registerLocalHooks(hooks, templateDir, hooksDir) {
|
|
|
37
37
|
walker.on('file', async (root, stats, next) => {
|
|
38
38
|
try {
|
|
39
39
|
const filePath = path.resolve(templateDir, path.resolve(root, stats.name));
|
|
40
|
+
|
|
41
|
+
registerTypeScript(filePath);
|
|
42
|
+
|
|
40
43
|
delete require.cache[require.resolve(filePath)];
|
|
41
44
|
const mod = require(filePath);
|
|
42
45
|
|
package/lib/utils.js
CHANGED
|
@@ -149,7 +149,13 @@ utils.registerSourceMap = () => {
|
|
|
149
149
|
*
|
|
150
150
|
* @private
|
|
151
151
|
*/
|
|
152
|
-
utils.registerTypeScript = () => {
|
|
152
|
+
utils.registerTypeScript = (filePath) => {
|
|
153
|
+
const isTypescriptFile = filePath.endsWith('.ts');
|
|
154
|
+
|
|
155
|
+
if (!isTypescriptFile) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
153
159
|
const { REGISTER_INSTANCE, register } = require('ts-node');
|
|
154
160
|
// if the ts-node has already been registered before, do not register it again.
|
|
155
161
|
// Check the env. TS_NODE_ENV if ts-node started via ts-node-dev package
|