@omnifyjp/ts 6.8.0 → 6.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/dist/cli.js +0 -0
- package/dist/php/orphan-cleanup.js +55 -23
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
File without changes
|
|
@@ -66,25 +66,26 @@ function collectModularLayerDirs(configDir, config, category) {
|
|
|
66
66
|
return dirs;
|
|
67
67
|
}
|
|
68
68
|
const BASE_SUBDIRS_SKIP = new Set(['Base', 'OmnifyBase']);
|
|
69
|
-
function findEditableSubclassFile(roots, fileName) {
|
|
69
|
+
function findEditableSubclassFile(roots, fileName, excludeAbsPath) {
|
|
70
70
|
for (const root of roots) {
|
|
71
|
-
|
|
71
|
+
const found = findFileAbsolutePath(root, fileName);
|
|
72
|
+
if (found && found !== excludeAbsPath)
|
|
72
73
|
return true;
|
|
73
74
|
}
|
|
74
75
|
return false;
|
|
75
76
|
}
|
|
76
|
-
function
|
|
77
|
+
function findFileAbsolutePath(dir, fileName) {
|
|
77
78
|
if (!existsSync(dir))
|
|
78
|
-
return
|
|
79
|
+
return null;
|
|
79
80
|
let info;
|
|
80
81
|
try {
|
|
81
82
|
info = statSync(dir);
|
|
82
83
|
}
|
|
83
84
|
catch {
|
|
84
|
-
return
|
|
85
|
+
return null;
|
|
85
86
|
}
|
|
86
87
|
if (!info.isDirectory()) {
|
|
87
|
-
return basename(dir) === fileName;
|
|
88
|
+
return basename(dir) === fileName ? resolve(dir) : null;
|
|
88
89
|
}
|
|
89
90
|
for (const entry of readdirSync(dir)) {
|
|
90
91
|
if (BASE_SUBDIRS_SKIP.has(entry))
|
|
@@ -97,14 +98,15 @@ function findFileByName(dir, fileName) {
|
|
|
97
98
|
continue;
|
|
98
99
|
}
|
|
99
100
|
if (info.isDirectory()) {
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
const nested = findFileAbsolutePath(full, fileName);
|
|
102
|
+
if (nested)
|
|
103
|
+
return nested;
|
|
102
104
|
}
|
|
103
105
|
else if (entry === fileName) {
|
|
104
|
-
return
|
|
106
|
+
return resolve(full);
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
|
-
return
|
|
109
|
+
return null;
|
|
108
110
|
}
|
|
109
111
|
function collectEditableSearchRoots(configDir, config, layer, modularCategory, baseAbsPath) {
|
|
110
112
|
const roots = [];
|
|
@@ -151,7 +153,7 @@ function pruneDisabledLayerBasesInRoots(configDir, config, spec, roots, expected
|
|
|
151
153
|
const editableName = spec.toEditableFileName(entry);
|
|
152
154
|
if (editableName) {
|
|
153
155
|
const editableRoots = collectEditableSearchRoots(configDir, config, spec.layerConfig, spec.modularCategory, fullPath);
|
|
154
|
-
if (findEditableSubclassFile(editableRoots, editableName)) {
|
|
156
|
+
if (findEditableSubclassFile(editableRoots, editableName, fullPath)) {
|
|
155
157
|
kept += 1;
|
|
156
158
|
continue;
|
|
157
159
|
}
|
|
@@ -210,12 +212,46 @@ export function hasEditableSubclassForBase(configDir, config, file) {
|
|
|
210
212
|
if (!editableName)
|
|
211
213
|
return false;
|
|
212
214
|
const roots = collectEditableSearchRoots(configDir, config, spec.layerConfig, spec.modularCategory, resolve(configDir, file.path));
|
|
213
|
-
return findEditableSubclassFile(roots, editableName);
|
|
215
|
+
return findEditableSubclassFile(roots, editableName, resolve(configDir, file.path));
|
|
214
216
|
}
|
|
215
217
|
return false;
|
|
216
218
|
}
|
|
219
|
+
const SCAFFOLD_LAYER_BASE_SUFFIX = {
|
|
220
|
+
request: 'RequestBase.php',
|
|
221
|
+
resource: 'ResourceBase.php',
|
|
222
|
+
policy: 'PolicyBase.php',
|
|
223
|
+
controller: 'ControllerBase.php',
|
|
224
|
+
service: 'ServiceBase.php',
|
|
225
|
+
};
|
|
226
|
+
const SCAFFOLD_LAYER_EDITABLE_SUFFIX = {
|
|
227
|
+
request: 'Request.php',
|
|
228
|
+
resource: 'Resource.php',
|
|
229
|
+
policy: 'Policy.php',
|
|
230
|
+
controller: 'Controller.php',
|
|
231
|
+
service: 'Service.php',
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* Legacy `flatBase` puts regenerated bases directly at `layer.basePath` with
|
|
235
|
+
* the same filename as the user-editable stub (different directory). That
|
|
236
|
+
* directory is generated-only: resolveBaseClass() always targets basePath and
|
|
237
|
+
* only per-schema base classes are written there (issue #96).
|
|
238
|
+
*/
|
|
239
|
+
function disabledLayerFileMatchers(config, layerConfig, baseSuffix, editableSuffix) {
|
|
240
|
+
const modularMatches = (name) => name.endsWith(baseSuffix);
|
|
241
|
+
const modularToEditable = (name) => baseToEditableFileName(name, baseSuffix, editableSuffix);
|
|
242
|
+
if (config.structure === 'modular') {
|
|
243
|
+
return { matchesBaseFile: modularMatches, toEditableFileName: modularToEditable };
|
|
244
|
+
}
|
|
245
|
+
if (layerConfig.flatBase) {
|
|
246
|
+
return {
|
|
247
|
+
matchesBaseFile: (name) => name.endsWith('.php'),
|
|
248
|
+
toEditableFileName: (name) => (name.endsWith('.php') ? name : null),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
return { matchesBaseFile: modularMatches, toEditableFileName: modularToEditable };
|
|
252
|
+
}
|
|
217
253
|
function scaffoldLayerSpecs(config) {
|
|
218
|
-
|
|
254
|
+
const layers = [
|
|
219
255
|
{
|
|
220
256
|
layer: 'request',
|
|
221
257
|
label: 'request base',
|
|
@@ -223,8 +259,6 @@ function scaffoldLayerSpecs(config) {
|
|
|
223
259
|
layerConfig: config.requests,
|
|
224
260
|
legacyBasePath: config.requests.basePath,
|
|
225
261
|
modularCategory: 'Requests',
|
|
226
|
-
matchesBaseFile: (name) => name.endsWith('RequestBase.php'),
|
|
227
|
-
toEditableFileName: (name) => baseToEditableFileName(name, 'RequestBase.php', 'Request.php'),
|
|
228
262
|
},
|
|
229
263
|
{
|
|
230
264
|
layer: 'resource',
|
|
@@ -233,8 +267,6 @@ function scaffoldLayerSpecs(config) {
|
|
|
233
267
|
layerConfig: config.resources,
|
|
234
268
|
legacyBasePath: config.resources.basePath,
|
|
235
269
|
modularCategory: 'Resources',
|
|
236
|
-
matchesBaseFile: (name) => name.endsWith('ResourceBase.php'),
|
|
237
|
-
toEditableFileName: (name) => baseToEditableFileName(name, 'ResourceBase.php', 'Resource.php'),
|
|
238
270
|
},
|
|
239
271
|
{
|
|
240
272
|
layer: 'policy',
|
|
@@ -243,8 +275,6 @@ function scaffoldLayerSpecs(config) {
|
|
|
243
275
|
layerConfig: config.policies,
|
|
244
276
|
legacyBasePath: config.policies.basePath,
|
|
245
277
|
modularCategory: 'Policies',
|
|
246
|
-
matchesBaseFile: (name) => name.endsWith('PolicyBase.php'),
|
|
247
|
-
toEditableFileName: (name) => baseToEditableFileName(name, 'PolicyBase.php', 'Policy.php'),
|
|
248
278
|
},
|
|
249
279
|
{
|
|
250
280
|
layer: 'controller',
|
|
@@ -253,8 +283,6 @@ function scaffoldLayerSpecs(config) {
|
|
|
253
283
|
layerConfig: config.controllers,
|
|
254
284
|
legacyBasePath: config.controllers.basePath,
|
|
255
285
|
modularCategory: 'Controllers',
|
|
256
|
-
matchesBaseFile: (name) => name.endsWith('ControllerBase.php'),
|
|
257
|
-
toEditableFileName: (name) => baseToEditableFileName(name, 'ControllerBase.php', 'Controller.php'),
|
|
258
286
|
},
|
|
259
287
|
{
|
|
260
288
|
layer: 'service',
|
|
@@ -263,10 +291,14 @@ function scaffoldLayerSpecs(config) {
|
|
|
263
291
|
layerConfig: config.services,
|
|
264
292
|
legacyBasePath: config.services.basePath,
|
|
265
293
|
modularCategory: 'Services',
|
|
266
|
-
matchesBaseFile: (name) => name.endsWith('ServiceBase.php'),
|
|
267
|
-
toEditableFileName: (name) => baseToEditableFileName(name, 'ServiceBase.php', 'Service.php'),
|
|
268
294
|
},
|
|
269
295
|
];
|
|
296
|
+
return layers.map((entry) => {
|
|
297
|
+
const baseSuffix = SCAFFOLD_LAYER_BASE_SUFFIX[entry.layer];
|
|
298
|
+
const editableSuffix = SCAFFOLD_LAYER_EDITABLE_SUFFIX[entry.layer];
|
|
299
|
+
const matchers = disabledLayerFileMatchers(config, entry.layerConfig, baseSuffix, editableSuffix);
|
|
300
|
+
return { ...entry, ...matchers };
|
|
301
|
+
});
|
|
270
302
|
}
|
|
271
303
|
/**
|
|
272
304
|
* Delete orphan `*ServiceBase.php` files; flag orphan editable services
|