@biorate/hygen 0.8.0 → 0.8.1
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.
|
@@ -29,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.normalizeProjectConfig = void 0;
|
|
30
30
|
const path_1 = __importDefault(require("path"));
|
|
31
31
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
32
|
-
const hygen_config_1 = require("./hygen-config");
|
|
33
32
|
const config_1 = require("./config");
|
|
34
33
|
const errors_1 = require("./errors");
|
|
35
34
|
const ts_node_register_1 = __importDefault(require("./ts-node-register"));
|
|
@@ -45,8 +44,9 @@ const configResolver = new config_1.ConfigResolver(constants_1.CONFIG_FILES, {
|
|
|
45
44
|
none: (_) => ({}),
|
|
46
45
|
});
|
|
47
46
|
const PROJECT_CONFIG_KEYS = ['templates', 'argCase', 'helpers', 'hooks'];
|
|
47
|
+
const INTEROP_KEYS = ['__esModule'];
|
|
48
48
|
const normalizeProjectConfig = (mod, file, logger) => {
|
|
49
|
-
const named = Object.keys(mod).filter((key) => key !== 'default');
|
|
49
|
+
const named = Object.keys(mod).filter((key) => key !== 'default' && !INTEROP_KEYS.includes(key));
|
|
50
50
|
if (named.length > 0) {
|
|
51
51
|
return Object.fromEntries(named.map((key) => [key, mod[key]]));
|
|
52
52
|
}
|
|
@@ -66,7 +66,7 @@ const normalizeProjectConfig = (mod, file, logger) => {
|
|
|
66
66
|
catch (cause) {
|
|
67
67
|
throw new errors_1.ConfigClassError(file, cause);
|
|
68
68
|
}
|
|
69
|
-
if (instance
|
|
69
|
+
if (typeof instance.toRunnerConfig === 'function') {
|
|
70
70
|
return instance.toRunnerConfig();
|
|
71
71
|
}
|
|
72
72
|
const own = Object.keys(instance);
|
|
@@ -91,9 +91,18 @@ const resolve = (cwd, defaultTemplates, templatesOverride) => {
|
|
|
91
91
|
exports.default = async (config) => {
|
|
92
92
|
const { cwd, templates: defaultTemplates, templatesOverride } = config;
|
|
93
93
|
const resolvedTemplates = resolve(cwd, defaultTemplates, templatesOverride);
|
|
94
|
+
const project = normalizeProjectConfig((await configResolver.resolve(cwd)), resolvedConfigFile ?? path_1.default.join(cwd, constants_1.CONFIG_FILES[0]), config.logger);
|
|
95
|
+
if (typeof project.templates === 'string' &&
|
|
96
|
+
project.templates !== '' &&
|
|
97
|
+
!path_1.default.isAbsolute(project.templates)) {
|
|
98
|
+
const resolved = path_1.default.resolve(cwd, project.templates);
|
|
99
|
+
if (fs_extra_1.default.existsSync(resolved) && fs_extra_1.default.statSync(resolved).isDirectory()) {
|
|
100
|
+
project.templates = resolved;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
94
103
|
return {
|
|
95
104
|
...config,
|
|
96
105
|
templates: resolvedTemplates,
|
|
97
|
-
...
|
|
106
|
+
...project,
|
|
98
107
|
};
|
|
99
108
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import fs from 'fs-extra';
|
|
3
|
-
import { HygenConfig } from './hygen-config.js';
|
|
4
3
|
import { ConfigResolver } from './config.js';
|
|
5
4
|
import { ConfigClassError, ConfigTsNodeError } from './errors.js';
|
|
6
5
|
import registerTsNode from './ts-node-register.js';
|
|
@@ -16,8 +15,9 @@ const configResolver = new ConfigResolver(CONFIG_FILES, {
|
|
|
16
15
|
none: (_) => ({}),
|
|
17
16
|
});
|
|
18
17
|
const PROJECT_CONFIG_KEYS = ['templates', 'argCase', 'helpers', 'hooks'];
|
|
18
|
+
const INTEROP_KEYS = ['__esModule'];
|
|
19
19
|
const normalizeProjectConfig = (mod, file, logger) => {
|
|
20
|
-
const named = Object.keys(mod).filter((key) => key !== 'default');
|
|
20
|
+
const named = Object.keys(mod).filter((key) => key !== 'default' && !INTEROP_KEYS.includes(key));
|
|
21
21
|
if (named.length > 0) {
|
|
22
22
|
return Object.fromEntries(named.map((key) => [key, mod[key]]));
|
|
23
23
|
}
|
|
@@ -37,7 +37,7 @@ const normalizeProjectConfig = (mod, file, logger) => {
|
|
|
37
37
|
catch (cause) {
|
|
38
38
|
throw new ConfigClassError(file, cause);
|
|
39
39
|
}
|
|
40
|
-
if (instance
|
|
40
|
+
if (typeof instance.toRunnerConfig === 'function') {
|
|
41
41
|
return instance.toRunnerConfig();
|
|
42
42
|
}
|
|
43
43
|
const own = Object.keys(instance);
|
|
@@ -62,9 +62,18 @@ export { normalizeProjectConfig };
|
|
|
62
62
|
export default async (config) => {
|
|
63
63
|
const { cwd, templates: defaultTemplates, templatesOverride } = config;
|
|
64
64
|
const resolvedTemplates = resolve(cwd, defaultTemplates, templatesOverride);
|
|
65
|
+
const project = normalizeProjectConfig((await configResolver.resolve(cwd)), resolvedConfigFile ?? path.join(cwd, CONFIG_FILES[0]), config.logger);
|
|
66
|
+
if (typeof project.templates === 'string' &&
|
|
67
|
+
project.templates !== '' &&
|
|
68
|
+
!path.isAbsolute(project.templates)) {
|
|
69
|
+
const resolved = path.resolve(cwd, project.templates);
|
|
70
|
+
if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) {
|
|
71
|
+
project.templates = resolved;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
65
74
|
return {
|
|
66
75
|
...config,
|
|
67
76
|
templates: resolvedTemplates,
|
|
68
|
-
...
|
|
77
|
+
...project,
|
|
69
78
|
};
|
|
70
79
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@biorate/hygen",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "The scalable code generator that saves you time. Fork of jondot/hygen",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"template",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"@types/inflection": "1.13.0",
|
|
81
81
|
"@types/yargs-parser": "21.0.3"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "4919387bf46e9d7dfec89fc3d65308cb71b3d410"
|
|
84
84
|
}
|