@simplix-boot/cli 0.0.0-stage → 1.3.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/LICENSE +25 -0
- package/LICENSE_KO +28 -0
- package/README.ko.md +82 -0
- package/README.md +81 -2
- package/bin/simplix-boot.js +6 -0
- package/package.json +45 -4
- package/src/cli.js +103 -0
- package/src/commands/config.js +129 -0
- package/src/commands/generate.js +291 -0
- package/src/commands/generated.js +125 -0
- package/src/commands/init.js +41 -0
- package/src/commands/promote.js +172 -0
- package/src/commands/templates.js +100 -0
- package/src/commands/version.js +134 -0
- package/src/lib/analysis/fields.js +217 -0
- package/src/lib/analysis/imports.js +76 -0
- package/src/lib/analysis/structure.js +193 -0
- package/src/lib/analysis/types.js +94 -0
- package/src/lib/args.js +69 -0
- package/src/lib/comment-extractor.js +141 -0
- package/src/lib/config/fields.js +321 -0
- package/src/lib/config/parents.js +108 -0
- package/src/lib/config/paths.js +156 -0
- package/src/lib/config/yml.js +61 -0
- package/src/lib/console.js +83 -0
- package/src/lib/controller-name.js +33 -0
- package/src/lib/entity-analyzer.js +49 -0
- package/src/lib/entity-type-resolver.js +80 -0
- package/src/lib/entity-type.js +35 -0
- package/src/lib/errors.js +17 -0
- package/src/lib/export-config.js +74 -0
- package/src/lib/file-utils.js +77 -0
- package/src/lib/generate/file-plan.js +155 -0
- package/src/lib/generate/search-fields.js +111 -0
- package/src/lib/generate/settings.js +111 -0
- package/src/lib/generate/support-classes.js +47 -0
- package/src/lib/generate/template-vars.js +183 -0
- package/src/lib/git-utils.js +18 -0
- package/src/lib/name-field.js +42 -0
- package/src/lib/project.js +121 -0
- package/src/lib/promote-files.js +132 -0
- package/src/lib/rendered-output.js +13 -0
- package/src/lib/search-operators.js +87 -0
- package/src/lib/templates.js +50 -0
- package/src/lib/tracked-render.js +200 -0
- package/src/lib/version-check.js +195 -0
- package/src/lib/version-utils.js +97 -0
- package/templates/controller/rest/EntityRestController.java.template +517 -0
- package/templates/controller/web/EntityWebController.java.template +211 -0
- package/templates/dto/EntityDTOs.java.template +981 -0
- package/templates/repository/EntityRepository.java.template +78 -0
- package/templates/service/EntityService.java.template +790 -0
- package/templates/service/EntityTreeService.java.template +352 -0
- package/templates/test/EntityServiceTest.java.template +937 -0
- package/templates/test/EntityTreeServiceTest.java.template +842 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { symbols } from '../lib/console.js';
|
|
4
|
+
import { CliError } from '../lib/errors.js';
|
|
5
|
+
import { BUILT_IN_TEMPLATE_DIR, listBuiltInTemplates, locateTemplate, projectTemplateDir } from '../lib/templates.js';
|
|
6
|
+
|
|
7
|
+
export const usage = 'simplix-boot templates [--eject [<template>]] [--force]';
|
|
8
|
+
|
|
9
|
+
export const summary = 'List the templates in use, or copy built-in templates into .simplix/templates';
|
|
10
|
+
|
|
11
|
+
export const argumentSpec = {
|
|
12
|
+
positionals: ['template'],
|
|
13
|
+
options: {
|
|
14
|
+
eject: { type: 'boolean', default: false },
|
|
15
|
+
force: { type: 'boolean', default: false },
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function projectOnlyTemplates(root) {
|
|
20
|
+
const dir = projectTemplateDir(root);
|
|
21
|
+
const found = [];
|
|
22
|
+
const walk = current => {
|
|
23
|
+
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
|
|
24
|
+
const full = path.join(current, entry.name);
|
|
25
|
+
if (entry.isDirectory()) walk(full);
|
|
26
|
+
else if (entry.name.endsWith('.template')) found.push(path.relative(dir, full).split(path.sep).join('/'));
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
if (fs.existsSync(dir)) walk(dir);
|
|
31
|
+
return found;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Every template the project can render from, with where it comes from: the project's own copy,
|
|
36
|
+
* or the built-in one when the project has none of that relative path.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} root the project root
|
|
39
|
+
* @returns {{ template: string, origin: 'project' | 'built-in', replacesBuiltIn: boolean }[]}
|
|
40
|
+
*/
|
|
41
|
+
export function listTemplates(root) {
|
|
42
|
+
const builtIn = new Set(listBuiltInTemplates());
|
|
43
|
+
const names = [...new Set([...builtIn, ...projectOnlyTemplates(root)])].sort();
|
|
44
|
+
|
|
45
|
+
return names.map(template => ({
|
|
46
|
+
template,
|
|
47
|
+
origin: locateTemplate(root, template).origin,
|
|
48
|
+
replacesBuiltIn: builtIn.has(template) && locateTemplate(root, template).origin === 'project',
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Copies built-in templates into the project, where an edited copy replaces the built-in one.
|
|
54
|
+
*
|
|
55
|
+
* @param {object} eject
|
|
56
|
+
* @param {string} eject.root the project root
|
|
57
|
+
* @param {string} [eject.template] one template by its relative path; every built-in one when omitted
|
|
58
|
+
* @param {boolean} [eject.force] whether an existing project copy is overwritten
|
|
59
|
+
* @returns {{ template: string, outcome: 'copied' | 'kept' }[]}
|
|
60
|
+
* @throws {CliError} when the named template is not a built-in one
|
|
61
|
+
*/
|
|
62
|
+
export function ejectTemplates({ root, template, force = false }) {
|
|
63
|
+
const builtIn = listBuiltInTemplates();
|
|
64
|
+
if (template !== undefined && !builtIn.includes(template)) {
|
|
65
|
+
throw new CliError(`No built-in template named ${template}. Run "simplix-boot templates" for the list.`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return (template === undefined ? builtIn : [template]).map(name => {
|
|
69
|
+
const dest = path.join(projectTemplateDir(root), name);
|
|
70
|
+
if (fs.existsSync(dest) && !force) return { template: name, outcome: 'kept' };
|
|
71
|
+
|
|
72
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
73
|
+
fs.copyFileSync(path.join(BUILT_IN_TEMPLATE_DIR, name), dest);
|
|
74
|
+
return { template: name, outcome: 'copied' };
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Runs `templates` from the command line. */
|
|
79
|
+
export function run({ root, positionals, options, output }) {
|
|
80
|
+
const { log } = output;
|
|
81
|
+
|
|
82
|
+
if (!options.eject) {
|
|
83
|
+
if (positionals.template !== undefined) {
|
|
84
|
+
throw new CliError(`A template name is only used with --eject\nUsage: ${usage}`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
for (const entry of listTemplates(root)) {
|
|
88
|
+
const note = entry.replacesBuiltIn ? ' (replaces the built-in template)' : '';
|
|
89
|
+
log(`${entry.origin.padEnd(8)} ${entry.template}${note}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
for (const result of ejectTemplates({ root, template: positionals.template, force: options.force })) {
|
|
96
|
+
const target = path.relative(root, path.join(projectTemplateDir(root), result.template));
|
|
97
|
+
if (result.outcome === 'copied') log(`${symbols.success} ${target}`);
|
|
98
|
+
else log(`${symbols.warning} SKIP: ${target} (already exists, use --force to overwrite)`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { style, symbols } from '../lib/console.js';
|
|
3
|
+
import { CliError } from '../lib/errors.js';
|
|
4
|
+
import { CONFIG_FILE_NAME, configPathOf, findProjectRoot, readProjectConfig } from '../lib/project.js';
|
|
5
|
+
import {
|
|
6
|
+
collectVersionStatus,
|
|
7
|
+
fetchLatestPublishedVersion,
|
|
8
|
+
installGeneratorVersion,
|
|
9
|
+
recordGeneratorVersion,
|
|
10
|
+
} from '../lib/version-check.js';
|
|
11
|
+
import {
|
|
12
|
+
compareReleaseVersions,
|
|
13
|
+
getGeneratorPackageName,
|
|
14
|
+
getGeneratorVersion,
|
|
15
|
+
parseReleaseCore,
|
|
16
|
+
toReleaseVersion,
|
|
17
|
+
} from '../lib/version-utils.js';
|
|
18
|
+
export const usage = 'simplix-boot version [--json] [--write] [--update [--to <X.Y.Z>]]';
|
|
19
|
+
|
|
20
|
+
export const summary = 'Report the running, required and latest CLI versions, record or install one';
|
|
21
|
+
|
|
22
|
+
export const argumentSpec = {
|
|
23
|
+
positionals: [],
|
|
24
|
+
options: {
|
|
25
|
+
json: { type: 'boolean', default: false },
|
|
26
|
+
write: { type: 'boolean', default: false },
|
|
27
|
+
update: { type: 'boolean', default: false },
|
|
28
|
+
to: { type: 'string' },
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** `version` reports from anywhere; outside a project it has no recorded version to compare. */
|
|
33
|
+
export const needsProject = false;
|
|
34
|
+
|
|
35
|
+
/** A version npm can install: X.Y.Z with an optional pre-release tag. */
|
|
36
|
+
const INSTALLABLE_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
37
|
+
|
|
38
|
+
function resolveUpdateTarget(requested) {
|
|
39
|
+
if (requested) {
|
|
40
|
+
if (!parseReleaseCore(requested) || !INSTALLABLE_VERSION.test(requested)) {
|
|
41
|
+
throw new CliError(`"${requested}" is not an X.Y.Z version`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return requested;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const latest = fetchLatestPublishedVersion();
|
|
48
|
+
if (!latest) {
|
|
49
|
+
throw new CliError(
|
|
50
|
+
`Cannot resolve the latest published version of ${getGeneratorPackageName()}. Check the registry connection or pass a version with --to.`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return latest;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function reportText(status, configPath, log) {
|
|
58
|
+
log('');
|
|
59
|
+
log(`${style.cyan('SimpliX Boot CLI')} version status\n`);
|
|
60
|
+
log(` package: ${status.packageName}`);
|
|
61
|
+
log(` running: ${style.bold(status.current)}${status.snapshot ? style.dim(' (development build)') : ''}`);
|
|
62
|
+
log(` required: ${status.required ?? style.dim('not recorded')}`);
|
|
63
|
+
log(` latest: ${status.latest ?? style.dim('lookup failed')}`);
|
|
64
|
+
log(` config: ${configPath ?? style.dim('not found')}`);
|
|
65
|
+
log('');
|
|
66
|
+
|
|
67
|
+
if (status.status === 'outdated') {
|
|
68
|
+
log(`${symbols.error} The running CLI is older than this project requires.`);
|
|
69
|
+
log(` run ${style.cyan('simplix-boot version --update')} to install the latest published version.`);
|
|
70
|
+
} else if (status.status === 'ahead') {
|
|
71
|
+
log(`${symbols.warning} The running CLI is newer than this project records.`);
|
|
72
|
+
log(` run ${style.cyan('simplix-boot version --write')} to record ${toReleaseVersion(status.current)}.`);
|
|
73
|
+
} else if (status.status === 'unrecorded') {
|
|
74
|
+
log(`${symbols.info} This project records no generator version.`);
|
|
75
|
+
log(` run ${style.cyan('simplix-boot version --write')} to record ${toReleaseVersion(status.current)}.`);
|
|
76
|
+
} else if (status.status === 'unknown') {
|
|
77
|
+
log(`${symbols.warning} The recorded version cannot be compared with the running version.`);
|
|
78
|
+
} else {
|
|
79
|
+
log(`${symbols.success} The running CLI matches this project.`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// A development build runs ahead of the registry, so only a genuinely newer
|
|
83
|
+
// published version is worth announcing.
|
|
84
|
+
if (status.latest && compareReleaseVersions(status.latest, status.current) > 0) {
|
|
85
|
+
log(`${symbols.info} npm has ${status.latest} available.`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
log('');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Runs `version` from the command line. */
|
|
92
|
+
export function run({ cwd, options, output }) {
|
|
93
|
+
const { log } = output;
|
|
94
|
+
|
|
95
|
+
if (options.to !== undefined && !options.update) {
|
|
96
|
+
throw new CliError('--to is only used with --update');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (options.update) {
|
|
100
|
+
const target = resolveUpdateTarget(options.to);
|
|
101
|
+
const packageName = getGeneratorPackageName();
|
|
102
|
+
|
|
103
|
+
log(`Installing ${style.cyan(`${packageName}@${target}`)} globally...`);
|
|
104
|
+
installGeneratorVersion(target, packageName);
|
|
105
|
+
log(`${symbols.success} Installed ${packageName}@${target}. The next ${style.cyan('simplix-boot')} run uses it.`);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const root = findProjectRoot(cwd);
|
|
110
|
+
const configPath = root !== undefined && fs.existsSync(configPathOf(root)) ? configPathOf(root) : null;
|
|
111
|
+
|
|
112
|
+
if (options.write) {
|
|
113
|
+
if (!configPath) {
|
|
114
|
+
throw new CliError(
|
|
115
|
+
`${CONFIG_FILE_NAME} not found. Run "simplix-boot init" first and create the configuration file.`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const version = toReleaseVersion(getGeneratorVersion());
|
|
120
|
+
recordGeneratorVersion(configPath, version);
|
|
121
|
+
log(`${symbols.success} Recorded generator version ${style.cyan(version)} in ${configPath}`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const config = configPath ? readProjectConfig(root) : null;
|
|
126
|
+
const status = collectVersionStatus({ config, includeLatest: true });
|
|
127
|
+
|
|
128
|
+
if (options.json) {
|
|
129
|
+
output.result(JSON.stringify({ ...status, configPath }));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
reportText(status, configPath, log);
|
|
134
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { TYPE_CLASSIFICATIONS, classifyNonBasicType, classifyType } from './types.js';
|
|
2
|
+
import { extractComment } from '../comment-extractor.js';
|
|
3
|
+
import { findImportPath } from './imports.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Annotation mapping for field characteristics
|
|
7
|
+
*/
|
|
8
|
+
const ANNOTATION_MAPPINGS = {
|
|
9
|
+
'@NaturalId': { property: 'isNaturalId', value: true },
|
|
10
|
+
'@Lob': { property: 'isLob', value: true },
|
|
11
|
+
'@NameField': { property: 'isNameField', value: true },
|
|
12
|
+
'@ManyToOne': { property: 'relationType', value: 'ManyToOne' },
|
|
13
|
+
'@OneToMany': { property: 'relationType', value: 'OneToMany' },
|
|
14
|
+
'@OneToOne': { property: 'relationType', value: 'OneToOne' },
|
|
15
|
+
'@ManyToMany': { property: 'relationType', value: 'ManyToMany' },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function analyzeFields(contentLines, imports, entityContent, isEntityType) {
|
|
19
|
+
const fields = [];
|
|
20
|
+
const annotations = [];
|
|
21
|
+
let inMultiLineAnnotation = false;
|
|
22
|
+
let currentAnnotation = '';
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < contentLines.length; i++) {
|
|
25
|
+
const line = contentLines[i].trim();
|
|
26
|
+
|
|
27
|
+
// Handle multi-line annotation continuation
|
|
28
|
+
if (inMultiLineAnnotation) {
|
|
29
|
+
currentAnnotation += ' ' + line;
|
|
30
|
+
// Check if annotation is complete (balanced parentheses)
|
|
31
|
+
const openCount = (currentAnnotation.match(/\(/g) || []).length;
|
|
32
|
+
const closeCount = (currentAnnotation.match(/\)/g) || []).length;
|
|
33
|
+
if (openCount === closeCount) {
|
|
34
|
+
annotations.push(currentAnnotation);
|
|
35
|
+
currentAnnotation = '';
|
|
36
|
+
inMultiLineAnnotation = false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Collect annotations
|
|
43
|
+
if (line.startsWith('@')) {
|
|
44
|
+
// Check if this is a multi-line annotation (has open paren but no close)
|
|
45
|
+
const hasOpenParen = line.includes('(');
|
|
46
|
+
const hasCloseParen = line.includes(')');
|
|
47
|
+
|
|
48
|
+
if (hasOpenParen && !hasCloseParen) {
|
|
49
|
+
// Start of multi-line annotation
|
|
50
|
+
inMultiLineAnnotation = true;
|
|
51
|
+
currentAnnotation = line;
|
|
52
|
+
} else {
|
|
53
|
+
// Single-line annotation
|
|
54
|
+
annotations.push(line);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Parse field definition
|
|
61
|
+
if (line.startsWith('private ')) {
|
|
62
|
+
// Skip fields with @Transient annotation
|
|
63
|
+
if (annotations.some(ann => ann.startsWith('@Transient'))) {
|
|
64
|
+
annotations.length = 0;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Remove Java modifiers (final, static, transient, volatile) before parsing
|
|
69
|
+
const cleanedLine = line
|
|
70
|
+
.replace(/\bfinal\b/g, '')
|
|
71
|
+
.replace(/\bstatic\b/g, '')
|
|
72
|
+
.replace(/\btransient\b/g, '')
|
|
73
|
+
.replace(/\bvolatile\b/g, '')
|
|
74
|
+
.replace(/\s+/g, ' ')
|
|
75
|
+
.trim();
|
|
76
|
+
|
|
77
|
+
// Skip method declarations (containing parentheses)
|
|
78
|
+
if (cleanedLine.includes('(') || cleanedLine.includes(')')) {
|
|
79
|
+
annotations.length = 0;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const fieldMatch = cleanedLine.match(/private\s+([^\s<>]+)(?:<([^>]+)>)?\s+(\w+)/);
|
|
84
|
+
|
|
85
|
+
if (!fieldMatch) {
|
|
86
|
+
annotations.length = 0;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const rawType = fieldMatch[1];
|
|
91
|
+
const genericType = fieldMatch[2];
|
|
92
|
+
const fieldName = fieldMatch[3];
|
|
93
|
+
|
|
94
|
+
// Determine if it's a collection
|
|
95
|
+
const isCollection = ['List', 'Set', 'Collection', 'ArrayList', 'HashSet'].includes(rawType);
|
|
96
|
+
const isMap = rawType === 'Map' || rawType === 'HashMap' || rawType === 'TreeMap' || rawType === 'LinkedHashMap';
|
|
97
|
+
const actualType = (isCollection || isMap) && genericType ? genericType : rawType;
|
|
98
|
+
|
|
99
|
+
// Initialize field info
|
|
100
|
+
const fieldInfo = {
|
|
101
|
+
name: fieldName,
|
|
102
|
+
type: isMap && genericType ? `${rawType}<${genericType}>` : isCollection ? rawType : actualType,
|
|
103
|
+
actualType: isCollection ? actualType : undefined,
|
|
104
|
+
isCollection,
|
|
105
|
+
isMap,
|
|
106
|
+
collectionType: isCollection || isMap ? rawType : undefined,
|
|
107
|
+
typeKind: isMap ? 'map' : classifyType(actualType, imports),
|
|
108
|
+
comment: extractComment(entityContent, fieldName),
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Process annotations
|
|
112
|
+
processFieldAnnotations(annotations, fieldInfo, contentLines, i);
|
|
113
|
+
|
|
114
|
+
// Classify a non-basic type as an enum, a related entity or a plain value, and set its import path
|
|
115
|
+
if (!TYPE_CLASSIFICATIONS.basic.has(actualType)) {
|
|
116
|
+
const importPath = findImportPath(actualType, imports, entityContent);
|
|
117
|
+
|
|
118
|
+
if (!fieldInfo.typeKind) {
|
|
119
|
+
Object.assign(
|
|
120
|
+
fieldInfo,
|
|
121
|
+
classifyNonBasicType(actualType, importPath, { entityContent, imports, isEntityType })
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (importPath) {
|
|
126
|
+
fieldInfo.importPath = importPath;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
fields.push(fieldInfo);
|
|
131
|
+
annotations.length = 0;
|
|
132
|
+
} else if (line.length > 0 && !line.startsWith('//') && !line.startsWith('/*')) {
|
|
133
|
+
annotations.length = 0;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return fields;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function processFieldAnnotations(annotations, fieldInfo, contentLines, lineIndex) {
|
|
141
|
+
annotations.forEach(annotation => {
|
|
142
|
+
// Apply annotation mappings
|
|
143
|
+
for (const [key, mapping] of Object.entries(ANNOTATION_MAPPINGS)) {
|
|
144
|
+
if (annotation.startsWith(key)) {
|
|
145
|
+
fieldInfo[mapping.property] = mapping.value;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Process Column annotation
|
|
150
|
+
if (annotation.startsWith('@Column')) {
|
|
151
|
+
const columnInfo = parseColumnAnnotation(annotation, contentLines, lineIndex);
|
|
152
|
+
if (columnInfo) {
|
|
153
|
+
fieldInfo.columnInfo = columnInfo;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Process JoinColumn annotation
|
|
158
|
+
if (annotation.startsWith('@JoinColumn')) {
|
|
159
|
+
const joinColumnMatch = annotation.match(/name\s*=\s*"([^"]+)"/);
|
|
160
|
+
if (joinColumnMatch) {
|
|
161
|
+
fieldInfo.joinColumnName = joinColumnMatch[1];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Process JsonIncludeProperties annotation
|
|
166
|
+
// Example: @JsonIncludeProperties({"contentId", "title", "status", "channelId"})
|
|
167
|
+
if (annotation.startsWith('@JsonIncludeProperties')) {
|
|
168
|
+
const propsMatch = annotation.match(/@JsonIncludeProperties\s*\(\s*\{([^}]+)\}\s*\)/);
|
|
169
|
+
if (propsMatch) {
|
|
170
|
+
const propsString = propsMatch[1];
|
|
171
|
+
const props = propsString
|
|
172
|
+
.split(',')
|
|
173
|
+
.map(p => p.trim().replace(/"/g, ''))
|
|
174
|
+
.filter(p => p.length > 0);
|
|
175
|
+
fieldInfo.jsonIncludeProperties = props;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function parseColumnAnnotation(annotation, contentLines, startIndex) {
|
|
182
|
+
let fullAnnotation = annotation;
|
|
183
|
+
|
|
184
|
+
// Handle multi-line annotations
|
|
185
|
+
if (!annotation.includes(')')) {
|
|
186
|
+
for (let j = startIndex - 1; j >= 0; j--) {
|
|
187
|
+
const prevLine = contentLines[j].trim();
|
|
188
|
+
fullAnnotation = prevLine + ' ' + fullAnnotation;
|
|
189
|
+
if (prevLine.includes('@Column')) break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const columnInfo = {};
|
|
194
|
+
|
|
195
|
+
// Extract column attributes
|
|
196
|
+
const patterns = {
|
|
197
|
+
nullable: /nullable\s*=\s*(true|false)/,
|
|
198
|
+
unique: /unique\s*=\s*(true|false)/,
|
|
199
|
+
length: /length\s*=\s*(\d+)/,
|
|
200
|
+
name: /name\s*=\s*"([^"]+)"/,
|
|
201
|
+
columnDefinition: /columnDefinition\s*=\s*"([^"]+)"/,
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
for (const [key, pattern] of Object.entries(patterns)) {
|
|
205
|
+
const match = fullAnnotation.match(pattern);
|
|
206
|
+
if (match) {
|
|
207
|
+
columnInfo[key] =
|
|
208
|
+
key === 'nullable' || key === 'unique'
|
|
209
|
+
? match[1] === 'true'
|
|
210
|
+
: key === 'length'
|
|
211
|
+
? parseInt(match[1], 10)
|
|
212
|
+
: match[1];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return Object.keys(columnInfo).length > 0 ? columnInfo : null;
|
|
217
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export function findImportPath(type, imports, entityContent) {
|
|
2
|
+
// Look for direct import
|
|
3
|
+
const directImport = imports.find(imp => imp.endsWith(`.${type}`));
|
|
4
|
+
if (directImport) return directImport;
|
|
5
|
+
|
|
6
|
+
// Look for entity wildcard imports and try to match with type name
|
|
7
|
+
const entityWildcards = imports.filter(imp => imp.endsWith('.*') && imp.includes('.entity.'));
|
|
8
|
+
|
|
9
|
+
// Try to match type name with wildcard package segment
|
|
10
|
+
// e.g., "CmsQnaExtension" should match "...extension.*"
|
|
11
|
+
for (const wildcard of entityWildcards) {
|
|
12
|
+
const packagePath = wildcard.slice(0, -2); // remove ".*"
|
|
13
|
+
const lastSegment = packagePath.split('.').pop(); // e.g., "extension"
|
|
14
|
+
|
|
15
|
+
// Check if type name contains this segment (case-insensitive)
|
|
16
|
+
if (type.toLowerCase().includes(lastSegment.toLowerCase())) {
|
|
17
|
+
return wildcard.replace('*', type);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// If no matching wildcard, assume same package
|
|
22
|
+
const packageMatch = entityContent ? entityContent.match(/package\s+([\w.]+);/) : null;
|
|
23
|
+
if (packageMatch) {
|
|
24
|
+
const currentPackage = packageMatch[1];
|
|
25
|
+
return `${currentPackage}.${type}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Fallback to any wildcard import (last resort)
|
|
29
|
+
const wildcardImports = imports.filter(imp => imp.endsWith('.*'));
|
|
30
|
+
for (const wildcard of wildcardImports) {
|
|
31
|
+
const possiblePath = wildcard.replace('*', type);
|
|
32
|
+
return possiblePath;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function analyzeImports(entityContent) {
|
|
39
|
+
const importPattern = /import\s+([\w.]+(?:\.\*)?);/g;
|
|
40
|
+
const imports = [];
|
|
41
|
+
let match;
|
|
42
|
+
|
|
43
|
+
while ((match = importPattern.exec(entityContent)) !== null) {
|
|
44
|
+
imports.push(match[1]);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return imports;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function processImports(entityContent) {
|
|
51
|
+
const imports = [];
|
|
52
|
+
const lines = entityContent.split('\n');
|
|
53
|
+
|
|
54
|
+
lines.forEach(line => {
|
|
55
|
+
const trimmed = line.trim();
|
|
56
|
+
if (trimmed.startsWith('import ') && trimmed.endsWith(';')) {
|
|
57
|
+
const importPath = trimmed.substring(7, trimmed.length - 1).trim();
|
|
58
|
+
|
|
59
|
+
// Classify import type
|
|
60
|
+
let type = 'other';
|
|
61
|
+
if (importPath.includes('.entities.') || importPath.includes('.entity.')) {
|
|
62
|
+
type = 'entity';
|
|
63
|
+
} else if (importPath.includes('.enums.') || importPath.includes('.enum.')) {
|
|
64
|
+
type = 'enum';
|
|
65
|
+
} else if (importPath.startsWith('java.') || importPath.startsWith('javax.')) {
|
|
66
|
+
type = 'java';
|
|
67
|
+
} else if (importPath.includes('springframework')) {
|
|
68
|
+
type = 'spring';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
imports.push({ path: importPath, type });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return imports;
|
|
76
|
+
}
|