@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.
Files changed (55) hide show
  1. package/LICENSE +25 -0
  2. package/LICENSE_KO +28 -0
  3. package/README.ko.md +82 -0
  4. package/README.md +81 -2
  5. package/bin/simplix-boot.js +6 -0
  6. package/package.json +45 -4
  7. package/src/cli.js +103 -0
  8. package/src/commands/config.js +129 -0
  9. package/src/commands/generate.js +291 -0
  10. package/src/commands/generated.js +125 -0
  11. package/src/commands/init.js +41 -0
  12. package/src/commands/promote.js +172 -0
  13. package/src/commands/templates.js +100 -0
  14. package/src/commands/version.js +134 -0
  15. package/src/lib/analysis/fields.js +217 -0
  16. package/src/lib/analysis/imports.js +76 -0
  17. package/src/lib/analysis/structure.js +193 -0
  18. package/src/lib/analysis/types.js +94 -0
  19. package/src/lib/args.js +69 -0
  20. package/src/lib/comment-extractor.js +141 -0
  21. package/src/lib/config/fields.js +321 -0
  22. package/src/lib/config/parents.js +108 -0
  23. package/src/lib/config/paths.js +156 -0
  24. package/src/lib/config/yml.js +61 -0
  25. package/src/lib/console.js +83 -0
  26. package/src/lib/controller-name.js +33 -0
  27. package/src/lib/entity-analyzer.js +49 -0
  28. package/src/lib/entity-type-resolver.js +80 -0
  29. package/src/lib/entity-type.js +35 -0
  30. package/src/lib/errors.js +17 -0
  31. package/src/lib/export-config.js +74 -0
  32. package/src/lib/file-utils.js +77 -0
  33. package/src/lib/generate/file-plan.js +155 -0
  34. package/src/lib/generate/search-fields.js +111 -0
  35. package/src/lib/generate/settings.js +111 -0
  36. package/src/lib/generate/support-classes.js +47 -0
  37. package/src/lib/generate/template-vars.js +183 -0
  38. package/src/lib/git-utils.js +18 -0
  39. package/src/lib/name-field.js +42 -0
  40. package/src/lib/project.js +121 -0
  41. package/src/lib/promote-files.js +132 -0
  42. package/src/lib/rendered-output.js +13 -0
  43. package/src/lib/search-operators.js +87 -0
  44. package/src/lib/templates.js +50 -0
  45. package/src/lib/tracked-render.js +200 -0
  46. package/src/lib/version-check.js +195 -0
  47. package/src/lib/version-utils.js +97 -0
  48. package/templates/controller/rest/EntityRestController.java.template +517 -0
  49. package/templates/controller/web/EntityWebController.java.template +211 -0
  50. package/templates/dto/EntityDTOs.java.template +981 -0
  51. package/templates/repository/EntityRepository.java.template +78 -0
  52. package/templates/service/EntityService.java.template +790 -0
  53. package/templates/service/EntityTreeService.java.template +352 -0
  54. package/templates/test/EntityServiceTest.java.template +937 -0
  55. package/templates/test/EntityTreeServiceTest.java.template +842 -0
@@ -0,0 +1,211 @@
1
+ package <%= packagePaths['controllerWeb'] %>;
2
+
3
+ import <%= entityPackage %>.<%= entityName %>;
4
+ import <%= packagePaths['dto'] %>.<%= classPrefix %>DTOs.*;
5
+ import <%= packagePaths['service'] %>.<%= classPrefix %>Service;
6
+ <% if (hasEmbeddedId) { %>
7
+ import <%= entityPackage %>.<%= entityName %>.<%= embeddedIdType %>;
8
+ import java.util.stream.Collectors;
9
+ <% } %>
10
+ <%
11
+ // Parse import statements for reference entities
12
+ const importedServices = new Set();
13
+ const importedDTOs = new Set();
14
+
15
+ // Find reference types from entity fields - skip incorrect imports
16
+ fields.forEach(field => {
17
+ if (field.typeKind === 'entity' || field.isRelation || field.relationType === 'ManyToOne') {
18
+ const entityType = field.isCollection ? field.actualType : field.type;
19
+ // Skip if importPath contains jakarta.persistence (incorrect import)
20
+ if (field.importPath && field.importPath.includes('jakarta.persistence')) {
21
+ return;
22
+ }
23
+ // Generate correct import paths based on the same module path
24
+ const servicePath = `${basePackage}.web.${modulePath}.service.${entityType}Service`;
25
+ const dtoPath = `${basePackage}.web.${modulePath}.dto.${entityType}DTOs`;
26
+
27
+ if (!importedServices.has(entityType)) {
28
+ importedServices.add(entityType); %>
29
+ import <%= servicePath %>;
30
+ import <%= dtoPath %>.*;<%
31
+ }
32
+ }
33
+ });
34
+
35
+ // Find additional reference types from yml configuration
36
+ if (ymlConfig && ymlConfig.fields) {
37
+ Object.entries(ymlConfig.fields).forEach(([fieldName, field]) => {
38
+ if (field.reference && field.reference.entity && !importedServices.has(field.reference.entity)) {
39
+ const refEntity = field.reference.entity;
40
+ importedServices.add(refEntity);
41
+ // Generate import paths based on module path and entity name
42
+ const servicePath = `${basePackage}.web.${modulePath}.service.${refEntity}Service`;
43
+ const dtoPath = `${basePackage}.web.${modulePath}.dto.${refEntity}DTOs`; %>
44
+ import <%= servicePath %>;
45
+ import <%= dtoPath %>.*;<%
46
+ }
47
+ });
48
+ } %>
49
+ <%
50
+ // Set template base path
51
+ const templatePath = ymlConfig?.thymeleafBaseDir ? ymlConfig.thymeleafBaseDir : _.kebabCase(entityName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase());
52
+ %>
53
+ import dev.simplecore.simplix.web.controller.SimpliXBaseController;
54
+ import dev.simplecore.searchable.core.condition.SearchCondition;
55
+ import dev.simplecore.searchable.core.condition.SearchConditionBuilder;
56
+ import org.springframework.security.access.prepost.PreAuthorize;
57
+ import org.springframework.stereotype.Controller;
58
+ import org.springframework.web.bind.annotation.*;
59
+ import org.springframework.ui.Model;
60
+
61
+ /**
62
+ * <%= entityComment.split(':')[0] %>
63
+ */
64
+ @Controller
65
+ @RequestMapping("/<%= templatePath %>")
66
+ public class <%= entityName %>Controller extends SimpliXBaseController<<%= entityName %>, <%= idType %>> {
67
+
68
+ private final <%= classPrefix %>Service service;
69
+ <%
70
+ // Declare reference service variables (remove duplicates)
71
+ const addedServices = new Set();
72
+ if (ymlConfig && ymlConfig.fields) {
73
+ Object.values(ymlConfig.fields).forEach(field => {
74
+ if (field.reference && !addedServices.has(field.reference.entity)) {
75
+ addedServices.add(field.reference.entity); %>
76
+ private final <%= field.reference.entity %>Service <%= _.camelCase(field.reference.entity) %>Service;<%
77
+ }
78
+ });
79
+ } %>
80
+
81
+ /**
82
+ * Constructor for <%= entityName %>Controller
83
+ *
84
+ * @param service The service instance for handling <%= entityName %> operations
85
+ */
86
+ protected <%= entityName %>Controller(<%= classPrefix %>Service service<%
87
+ // Constructor parameters (remove duplicates)
88
+ addedServices.forEach(entity => { %>,
89
+ <%= entity %>Service <%= _.camelCase(entity) %>Service<%
90
+ }); %>) {
91
+ super(service);
92
+ this.service = service;
93
+ <%
94
+ // Initialize reference services (remove duplicates)
95
+ addedServices.forEach(entity => { %>
96
+ this.<%= _.camelCase(entity) %>Service = <%= _.camelCase(entity) %>Service;<%
97
+ }); %>
98
+ }
99
+
100
+ /**
101
+ * Displays the list page for <%= entityName %> entities
102
+ *
103
+ * @param model Spring MVC Model
104
+ * @return The view name for the list page
105
+ */
106
+ @GetMapping("/list")
107
+ @PreAuthorize("hasPermission('<%= entityName %>', 'list')")
108
+ public String list(Model model) {
109
+ model.addAttribute("pageTitle", "<%= entityComment.split(':')[0] %> Management");
110
+ addSelectData(model);
111
+ return "<%= templatePath %>/list";
112
+ }
113
+
114
+ /**
115
+ * Displays the detail page for a <%= entityName %> entity
116
+ *<% if (hasEmbeddedId) { %><% embeddedIdFields.forEach(function(field) { %>
117
+ * @param <%= field.name %> <%= field.comment %><% }); %><% } else { %>
118
+ * @param <%= ymlConfig.idField %> The ID of the <%= entityName %> to display<% } %>
119
+ * @param model Spring MVC Model
120
+ * @return The view name for the detail page or redirect to list
121
+ */
122
+ @GetMapping("/detail/{<%= hasEmbeddedId ? embeddedIdFields.map(f => f.name).join('}__{') : ymlConfig.idField %>}")
123
+ @PreAuthorize("hasPermission('<%= entityName %>', 'view')")
124
+ public String detail(<% if (hasEmbeddedId) { %><% embeddedIdFields.forEach(function(field, index) { %>@PathVariable String <%= field.name %><%= index < embeddedIdFields.length - 1 ? ',' : '' %><% }); %><% } else { %>@PathVariable <%= idType %> <%= ymlConfig.idField %><% } %>, Model model) {
125
+ model.addAttribute("pageTitle", "<%= entityComment.split(':')[0] %> Details");
126
+ <% if (hasEmbeddedId) { %><%= idType %> <%= ymlConfig.idField %> = (new <%= embeddedIdType %>()).fromPathVariables(<%= embeddedIdFields.map(f => f.name).join(', ') %>);<% }%>
127
+ return service.findById(<%= ymlConfig.idField %>, <%= classPrefix %>DetailDTO.class)
128
+ .map(item -> {
129
+ model.addAttribute("item", item);
130
+ return "<%= templatePath %>/detail";
131
+ })
132
+ .orElse("redirect:/<%= templatePath %>/list");
133
+ }
134
+
135
+ /**
136
+ * Returns the brief content fragment for a <%= entityName %> entity
137
+ *<% if (hasEmbeddedId) { %><% embeddedIdFields.forEach(function(field) { %>
138
+ * @param <%= field.name %> <%= field.comment %><% }); %><% } else { %>
139
+ * @param <%= ymlConfig.idField %> The ID of the <%= entityName %> to display<% } %>
140
+ * @param model Spring MVC Model
141
+ * @return The fragment name for brief content
142
+ */
143
+ @GetMapping("/brief/{<%= hasEmbeddedId ? embeddedIdFields.map(f => f.name).join('}__{') : ymlConfig.idField %>}")
144
+ @PreAuthorize("hasPermission('<%= entityName %>', 'view')")
145
+ public String getBrief(<% if (hasEmbeddedId) { %><% embeddedIdFields.forEach(function(field, index) { %>@PathVariable String <%= field.name %><%= index < embeddedIdFields.length - 1 ? ',' : '' %><% }); %><% } else { %>@PathVariable <%= idType %> <%= ymlConfig.idField %><% } %>, Model model) {
146
+ <% if (hasEmbeddedId) { %><%= idType %> <%= ymlConfig.idField %> = (new <%= embeddedIdType %>()).fromPathVariables(<%= embeddedIdFields.map(f => f.name).join(', ') %>);<% }%>
147
+ service.findById(<%= ymlConfig.idField %>, <%= classPrefix %>DetailDTO.class)
148
+ .ifPresent(item -> model.addAttribute("item", item));
149
+ return "<%= templatePath %>/detail :: brief-content";
150
+ }
151
+
152
+ /**
153
+ * Displays the edit page for a <%= entityName %> entity
154
+ *<% if (hasEmbeddedId) { %><% embeddedIdFields.forEach(function(field) { %>
155
+ * @param <%= field.name %> <%= field.comment %><% }); %><% } else { %>
156
+ * @param <%= ymlConfig.idField %> The ID of the <%= entityName %> to edit<% } %>
157
+ * @param model Spring MVC Model
158
+ * @return The view name for the edit page
159
+ */
160
+ @GetMapping("/edit/{<%= hasEmbeddedId ? embeddedIdFields.map(f => f.name).join('}__{') : ymlConfig.idField %>}")
161
+ @PreAuthorize("hasPermission('<%= entityName %>', 'edit')")
162
+ public String edit(<% if (hasEmbeddedId) { %><% embeddedIdFields.forEach(function(field, index) { %>@PathVariable String <%= field.name %><%= index < embeddedIdFields.length - 1 ? ',' : '' %><% }); %><% } else { %>@PathVariable <%= idType %> <%= ymlConfig.idField %><% } %>, Model model) {
163
+ <% if (hasEmbeddedId) { %><%= idType %> <%= ymlConfig.idField %> = (new <%= embeddedIdType %>()).fromPathVariables(<%= embeddedIdFields.map(f => f.name).join(', ') %>);<% }%>
164
+ <%= classPrefix %>DetailDTO item = service.findById(<%= ymlConfig.idField %>, <%= classPrefix %>DetailDTO.class)
165
+ .orElseThrow(() -> new RuntimeException("<%= entityName %> not found"));
166
+
167
+ model.addAttribute("item", item);
168
+ model.addAttribute("pageTitle", "<%= entityComment.split(':')[0] %> Edit");
169
+ addSelectData(model);
170
+
171
+ return "<%= templatePath %>/edit";
172
+ }
173
+
174
+ /**
175
+ * Displays the create page for a new <%= entityName %> entity
176
+ *
177
+ * @param model Spring MVC Model
178
+ * @return The view name for the edit page
179
+ */
180
+ @GetMapping("/create")
181
+ @PreAuthorize("hasPermission('<%= entityName %>', 'create')")
182
+ public String create(Model model) {
183
+ model.addAttribute("pageTitle", "<%= entityComment.split(':')[0] %> Create");
184
+ addSelectData(model);
185
+
186
+ return "<%= templatePath %>/edit";
187
+ }
188
+
189
+ //----------------------------------------------------------
190
+
191
+ /**
192
+ * Adds select box data to the model
193
+ *
194
+ * @param model Spring MVC Model
195
+ */
196
+ private void addSelectData(Model model) {
197
+ <%
198
+ // Add search conditions for reference fields (remove duplicates)
199
+ addedServices.forEach(entity => {
200
+ const fieldName = Object.values(ymlConfig.fields).find(f => f.reference?.entity === entity).name;
201
+ %>
202
+ SearchCondition<<%= entity %>SearchDTO> <%= _.camelCase(entity) %>Condition = SearchConditionBuilder
203
+ .create(<%= entity %>SearchDTO.class)
204
+ .build();
205
+ model.addAttribute(
206
+ "<%= _.camelCase(entity) %>s",
207
+ <%= _.camelCase(entity) %>Service.findAllWithSearch(<%= _.camelCase(entity) %>Condition).getContent()
208
+ );
209
+ <% }); %>
210
+ }
211
+ }