@biorate/hygen 0.6.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.
- package/README.md +14 -14
- package/dist/cjs/src/config-resolver.js +15 -2
- package/dist/cjs/src/hygen-config.js +58 -0
- package/dist/cjs/src/index.js +3 -1
- package/dist/esm/src/config-resolver.js +15 -2
- package/dist/esm/src/hygen-config.js +54 -0
- package/dist/esm/src/index.js +1 -0
- package/dist/types/src/hygen-config.d.ts +13 -0
- package/dist/types/src/index.d.ts +1 -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
|
|
|
@@ -44,8 +44,9 @@ const configResolver = new config_1.ConfigResolver(constants_1.CONFIG_FILES, {
|
|
|
44
44
|
none: (_) => ({}),
|
|
45
45
|
});
|
|
46
46
|
const PROJECT_CONFIG_KEYS = ['templates', 'argCase', 'helpers', 'hooks'];
|
|
47
|
+
const INTEROP_KEYS = ['__esModule'];
|
|
47
48
|
const normalizeProjectConfig = (mod, file, logger) => {
|
|
48
|
-
const named = Object.keys(mod).filter((key) => key !== 'default');
|
|
49
|
+
const named = Object.keys(mod).filter((key) => key !== 'default' && !INTEROP_KEYS.includes(key));
|
|
49
50
|
if (named.length > 0) {
|
|
50
51
|
return Object.fromEntries(named.map((key) => [key, mod[key]]));
|
|
51
52
|
}
|
|
@@ -65,6 +66,9 @@ const normalizeProjectConfig = (mod, file, logger) => {
|
|
|
65
66
|
catch (cause) {
|
|
66
67
|
throw new errors_1.ConfigClassError(file, cause);
|
|
67
68
|
}
|
|
69
|
+
if (typeof instance.toRunnerConfig === 'function') {
|
|
70
|
+
return instance.toRunnerConfig();
|
|
71
|
+
}
|
|
68
72
|
const own = Object.keys(instance);
|
|
69
73
|
for (const key of own) {
|
|
70
74
|
if (!PROJECT_CONFIG_KEYS.includes(key)) {
|
|
@@ -87,9 +91,18 @@ const resolve = (cwd, defaultTemplates, templatesOverride) => {
|
|
|
87
91
|
exports.default = async (config) => {
|
|
88
92
|
const { cwd, templates: defaultTemplates, templatesOverride } = config;
|
|
89
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
|
+
}
|
|
90
103
|
return {
|
|
91
104
|
...config,
|
|
92
105
|
templates: resolvedTemplates,
|
|
93
|
-
...
|
|
106
|
+
...project,
|
|
94
107
|
};
|
|
95
108
|
};
|
|
@@ -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; } });
|
|
@@ -15,8 +15,9 @@ const configResolver = new ConfigResolver(CONFIG_FILES, {
|
|
|
15
15
|
none: (_) => ({}),
|
|
16
16
|
});
|
|
17
17
|
const PROJECT_CONFIG_KEYS = ['templates', 'argCase', 'helpers', 'hooks'];
|
|
18
|
+
const INTEROP_KEYS = ['__esModule'];
|
|
18
19
|
const normalizeProjectConfig = (mod, file, logger) => {
|
|
19
|
-
const named = Object.keys(mod).filter((key) => key !== 'default');
|
|
20
|
+
const named = Object.keys(mod).filter((key) => key !== 'default' && !INTEROP_KEYS.includes(key));
|
|
20
21
|
if (named.length > 0) {
|
|
21
22
|
return Object.fromEntries(named.map((key) => [key, mod[key]]));
|
|
22
23
|
}
|
|
@@ -36,6 +37,9 @@ const normalizeProjectConfig = (mod, file, logger) => {
|
|
|
36
37
|
catch (cause) {
|
|
37
38
|
throw new ConfigClassError(file, cause);
|
|
38
39
|
}
|
|
40
|
+
if (typeof instance.toRunnerConfig === 'function') {
|
|
41
|
+
return instance.toRunnerConfig();
|
|
42
|
+
}
|
|
39
43
|
const own = Object.keys(instance);
|
|
40
44
|
for (const key of own) {
|
|
41
45
|
if (!PROJECT_CONFIG_KEYS.includes(key)) {
|
|
@@ -58,9 +62,18 @@ export { normalizeProjectConfig };
|
|
|
58
62
|
export default async (config) => {
|
|
59
63
|
const { cwd, templates: defaultTemplates, templatesOverride } = config;
|
|
60
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
|
+
}
|
|
61
74
|
return {
|
|
62
75
|
...config,
|
|
63
76
|
templates: resolvedTemplates,
|
|
64
|
-
...
|
|
77
|
+
...project,
|
|
65
78
|
};
|
|
66
79
|
};
|
|
@@ -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
|
@@ -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
|
+
}
|
|
@@ -5,3 +5,4 @@ export { printHelp, availableActions, VERSION } from './help';
|
|
|
5
5
|
export { default as Logger } from './logger';
|
|
6
6
|
export * as errors from './errors';
|
|
7
7
|
export type { ParamDescriptor, ParamType, ParamsSchema, ProjectConfig, RunnerContextConfig, } from './types';
|
|
8
|
+
export { HygenConfig } from './hygen-config';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@biorate/hygen",
|
|
3
|
-
"version": "0.
|
|
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
|
}
|