@biorate/hygen 0.5.2 → 0.8.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/README.md +14 -14
- package/dist/cjs/src/config-resolver.js +41 -1
- package/dist/cjs/src/errors.js +9 -1
- package/dist/cjs/src/hygen-config.js +58 -0
- package/dist/cjs/src/index.js +3 -1
- package/dist/esm/src/config-resolver.js +41 -2
- package/dist/esm/src/errors.js +7 -0
- package/dist/esm/src/hygen-config.js +54 -0
- package/dist/esm/src/index.js +1 -0
- package/dist/types/src/config-resolver.d.ts +3 -1
- package/dist/types/src/errors.d.ts +3 -0
- package/dist/types/src/hygen-config.d.ts +13 -0
- package/dist/types/src/index.d.ts +2 -1
- package/dist/types/src/types/config.d.ts +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -116,20 +116,20 @@ For the full API reference see the [typedoc](https://biorate.github.io/core/modu
|
|
|
116
116
|
|
|
117
117
|
The complete user guide lives in the package's local `docs/` pages. README is for the overview, quick start, and embedding; `docs/` is the full guide; typedoc is the generated API reference.
|
|
118
118
|
|
|
119
|
-
| Page | Contents
|
|
120
|
-
| ---------------------------------------- |
|
|
121
|
-
| [quick-start](./docs/quick-start.md) | CLI installation, `init`, generator creation, `--version`.
|
|
122
|
-
| [templates](./docs/templates.md) | Template & frontmatter reference: `add`, `inject`, `sh`, anchors, `replace`, escaping.
|
|
123
|
-
| [generators](./docs/generators.md) | Building and organizing reusable generators.
|
|
124
|
-
| [prompts](./docs/prompts.md) | Prompt hooks reference: file names, `params`/`prompt`/array forms, filtering, TS.
|
|
125
|
-
| [extensibility](./docs/extensibility.md) | Extending hygen via the project config file: helpers, logger, template location, shell executor; action hook classes, the declarative `params` schema and `argCase` flag normalization. |
|
|
126
|
-
| [packages](./docs/packages.md) | Sharing compiled generators as publishable packages (`hygen-add`).
|
|
127
|
-
| [create](./docs/create.md) | Turning existing code into a generator (`hygen-create`).
|
|
128
|
-
| [faq](./docs/faq.md) | Why hygen and its position among generator toolkits.
|
|
129
|
-
| [express](./docs/express.md) | Express.js app generation pattern.
|
|
130
|
-
| [redux](./docs/redux.md) | Redux (ducks) app generation pattern.
|
|
131
|
-
| [react-native](./docs/react-native.md) | React Native app generation pattern.
|
|
132
|
-
| [standalone](./docs/standalone.md) | Standalone binary distribution.
|
|
119
|
+
| Page | Contents |
|
|
120
|
+
| ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
121
|
+
| [quick-start](./docs/quick-start.md) | CLI installation, `init`, generator creation, `--version`. |
|
|
122
|
+
| [templates](./docs/templates.md) | Template & frontmatter reference: `add`, `inject`, `sh`, anchors, `replace`, escaping. |
|
|
123
|
+
| [generators](./docs/generators.md) | Building and organizing reusable generators. |
|
|
124
|
+
| [prompts](./docs/prompts.md) | Prompt hooks reference: file names, `params`/`prompt`/array forms, filtering, TS. |
|
|
125
|
+
| [extensibility](./docs/extensibility.md) | Extending hygen via the project config file: helpers, logger, template location, shell executor; the `HygenConfig` base class (hooks as prototype methods, helpers as property/getter/factory); action hook classes, the declarative `params` schema and `argCase` flag normalization. |
|
|
126
|
+
| [packages](./docs/packages.md) | Sharing compiled generators as publishable packages (`hygen-add`). |
|
|
127
|
+
| [create](./docs/create.md) | Turning existing code into a generator (`hygen-create`). |
|
|
128
|
+
| [faq](./docs/faq.md) | Why hygen and its position among generator toolkits. |
|
|
129
|
+
| [express](./docs/express.md) | Express.js app generation pattern. |
|
|
130
|
+
| [redux](./docs/redux.md) | Redux (ducks) app generation pattern. |
|
|
131
|
+
| [react-native](./docs/react-native.md) | React Native app generation pattern. |
|
|
132
|
+
| [standalone](./docs/standalone.md) | Standalone binary distribution. |
|
|
133
133
|
|
|
134
134
|
## Differences from upstream
|
|
135
135
|
|
|
@@ -26,20 +26,60 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.normalizeProjectConfig = void 0;
|
|
29
30
|
const path_1 = __importDefault(require("path"));
|
|
30
31
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
32
|
+
const hygen_config_1 = require("./hygen-config");
|
|
31
33
|
const config_1 = require("./config");
|
|
32
34
|
const errors_1 = require("./errors");
|
|
33
35
|
const ts_node_register_1 = __importDefault(require("./ts-node-register"));
|
|
34
36
|
const constants_1 = require("./constants");
|
|
37
|
+
let resolvedConfigFile;
|
|
35
38
|
const configResolver = new config_1.ConfigResolver(constants_1.CONFIG_FILES, {
|
|
36
39
|
exists: (f) => fs_extra_1.default.pathExists(f),
|
|
37
40
|
load: async (f) => {
|
|
38
41
|
await (0, ts_node_register_1.default)(f, errors_1.ConfigTsNodeError);
|
|
42
|
+
resolvedConfigFile = f;
|
|
39
43
|
return await Promise.resolve(`${f}`).then(s => __importStar(require(s)));
|
|
40
44
|
},
|
|
41
45
|
none: (_) => ({}),
|
|
42
46
|
});
|
|
47
|
+
const PROJECT_CONFIG_KEYS = ['templates', 'argCase', 'helpers', 'hooks'];
|
|
48
|
+
const normalizeProjectConfig = (mod, file, logger) => {
|
|
49
|
+
const named = Object.keys(mod).filter((key) => key !== 'default');
|
|
50
|
+
if (named.length > 0) {
|
|
51
|
+
return Object.fromEntries(named.map((key) => [key, mod[key]]));
|
|
52
|
+
}
|
|
53
|
+
const raw = mod.default;
|
|
54
|
+
if (raw === undefined || raw === null)
|
|
55
|
+
return {};
|
|
56
|
+
if (typeof raw === 'object' && !Array.isArray(raw))
|
|
57
|
+
return raw;
|
|
58
|
+
if (typeof raw !== 'function') {
|
|
59
|
+
logger.warn(`Ignoring unsupported default export of project config '${file}': expected an object or a class.`);
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
let instance;
|
|
63
|
+
try {
|
|
64
|
+
instance = new raw();
|
|
65
|
+
}
|
|
66
|
+
catch (cause) {
|
|
67
|
+
throw new errors_1.ConfigClassError(file, cause);
|
|
68
|
+
}
|
|
69
|
+
if (instance instanceof hygen_config_1.HygenConfig) {
|
|
70
|
+
return instance.toRunnerConfig();
|
|
71
|
+
}
|
|
72
|
+
const own = Object.keys(instance);
|
|
73
|
+
for (const key of own) {
|
|
74
|
+
if (!PROJECT_CONFIG_KEYS.includes(key)) {
|
|
75
|
+
logger.warn(`Ignoring unknown project config property '${key}' in '${file}' (known: ${PROJECT_CONFIG_KEYS.join(', ')}).`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return Object.fromEntries(own
|
|
79
|
+
.filter((key) => PROJECT_CONFIG_KEYS.includes(key))
|
|
80
|
+
.map((key) => [key, instance[key]]));
|
|
81
|
+
};
|
|
82
|
+
exports.normalizeProjectConfig = normalizeProjectConfig;
|
|
43
83
|
const resolve = (cwd, defaultTemplates, templatesOverride) => {
|
|
44
84
|
return [
|
|
45
85
|
templatesOverride && path_1.default.resolve(cwd, templatesOverride),
|
|
@@ -54,6 +94,6 @@ exports.default = async (config) => {
|
|
|
54
94
|
return {
|
|
55
95
|
...config,
|
|
56
96
|
templates: resolvedTemplates,
|
|
57
|
-
...(await configResolver.resolve(cwd)),
|
|
97
|
+
...normalizeProjectConfig((await configResolver.resolve(cwd)), resolvedConfigFile ?? path_1.default.join(cwd, constants_1.CONFIG_FILES[0]), config.logger),
|
|
58
98
|
};
|
|
59
99
|
};
|
package/dist/cjs/src/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ParamUnknownTypeError = exports.ParamRequiredError = exports.ParamCoercionError = exports.NameFlagRemovedError = exports.CliArgumentError = exports.SetupRepositoryError = exports.UnknownTransformError = exports.HookModuleError = exports.HookTsNodeError = exports.ConfigTsNodeError = exports.GlobMirrorConflictError = exports.PathMacroResolutionError = exports.ShellCommandError = exports.TemplateConfigError = exports.InjectionAnchorNotFoundError = exports.InjectionTargetNotFoundError = exports.TemplateNotFoundError = exports.TemplateRenderError = exports.KeepGoingError = exports.ShowHelpError = void 0;
|
|
3
|
+
exports.ParamUnknownTypeError = exports.ParamRequiredError = exports.ParamCoercionError = exports.NameFlagRemovedError = exports.CliArgumentError = exports.SetupRepositoryError = exports.UnknownTransformError = exports.HookModuleError = exports.HookTsNodeError = exports.ConfigClassError = exports.ConfigTsNodeError = exports.GlobMirrorConflictError = exports.PathMacroResolutionError = exports.ShellCommandError = exports.TemplateConfigError = exports.InjectionAnchorNotFoundError = exports.InjectionTargetNotFoundError = exports.TemplateNotFoundError = exports.TemplateRenderError = exports.KeepGoingError = exports.ShowHelpError = void 0;
|
|
4
4
|
const errors_1 = require("@biorate/errors");
|
|
5
5
|
class ShowHelpError extends errors_1.BaseError {
|
|
6
6
|
constructor(message) {
|
|
@@ -83,6 +83,14 @@ class ConfigTsNodeError extends errors_1.BaseError {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
exports.ConfigTsNodeError = ConfigTsNodeError;
|
|
86
|
+
class ConfigClassError extends errors_1.BaseError {
|
|
87
|
+
constructor(file, cause) {
|
|
88
|
+
super('Project config [%s] default-exports a class that could not be instantiated ' +
|
|
89
|
+
'without constructor arguments (error: [%s]). The config class must have a ' +
|
|
90
|
+
'parameterless constructor.', [file, cause?.message ?? cause]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.ConfigClassError = ConfigClassError;
|
|
86
94
|
class HookTsNodeError extends errors_1.BaseError {
|
|
87
95
|
constructor(file, cause) {
|
|
88
96
|
super('TypeScript hook [%s] requires ts-node: install it with `npm i -D ts-node` (error: [%s])', [file, cause?.message ?? cause]);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HygenConfig = void 0;
|
|
4
|
+
class HygenConfig {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.templates = undefined;
|
|
7
|
+
this.argCase = 'keep';
|
|
8
|
+
this.localsDefaults = undefined;
|
|
9
|
+
if (hygenHelpersProvidedOnPrototype(this))
|
|
10
|
+
return;
|
|
11
|
+
this.helpers = undefined;
|
|
12
|
+
}
|
|
13
|
+
beforeAll(_ctx) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
beforeEach(_ctx) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
afterEach(_ctx, _results) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
afterAll(_ctx, _results) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
toRunnerConfig() {
|
|
26
|
+
const hooks = {};
|
|
27
|
+
const hookNames = ['beforeAll', 'beforeEach', 'afterEach', 'afterAll'];
|
|
28
|
+
for (const name of hookNames) {
|
|
29
|
+
const method = this[name];
|
|
30
|
+
if (method !== HygenConfig.prototype[name] && typeof method === 'function') {
|
|
31
|
+
hooks[name] = method.bind(this);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
let { helpers } = this;
|
|
35
|
+
if (typeof helpers === 'function') {
|
|
36
|
+
helpers = helpers.bind(this);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
...(this.templates !== undefined ? { templates: this.templates } : {}),
|
|
40
|
+
argCase: this.argCase,
|
|
41
|
+
...(this.localsDefaults !== undefined
|
|
42
|
+
? { localsDefaults: this.localsDefaults }
|
|
43
|
+
: {}),
|
|
44
|
+
...(helpers !== undefined ? { helpers } : {}),
|
|
45
|
+
...(Object.keys(hooks).length > 0 ? { hooks } : {}),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.HygenConfig = HygenConfig;
|
|
50
|
+
const hygenHelpersProvidedOnPrototype = (instance) => {
|
|
51
|
+
let proto = Object.getPrototypeOf(instance);
|
|
52
|
+
while (proto && proto !== HygenConfig.prototype && proto !== Object.prototype) {
|
|
53
|
+
if (Object.getOwnPropertyDescriptor(proto, 'helpers'))
|
|
54
|
+
return true;
|
|
55
|
+
proto = Object.getPrototypeOf(proto);
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
};
|
package/dist/cjs/src/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.errors = exports.Logger = exports.VERSION = exports.availableActions = exports.printHelp = exports.resolve = exports.engine = exports.runner = void 0;
|
|
29
|
+
exports.HygenConfig = exports.errors = exports.Logger = exports.VERSION = exports.availableActions = exports.printHelp = exports.resolve = exports.engine = exports.runner = void 0;
|
|
30
30
|
var runner_1 = require("./runner");
|
|
31
31
|
Object.defineProperty(exports, "runner", { enumerable: true, get: function () { return runner_1.runner; } });
|
|
32
32
|
var engine_1 = require("./engine");
|
|
@@ -40,3 +40,5 @@ Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () {
|
|
|
40
40
|
var logger_1 = require("./logger");
|
|
41
41
|
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return __importDefault(logger_1).default; } });
|
|
42
42
|
exports.errors = __importStar(require("./errors"));
|
|
43
|
+
var hygen_config_1 = require("./hygen-config");
|
|
44
|
+
Object.defineProperty(exports, "HygenConfig", { enumerable: true, get: function () { return hygen_config_1.HygenConfig; } });
|
|
@@ -1,17 +1,55 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import fs from 'fs-extra';
|
|
3
|
+
import { HygenConfig } from './hygen-config.js';
|
|
3
4
|
import { ConfigResolver } from './config.js';
|
|
4
|
-
import { ConfigTsNodeError } from './errors.js';
|
|
5
|
+
import { ConfigClassError, ConfigTsNodeError } from './errors.js';
|
|
5
6
|
import registerTsNode from './ts-node-register.js';
|
|
6
7
|
import { CONFIG_FILES } from './constants/index.js';
|
|
8
|
+
let resolvedConfigFile;
|
|
7
9
|
const configResolver = new ConfigResolver(CONFIG_FILES, {
|
|
8
10
|
exists: (f) => fs.pathExists(f),
|
|
9
11
|
load: async (f) => {
|
|
10
12
|
await registerTsNode(f, ConfigTsNodeError);
|
|
13
|
+
resolvedConfigFile = f;
|
|
11
14
|
return await import(f);
|
|
12
15
|
},
|
|
13
16
|
none: (_) => ({}),
|
|
14
17
|
});
|
|
18
|
+
const PROJECT_CONFIG_KEYS = ['templates', 'argCase', 'helpers', 'hooks'];
|
|
19
|
+
const normalizeProjectConfig = (mod, file, logger) => {
|
|
20
|
+
const named = Object.keys(mod).filter((key) => key !== 'default');
|
|
21
|
+
if (named.length > 0) {
|
|
22
|
+
return Object.fromEntries(named.map((key) => [key, mod[key]]));
|
|
23
|
+
}
|
|
24
|
+
const raw = mod.default;
|
|
25
|
+
if (raw === undefined || raw === null)
|
|
26
|
+
return {};
|
|
27
|
+
if (typeof raw === 'object' && !Array.isArray(raw))
|
|
28
|
+
return raw;
|
|
29
|
+
if (typeof raw !== 'function') {
|
|
30
|
+
logger.warn(`Ignoring unsupported default export of project config '${file}': expected an object or a class.`);
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
let instance;
|
|
34
|
+
try {
|
|
35
|
+
instance = new raw();
|
|
36
|
+
}
|
|
37
|
+
catch (cause) {
|
|
38
|
+
throw new ConfigClassError(file, cause);
|
|
39
|
+
}
|
|
40
|
+
if (instance instanceof HygenConfig) {
|
|
41
|
+
return instance.toRunnerConfig();
|
|
42
|
+
}
|
|
43
|
+
const own = Object.keys(instance);
|
|
44
|
+
for (const key of own) {
|
|
45
|
+
if (!PROJECT_CONFIG_KEYS.includes(key)) {
|
|
46
|
+
logger.warn(`Ignoring unknown project config property '${key}' in '${file}' (known: ${PROJECT_CONFIG_KEYS.join(', ')}).`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return Object.fromEntries(own
|
|
50
|
+
.filter((key) => PROJECT_CONFIG_KEYS.includes(key))
|
|
51
|
+
.map((key) => [key, instance[key]]));
|
|
52
|
+
};
|
|
15
53
|
const resolve = (cwd, defaultTemplates, templatesOverride) => {
|
|
16
54
|
return [
|
|
17
55
|
templatesOverride && path.resolve(cwd, templatesOverride),
|
|
@@ -20,12 +58,13 @@ const resolve = (cwd, defaultTemplates, templatesOverride) => {
|
|
|
20
58
|
defaultTemplates && path.resolve(cwd, defaultTemplates),
|
|
21
59
|
].find((_) => _ && fs.existsSync(_));
|
|
22
60
|
};
|
|
61
|
+
export { normalizeProjectConfig };
|
|
23
62
|
export default async (config) => {
|
|
24
63
|
const { cwd, templates: defaultTemplates, templatesOverride } = config;
|
|
25
64
|
const resolvedTemplates = resolve(cwd, defaultTemplates, templatesOverride);
|
|
26
65
|
return {
|
|
27
66
|
...config,
|
|
28
67
|
templates: resolvedTemplates,
|
|
29
|
-
...(await configResolver.resolve(cwd)),
|
|
68
|
+
...normalizeProjectConfig((await configResolver.resolve(cwd)), resolvedConfigFile ?? path.join(cwd, CONFIG_FILES[0]), config.logger),
|
|
30
69
|
};
|
|
31
70
|
};
|
package/dist/esm/src/errors.js
CHANGED
|
@@ -69,6 +69,13 @@ export class ConfigTsNodeError extends BaseError {
|
|
|
69
69
|
super('TypeScript config [%s] requires ts-node: install it with `npm i -D ts-node` (error: [%s])', [file, cause?.message ?? cause]);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
+
export class ConfigClassError extends BaseError {
|
|
73
|
+
constructor(file, cause) {
|
|
74
|
+
super('Project config [%s] default-exports a class that could not be instantiated ' +
|
|
75
|
+
'without constructor arguments (error: [%s]). The config class must have a ' +
|
|
76
|
+
'parameterless constructor.', [file, cause?.message ?? cause]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
72
79
|
export class HookTsNodeError extends BaseError {
|
|
73
80
|
constructor(file, cause) {
|
|
74
81
|
super('TypeScript hook [%s] requires ts-node: install it with `npm i -D ts-node` (error: [%s])', [file, cause?.message ?? cause]);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export class HygenConfig {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.templates = undefined;
|
|
4
|
+
this.argCase = 'keep';
|
|
5
|
+
this.localsDefaults = undefined;
|
|
6
|
+
if (hygenHelpersProvidedOnPrototype(this))
|
|
7
|
+
return;
|
|
8
|
+
this.helpers = undefined;
|
|
9
|
+
}
|
|
10
|
+
beforeAll(_ctx) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
beforeEach(_ctx) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
afterEach(_ctx, _results) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
afterAll(_ctx, _results) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
toRunnerConfig() {
|
|
23
|
+
const hooks = {};
|
|
24
|
+
const hookNames = ['beforeAll', 'beforeEach', 'afterEach', 'afterAll'];
|
|
25
|
+
for (const name of hookNames) {
|
|
26
|
+
const method = this[name];
|
|
27
|
+
if (method !== HygenConfig.prototype[name] && typeof method === 'function') {
|
|
28
|
+
hooks[name] = method.bind(this);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
let { helpers } = this;
|
|
32
|
+
if (typeof helpers === 'function') {
|
|
33
|
+
helpers = helpers.bind(this);
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
...(this.templates !== undefined ? { templates: this.templates } : {}),
|
|
37
|
+
argCase: this.argCase,
|
|
38
|
+
...(this.localsDefaults !== undefined
|
|
39
|
+
? { localsDefaults: this.localsDefaults }
|
|
40
|
+
: {}),
|
|
41
|
+
...(helpers !== undefined ? { helpers } : {}),
|
|
42
|
+
...(Object.keys(hooks).length > 0 ? { hooks } : {}),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const hygenHelpersProvidedOnPrototype = (instance) => {
|
|
47
|
+
let proto = Object.getPrototypeOf(instance);
|
|
48
|
+
while (proto && proto !== HygenConfig.prototype && proto !== Object.prototype) {
|
|
49
|
+
if (Object.getOwnPropertyDescriptor(proto, 'helpers'))
|
|
50
|
+
return true;
|
|
51
|
+
proto = Object.getPrototypeOf(proto);
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
};
|
package/dist/esm/src/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import type { RunnerConfig } from './types';
|
|
1
|
+
import type { Logger, RunnerConfig } from './types';
|
|
2
|
+
declare const normalizeProjectConfig: (mod: Record<string, unknown>, file: string, logger: Logger) => Record<string, unknown>;
|
|
3
|
+
export { normalizeProjectConfig };
|
|
2
4
|
declare const _default: (config: RunnerConfig) => Promise<RunnerConfig>;
|
|
3
5
|
export default _default;
|
|
@@ -36,6 +36,9 @@ export declare class GlobMirrorConflictError extends BaseError {
|
|
|
36
36
|
export declare class ConfigTsNodeError extends BaseError {
|
|
37
37
|
constructor(file: string, cause: unknown);
|
|
38
38
|
}
|
|
39
|
+
export declare class ConfigClassError extends BaseError {
|
|
40
|
+
constructor(file: string, cause: unknown);
|
|
41
|
+
}
|
|
39
42
|
export declare class HookTsNodeError extends BaseError {
|
|
40
43
|
constructor(file: string, cause: unknown);
|
|
41
44
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Helpers, ProjectConfig, RunnerContextConfig } from './types';
|
|
2
|
+
export declare abstract class HygenConfig {
|
|
3
|
+
templates: string | undefined;
|
|
4
|
+
argCase: 'keep' | 'upper-underscore';
|
|
5
|
+
localsDefaults: Record<string, unknown> | undefined;
|
|
6
|
+
helpers?: Helpers | ((locals: Record<string, unknown>, config: RunnerContextConfig) => Helpers);
|
|
7
|
+
constructor();
|
|
8
|
+
beforeAll(_ctx: import('./types').HookContext): unknown;
|
|
9
|
+
beforeEach(_ctx: import('./types').HookContext): unknown;
|
|
10
|
+
afterEach(_ctx: import('./types').HookContext, _results: import('./types').ActionResult[]): unknown;
|
|
11
|
+
afterAll(_ctx: import('./types').HookContext, _results: import('./types').ActionResult[]): unknown;
|
|
12
|
+
toRunnerConfig(): Partial<ProjectConfig>;
|
|
13
|
+
}
|
|
@@ -4,4 +4,5 @@ export { default as resolve } from './config-resolver';
|
|
|
4
4
|
export { printHelp, availableActions, VERSION } from './help';
|
|
5
5
|
export { default as Logger } from './logger';
|
|
6
6
|
export * as errors from './errors';
|
|
7
|
-
export type { ParamDescriptor, ParamType, ParamsSchema } from './types';
|
|
7
|
+
export type { ParamDescriptor, ParamType, ParamsSchema, ProjectConfig, RunnerContextConfig, } from './types';
|
|
8
|
+
export { HygenConfig } from './hygen-config';
|
|
@@ -2,6 +2,8 @@ import type { Logger } from './logger';
|
|
|
2
2
|
import type { Helpers, Transforms } from './helpers-ns';
|
|
3
3
|
import type { Prompter } from './prompter';
|
|
4
4
|
import type { ProjectHooks } from './hooks';
|
|
5
|
+
export interface ProjectConfig extends Pick<RunnerConfig, 'templates' | 'argCase' | 'helpers' | 'hooks'> {
|
|
6
|
+
}
|
|
5
7
|
export interface RunnerConfig {
|
|
6
8
|
exec: (sh: string, body: string) => void;
|
|
7
9
|
templates?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@biorate/hygen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
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": "fb3bd01484f1e1a8f75df527450033f137ed05bb"
|
|
84
84
|
}
|