@omnifyjp/omnify 3.2.11 → 3.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnifyjp/omnify",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Schema-driven code generation for Laravel, TypeScript, and SQL",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"zod": "^3.24.0"
|
|
37
37
|
},
|
|
38
38
|
"optionalDependencies": {
|
|
39
|
-
"@omnifyjp/omnify-darwin-arm64": "3.
|
|
40
|
-
"@omnifyjp/omnify-darwin-x64": "3.
|
|
41
|
-
"@omnifyjp/omnify-linux-x64": "3.
|
|
42
|
-
"@omnifyjp/omnify-linux-arm64": "3.
|
|
43
|
-
"@omnifyjp/omnify-win32-x64": "3.
|
|
39
|
+
"@omnifyjp/omnify-darwin-arm64": "3.3.0",
|
|
40
|
+
"@omnifyjp/omnify-darwin-x64": "3.3.0",
|
|
41
|
+
"@omnifyjp/omnify-linux-x64": "3.3.0",
|
|
42
|
+
"@omnifyjp/omnify-linux-arm64": "3.3.0",
|
|
43
|
+
"@omnifyjp/omnify-win32-x64": "3.3.0"
|
|
44
44
|
}
|
|
45
45
|
}
|
package/ts-dist/cli.js
CHANGED
|
@@ -47,6 +47,7 @@ function resolveFromConfig(configPath) {
|
|
|
47
47
|
const laravelConfig = config.codegen?.laravel;
|
|
48
48
|
const laravelEnabled = laravelConfig?.enable === true;
|
|
49
49
|
const laravelOverrides = laravelEnabled ? {
|
|
50
|
+
rootPath: laravelConfig?.rootPath,
|
|
50
51
|
structure: laravelConfig?.structure,
|
|
51
52
|
model: laravelConfig?.model,
|
|
52
53
|
request: laravelConfig?.request,
|
|
@@ -57,6 +58,7 @@ function resolveFromConfig(configPath) {
|
|
|
57
58
|
controller: laravelConfig?.controller,
|
|
58
59
|
service: laravelConfig?.service,
|
|
59
60
|
route: laravelConfig?.route,
|
|
61
|
+
config: laravelConfig?.config,
|
|
60
62
|
nestedset: laravelConfig?.nestedset,
|
|
61
63
|
} : undefined;
|
|
62
64
|
return {
|
|
@@ -13,7 +13,7 @@ export function generateFileCleanup(reader, config) {
|
|
|
13
13
|
return [];
|
|
14
14
|
const modelNamespace = config.models.namespace;
|
|
15
15
|
const purgeHours = parseDurationHours(fileConfig.purgeAfter ?? '72h');
|
|
16
|
-
return [generateCommand(modelNamespace, purgeHours)];
|
|
16
|
+
return [generateCommand(modelNamespace, purgeHours, config)];
|
|
17
17
|
}
|
|
18
18
|
/** Parse a duration string like "72h" or "3d" to hours. */
|
|
19
19
|
function parseDurationHours(duration) {
|
|
@@ -24,7 +24,7 @@ function parseDurationHours(duration) {
|
|
|
24
24
|
const unit = match[2];
|
|
25
25
|
return unit === 'd' ? value * 24 : value;
|
|
26
26
|
}
|
|
27
|
-
function generateCommand(modelNamespace, purgeHours) {
|
|
27
|
+
function generateCommand(modelNamespace, purgeHours, config) {
|
|
28
28
|
const content = `<?php
|
|
29
29
|
|
|
30
30
|
namespace App\\Console\\Commands;
|
|
@@ -153,5 +153,8 @@ class CleanupFiles extends Command
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
`;
|
|
156
|
-
|
|
156
|
+
const path = config.rootPath
|
|
157
|
+
? `${config.rootPath}/app/Console/Commands/CleanupFiles.php`
|
|
158
|
+
: 'app/Console/Commands/CleanupFiles.php';
|
|
159
|
+
return baseFile(path, content);
|
|
157
160
|
}
|
|
@@ -22,7 +22,7 @@ export function generateSchemaConfig(reader, config) {
|
|
|
22
22
|
return [
|
|
23
23
|
${entries.join('\n')}];
|
|
24
24
|
`;
|
|
25
|
-
return [baseFile(
|
|
25
|
+
return [baseFile(config.configFile.path, content)];
|
|
26
26
|
}
|
|
27
27
|
function generateSchemaEntry(name, schema, reader, config) {
|
|
28
28
|
const modelName = toPascalCase(name);
|
package/ts-dist/php/types.d.ts
CHANGED
|
@@ -49,6 +49,13 @@ export interface NestedSetOverride {
|
|
|
49
49
|
}
|
|
50
50
|
/** Overrides from codegen.laravel YAML config (all optional). */
|
|
51
51
|
export interface LaravelCodegenOverrides {
|
|
52
|
+
/**
|
|
53
|
+
* Filesystem prefix applied to ALL generated paths (defaults + explicit overrides
|
|
54
|
+
* that are not already absolute). Use this for monorepo setups where the Laravel
|
|
55
|
+
* project lives in a subdirectory, e.g. `rootPath: backend` makes everything
|
|
56
|
+
* write under `backend/app/...`, `backend/config/...`, etc.
|
|
57
|
+
*/
|
|
58
|
+
rootPath?: string;
|
|
52
59
|
structure?: 'legacy' | 'modular';
|
|
53
60
|
model?: LaravelPathOverride;
|
|
54
61
|
request?: LaravelPathOverride;
|
|
@@ -59,10 +66,13 @@ export interface LaravelCodegenOverrides {
|
|
|
59
66
|
controller?: LaravelPathOverride;
|
|
60
67
|
service?: LaravelPathOverride;
|
|
61
68
|
route?: LaravelPathOverride;
|
|
69
|
+
config?: LaravelPathOverride;
|
|
62
70
|
nestedset?: NestedSetOverride;
|
|
63
71
|
}
|
|
64
72
|
/** PHP codegen configuration (resolved with defaults). */
|
|
65
73
|
export interface PhpConfig {
|
|
74
|
+
/** Filesystem prefix applied to all generated paths. Empty when not set. */
|
|
75
|
+
rootPath: string;
|
|
66
76
|
structure: 'legacy' | 'modular';
|
|
67
77
|
modulesPath: string;
|
|
68
78
|
models: {
|
|
@@ -112,6 +122,10 @@ export interface PhpConfig {
|
|
|
112
122
|
routes: {
|
|
113
123
|
path: string;
|
|
114
124
|
};
|
|
125
|
+
/** Path to the omnify-schemas.php config file (full path including filename). */
|
|
126
|
+
configFile: {
|
|
127
|
+
path: string;
|
|
128
|
+
};
|
|
115
129
|
nestedset: {
|
|
116
130
|
namespace: string;
|
|
117
131
|
};
|
package/ts-dist/php/types.js
CHANGED
|
@@ -27,7 +27,7 @@ export function resolveModularBasePath(config, schemaName, category, fileName, l
|
|
|
27
27
|
*/
|
|
28
28
|
export function resolveModularBaseNamespace(config, schemaName, category, legacyNamespace) {
|
|
29
29
|
if (config.structure === 'modular') {
|
|
30
|
-
return pathToNamespace(`${config.modulesPath}/${schemaName}/${category}`);
|
|
30
|
+
return pathToNamespace(`${stripRootPath(config, config.modulesPath)}/${schemaName}/${category}`);
|
|
31
31
|
}
|
|
32
32
|
return legacyNamespace;
|
|
33
33
|
}
|
|
@@ -49,10 +49,20 @@ export function resolveSharedBasePath(config, category, fileName, legacyPath) {
|
|
|
49
49
|
*/
|
|
50
50
|
export function resolveSharedBaseNamespace(config, category, legacyNamespace) {
|
|
51
51
|
if (config.structure === 'modular') {
|
|
52
|
-
return pathToNamespace(`${config.modulesPath}/Shared/${category}`);
|
|
52
|
+
return pathToNamespace(`${stripRootPath(config, config.modulesPath)}/Shared/${category}`);
|
|
53
53
|
}
|
|
54
54
|
return legacyNamespace;
|
|
55
55
|
}
|
|
56
|
+
/** Strip the configured rootPath prefix from a filesystem path. */
|
|
57
|
+
function stripRootPath(config, p) {
|
|
58
|
+
if (!config.rootPath)
|
|
59
|
+
return p;
|
|
60
|
+
if (p === config.rootPath)
|
|
61
|
+
return '';
|
|
62
|
+
if (p.startsWith(`${config.rootPath}/`))
|
|
63
|
+
return p.slice(config.rootPath.length + 1);
|
|
64
|
+
return p;
|
|
65
|
+
}
|
|
56
66
|
/** Convert a file path to a PHP namespace (e.g., app/Models/Omnify → App\Models\Omnify). */
|
|
57
67
|
function pathToNamespace(p) {
|
|
58
68
|
return p
|
|
@@ -70,32 +80,64 @@ const DEFAULT_POLICY_PATH = 'app/Policies/Omnify';
|
|
|
70
80
|
const DEFAULT_CONTROLLER_PATH = 'app/Http/Controllers';
|
|
71
81
|
const DEFAULT_SERVICE_PATH = 'app/Services';
|
|
72
82
|
const DEFAULT_ROUTE_PATH = 'routes/api/omnify';
|
|
83
|
+
const DEFAULT_CONFIG_FILE_PATH = 'config/omnify-schemas.php';
|
|
84
|
+
const DEFAULT_MODULES_PATH = 'app/Modules';
|
|
85
|
+
/**
|
|
86
|
+
* Apply a rootPath prefix to a path. Absolute paths and paths that already
|
|
87
|
+
* begin with `${rootPath}/` are returned as-is, so users can mix and match
|
|
88
|
+
* if needed.
|
|
89
|
+
*/
|
|
90
|
+
function withRoot(rootPath, p) {
|
|
91
|
+
if (!rootPath)
|
|
92
|
+
return p;
|
|
93
|
+
if (p.startsWith('/'))
|
|
94
|
+
return p;
|
|
95
|
+
if (p === rootPath || p.startsWith(`${rootPath}/`))
|
|
96
|
+
return p;
|
|
97
|
+
return `${rootPath}/${p}`;
|
|
98
|
+
}
|
|
73
99
|
/**
|
|
74
100
|
* Derive full PHP config from optional overrides.
|
|
75
101
|
* All paths and namespaces fall back to sensible defaults.
|
|
76
102
|
*/
|
|
77
103
|
export function derivePhpConfig(overrides) {
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
const
|
|
104
|
+
// Strip trailing slash for stable join behavior.
|
|
105
|
+
const rootPath = (overrides?.rootPath ?? '').replace(/\/+$/, '');
|
|
106
|
+
// Namespace generation should NOT include the rootPath prefix — it's a
|
|
107
|
+
// filesystem location, not a PHP namespace component.
|
|
108
|
+
const stripRoot = (p) => {
|
|
109
|
+
if (!rootPath)
|
|
110
|
+
return p;
|
|
111
|
+
if (p === rootPath)
|
|
112
|
+
return '';
|
|
113
|
+
if (p.startsWith(`${rootPath}/`))
|
|
114
|
+
return p.slice(rootPath.length + 1);
|
|
115
|
+
return p;
|
|
116
|
+
};
|
|
117
|
+
const nsFromPath = (p) => pathToNamespace(stripRoot(p));
|
|
118
|
+
const modelPath = withRoot(rootPath, overrides?.model?.path ?? DEFAULT_MODEL_PATH);
|
|
119
|
+
const modelNs = overrides?.model?.namespace ?? nsFromPath(modelPath);
|
|
120
|
+
const requestPath = withRoot(rootPath, overrides?.request?.path ?? DEFAULT_REQUEST_PATH);
|
|
121
|
+
const requestNs = overrides?.request?.namespace ?? nsFromPath(requestPath);
|
|
122
|
+
const resourcePath = withRoot(rootPath, overrides?.resource?.path ?? DEFAULT_RESOURCE_PATH);
|
|
123
|
+
const resourceNs = overrides?.resource?.namespace ?? nsFromPath(resourcePath);
|
|
124
|
+
const factoryPath = withRoot(rootPath, overrides?.factory?.path ?? DEFAULT_FACTORY_PATH);
|
|
125
|
+
const factoryNs = overrides?.factory?.namespace ?? nsFromPath(factoryPath);
|
|
126
|
+
const providerPath = withRoot(rootPath, overrides?.provider?.path ?? DEFAULT_PROVIDER_PATH);
|
|
127
|
+
const providerNs = overrides?.provider?.namespace ?? nsFromPath(providerPath);
|
|
128
|
+
const policyPath = withRoot(rootPath, overrides?.policy?.path ?? DEFAULT_POLICY_PATH);
|
|
129
|
+
const policyNs = overrides?.policy?.namespace ?? nsFromPath(policyPath);
|
|
130
|
+
const controllerPath = withRoot(rootPath, overrides?.controller?.path ?? DEFAULT_CONTROLLER_PATH);
|
|
131
|
+
const controllerNs = overrides?.controller?.namespace ?? nsFromPath(controllerPath);
|
|
132
|
+
const servicePath = withRoot(rootPath, overrides?.service?.path ?? DEFAULT_SERVICE_PATH);
|
|
133
|
+
const serviceNs = overrides?.service?.namespace ?? nsFromPath(servicePath);
|
|
134
|
+
const routePath = withRoot(rootPath, overrides?.route?.path ?? DEFAULT_ROUTE_PATH);
|
|
135
|
+
const configFilePath = withRoot(rootPath, overrides?.config?.path ?? DEFAULT_CONFIG_FILE_PATH);
|
|
95
136
|
const nestedsetNs = overrides?.nestedset?.namespace ?? 'Aimeos\\Nestedset';
|
|
96
137
|
const structure = overrides?.structure ?? 'legacy';
|
|
97
|
-
const modulesPath =
|
|
138
|
+
const modulesPath = withRoot(rootPath, DEFAULT_MODULES_PATH);
|
|
98
139
|
return {
|
|
140
|
+
rootPath,
|
|
99
141
|
structure,
|
|
100
142
|
modulesPath,
|
|
101
143
|
models: {
|
|
@@ -145,6 +187,9 @@ export function derivePhpConfig(overrides) {
|
|
|
145
187
|
routes: {
|
|
146
188
|
path: routePath,
|
|
147
189
|
},
|
|
190
|
+
configFile: {
|
|
191
|
+
path: configFilePath,
|
|
192
|
+
},
|
|
148
193
|
nestedset: {
|
|
149
194
|
namespace: nestedsetNs,
|
|
150
195
|
},
|
package/types/config.d.ts
CHANGED
|
@@ -53,6 +53,14 @@ export interface CodegenNestedSetConfig {
|
|
|
53
53
|
export interface CodegenLaravelConfig {
|
|
54
54
|
/** Enable Laravel codegen. Defaults to false. */
|
|
55
55
|
enable: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Filesystem prefix applied to all generated paths. Use this for monorepo
|
|
58
|
+
* setups where the Laravel project lives in a subdirectory, e.g. `backend`
|
|
59
|
+
* makes everything write under `backend/app/...`, `backend/config/...`, etc.
|
|
60
|
+
*/
|
|
61
|
+
rootPath?: string;
|
|
62
|
+
/** Directory layout: "legacy" (default) or "modular". */
|
|
63
|
+
structure?: "legacy" | "modular";
|
|
56
64
|
/** Model output configuration. */
|
|
57
65
|
model?: CodegenLaravelPathConfig;
|
|
58
66
|
/** Request output configuration. */
|
|
@@ -65,6 +73,14 @@ export interface CodegenLaravelConfig {
|
|
|
65
73
|
provider?: CodegenLaravelPathConfig;
|
|
66
74
|
/** Policy output configuration (default: app/Policies/Omnify). */
|
|
67
75
|
policy?: CodegenLaravelPathConfig;
|
|
76
|
+
/** Controller output configuration (default: app/Http/Controllers). */
|
|
77
|
+
controller?: CodegenLaravelPathConfig;
|
|
78
|
+
/** Service output configuration (default: app/Services). */
|
|
79
|
+
service?: CodegenLaravelPathConfig;
|
|
80
|
+
/** Route file output configuration (default: routes/api/omnify). */
|
|
81
|
+
route?: CodegenLaravelPathConfig;
|
|
82
|
+
/** Path for the omnify-schemas.php config file (default: config/omnify-schemas.php). */
|
|
83
|
+
config?: CodegenLaravelPathConfig;
|
|
68
84
|
/** Nested set package configuration. Only applies to schemas with nestedSet: true. */
|
|
69
85
|
nestedset?: CodegenNestedSetConfig;
|
|
70
86
|
}
|