@simplix-boot/cli 2.0.0 → 2.0.2

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.ko.md ADDED
@@ -0,0 +1,82 @@
1
+ [English](./README.md) | **한국어**
2
+
3
+ # SimpliX CLI
4
+
5
+ `simplix-boot`는 JPA 엔티티를 읽어 그 엔티티를 SimpliX로 제공하는 서비스, REST 컨트롤러, DTO, 테스트를 생성합니다. 필드별 동작은 yml 파일에 한 번만 적으면 되고, 이후 템플릿이 바뀌어도 생성된 코드와 직접 고친 내용을 함께 유지합니다.
6
+
7
+ ![엔티티는 config, generate, promote를 거쳐 모듈 소스가 됩니다. 개발자는 엔티티 yml을 편집하고, 템플릿이 코드의 모양을 정하며, generated가 모듈로 옮긴 파일과 템플릿의 일치 여부를 보고합니다.](../docs/assets/figures/cli-readme-pipeline.ko.svg)
8
+
9
+ ## 언제 사용하나
10
+
11
+ - 엔티티를 추가하고, 프로젝트의 다른 SimpliX API와 같은 형태의 CRUD API가 필요할 때
12
+ - 필드를 바꾸고 DTO, 검색 조건, 테스트에 그 변경을 반영해야 할 때
13
+ - 생성된 클래스를 직접 고친 내용을 다음 템플릿 변경 이후에도 유지해야 할 때
14
+
15
+ 엔티티 하나에 대응하지 않는 화면(대시보드, 여러 집계를 합친 보고서)은 직접 작성합니다. CLI가 생성의 근거로 삼을 엔티티가 없기 때문입니다.
16
+
17
+ ## 요구 사항
18
+
19
+ - Node.js 20 이상
20
+ - SimpliX에 의존하는 Gradle 또는 Maven 프로젝트
21
+ - 프로젝트의 SimpliX와 같은 릴리스 라인의 CLI
22
+
23
+ | 프로젝트 | SimpliX 라인 | 설치 |
24
+ |---|---|---|
25
+ | Spring Boot 4 | 2.x | `npm install -g @simplix-boot/cli` |
26
+ | Spring Boot 3 | 1.x | `npm install -g @simplix-boot/cli@spring-boot-3x` |
27
+
28
+ ## 설치
29
+
30
+ ```bash
31
+ # Spring Boot 4 projects (SimpliX 2.x)
32
+ npm install -g @simplix-boot/cli
33
+
34
+ # Spring Boot 3 projects (SimpliX 1.x)
35
+ npm install -g @simplix-boot/cli@spring-boot-3x
36
+
37
+ simplix-boot --version
38
+ ```
39
+
40
+ 설치하지 않고 실행하려면 같은 패키지 표기로 `npx @simplix-boot/cli <명령>`을 사용하세요. 팀 단위의 버전 고정과 프레임워크 체크아웃의 CLI를 실행하는 방법은 [버전 관리](docs/ko/managing-versions.md)에 있습니다.
41
+
42
+ ## 빠른 시작
43
+
44
+ `Author`라는 JPA 엔티티와 그 저장소가 이미 있는 프로젝트의 루트에서 실행하세요.
45
+
46
+ ```bash
47
+ # 1. Create the .simplix folder, then write .simplix/generator-simplix.json
48
+ simplix-boot init
49
+
50
+ # 2. Write .simplix/entity/Author.yml from the entity
51
+ simplix-boot config Author
52
+
53
+ # 3. Edit the yml, then generate the code into generated/
54
+ simplix-boot generate Author
55
+
56
+ # 4. Move the generated files into a module
57
+ simplix-boot promote Author --module catalog
58
+
59
+ # 5. Check that every promoted file matches the templates
60
+ simplix-boot generated
61
+ ```
62
+
63
+ [시작하기](docs/ko/getting-started.md)에서 같은 단계를 설정 파일, yml 편집 내용, 명령별 출력과 함께 따라 할 수 있습니다.
64
+
65
+ ## 문서
66
+
67
+ | 하려는 일 | 문서 |
68
+ |---|---|
69
+ | 첫 API를 단계별로 생성 | [시작하기](docs/ko/getting-started.md) |
70
+ | 생성되는 코드의 모양 변경 | [템플릿 사용자 지정](docs/ko/customizing-templates.md) |
71
+ | 템플릿이나 yml을 바꾼 뒤 직접 고친 내용을 유지하며 다시 생성 | [생성 코드 갱신](docs/ko/updating-generated-code.md) |
72
+ | 맞는 라인 설치, 버전 고정, 체크아웃 연결 | [버전 관리](docs/ko/managing-versions.md) |
73
+ | generator-simplix를 쓰던 프로젝트 전환 | [generator-simplix에서 전환](docs/ko/migrating-from-generator-simplix.md) |
74
+ | 명령과 옵션 확인 | [명령 레퍼런스](docs/ko/command-reference.md) |
75
+ | 설정 파일과 엔티티 yml의 키 확인 | [설정 레퍼런스](docs/ko/configuration-reference.md) |
76
+ | 템플릿 변수와 내장 템플릿 확인 | [템플릿 레퍼런스](docs/ko/template-reference.md) |
77
+ | 명령의 내부 동작 이해 | [동작 원리](docs/ko/how-it-works.md) |
78
+ | 오류 해결 | [문제 해결](docs/ko/troubleshooting.md) |
79
+
80
+ ## 라이선스
81
+
82
+ SimpleCORE License 1.0 (SCL-1.0). [LICENSE](../LICENSE)를 참조하세요.
package/README.md CHANGED
@@ -1,145 +1,82 @@
1
+ **English** | [한국어](./README.ko.md)
2
+
1
3
  # SimpliX CLI
2
4
 
3
- JPA 엔티티에서 SimpliX 서비스, REST 컨트롤러, DTO, 테스트 코드를 생성하는 명령줄 도구입니다. npm 패키지 이름은 `@simplix-boot/cli`이고 실행 파일 이름은 `simplix-boot`입니다.
5
+ `simplix-boot` reads a JPA entity and writes the service, REST controller, DTOs and tests that expose it through SimpliX. You describe each field once in a yml file, and the CLI keeps the generated code and your own edits together when a template changes later.
4
6
 
5
- ## 주요 기능
7
+ ![An entity becomes module source through config, generate and promote. The developer edits the entity yml, templates decide the code, and generated reports whether promoted files still match the templates.](../docs/assets/figures/cli-readme-pipeline.en.svg)
6
8
 
7
- - ✔ **엔티티 분석** - JPA 엔티티 소스를 읽어 필드, 식별자, 연관 관계를 담은 yml을 작성합니다.
8
- - ✔ **코드 생성** - yml과 템플릿으로 서비스, REST 컨트롤러, DTO, 서비스 테스트를 생성합니다.
9
- - ✔ **내장 템플릿** - 템플릿을 CLI에 포함해 배포하므로 프로젝트에 템플릿을 복사하지 않아도 생성할 수 있습니다.
10
- - ✔ **프로젝트 템플릿 우선** - `.simplix/templates`에 같은 상대 경로의 파일을 두면 내장 템플릿 대신 그 파일로 렌더링합니다.
11
- - ✔ **추적 렌더(tracked render)** - 모듈로 옮긴 파일에 렌더 지문(render fingerprint)을 기록하고, 템플릿이 바뀌면 직접 고친 내용에 3방향 병합으로 반영합니다.
12
- - ✔ **버전 고정** - 프로젝트가 요구하는 CLI 버전을 설정 파일에 기록하고, 더 낮은 버전의 CLI로는 생성하지 않습니다.
9
+ ## When to use it
13
10
 
14
- ## 빠른 시작
11
+ - You add an entity and need its CRUD API in the shape every other SimpliX API of the project has.
12
+ - You change a field and want the DTOs, the search conditions and the tests to follow.
13
+ - You want hand edits in generated classes to survive the next template change.
15
14
 
16
- ### 1. 실행
15
+ A screen that is not backed by one entity (a dashboard, a report that joins several aggregates) is written by hand; the CLI has nothing to generate it from.
17
16
 
18
- 설치 없이 실행하려면 `npx`를 사용하세요.
17
+ ## Requirements
19
18
 
20
- ```bash
21
- npx @simplix-boot/cli help
22
- ```
19
+ - Node.js 20 or later
20
+ - A Gradle or Maven project that depends on SimpliX
21
+ - The CLI of the same release line as the project's SimpliX
23
22
 
24
- 자주 쓰는 환경에서는 전역으로 설치하세요.
23
+ | Your project | SimpliX line | Install |
24
+ |---|---|---|
25
+ | Spring Boot 4 | 2.x | `npm install -g @simplix-boot/cli` |
26
+ | Spring Boot 3 | 1.x | `npm install -g @simplix-boot/cli@spring-boot-3x` |
27
+
28
+ ## Install
25
29
 
26
30
  ```bash
31
+ # Spring Boot 4 projects (SimpliX 2.x)
27
32
  npm install -g @simplix-boot/cli
28
- simplix-boot help
29
- ```
30
33
 
31
- SimpliX 프레임워크 체크아웃이 있으면 그 안의 `simplix-cli`를 전역 명령으로 연결해 사용할 수 있습니다. 게시된 버전을 기다리지 않고 체크아웃의 현재 소스로 실행합니다. 확인과 해제 방법은 [개요](docs/ko/overview.md#설치와-실행)에 있습니다.
34
+ # Spring Boot 3 projects (SimpliX 1.x)
35
+ npm install -g @simplix-boot/cli@spring-boot-3x
32
36
 
33
- ```bash
34
- cd <simplix checkout>/simplix-cli
35
- npm ci
36
- npm link
37
37
  simplix-boot --version
38
38
  ```
39
39
 
40
- ### 2. 프로젝트 설정
40
+ To run it without installing, use `npx @simplix-boot/cli <command>` with the same package spec. [Managing versions](docs/en/managing-versions.md) covers pinning a version for a team and running the CLI from a framework checkout.
41
+
42
+ ## Quick start
41
43
 
42
- 프로젝트 루트에서 `.simplix` 폴더를 만듭니다.
44
+ Run these in the root of a project that already has a JPA entity named `Author` and its repository.
43
45
 
44
46
  ```bash
47
+ # 1. Create the .simplix folder, then write .simplix/generator-simplix.json
45
48
  simplix-boot init
46
- ```
47
-
48
- `.simplix/generator-simplix.json`을 작성합니다.
49
-
50
- ```json
51
- {
52
- "entity": {
53
- "scanPath": "src/main/java",
54
- "basePackage": "com.example.library.domain"
55
- },
56
- "repository": {
57
- "scanPath": "src/main/java",
58
- "deriveFromEntity": true
59
- },
60
- "target": {
61
- "generatedBasePath": "generated/main/java/com/example/library/web",
62
- "basePackage": "com.example.library.web",
63
- "targetPath": {
64
- "service": "{modulePath}/service",
65
- "controllerRest": "{modulePath}/controller",
66
- "dto": "{modulePath}/dto"
67
- },
68
- "testGeneratedBasePath": "generated/test/java/com/example/library/web",
69
- "testTargetPath": {
70
- "serviceTest": "{modulePath}/service"
71
- }
72
- },
73
- "promote": {
74
- "moduleRoot": "modules"
75
- }
76
- }
77
- ```
78
49
 
79
- ### 3. 사용
50
+ # 2. Write .simplix/entity/Author.yml from the entity
51
+ simplix-boot config Author
80
52
 
81
- ```bash
82
- # Write .simplix/entity/Book.yml from the Book entity
83
- simplix-boot config Book
84
-
85
- # Edit the yml, then generate the code into the generated tree
86
- simplix-boot generate Book
53
+ # 3. Edit the yml, then generate the code into generated/
54
+ simplix-boot generate Author
87
55
 
88
- # Move the generated files into a module as tracked renders
89
- simplix-boot promote Book --module catalog
56
+ # 4. Move the generated files into a module
57
+ simplix-boot promote Author --module catalog
90
58
 
91
- # Report the state of every promoted file
59
+ # 5. Check that every promoted file matches the templates
92
60
  simplix-boot generated
93
61
  ```
94
62
 
95
- ## 설정 요약
96
-
97
- `.simplix/generator-simplix.json`의 주요 키입니다. 전체 목록은 [설정 레퍼런스](docs/ko/configuration.md)에 있습니다.
98
-
99
- | 키 | 필수 | 설명 |
100
- |----|------|------|
101
- | `entity.scanPath` | 아니요 | 엔티티 소스를 찾는 경로입니다. 지정하지 않으면 `src/main/java`를 사용합니다. |
102
- | `target.generatedBasePath` | 예 | 생성한 소스를 쓰는 경로입니다. |
103
- | `target.basePackage` | 예 | 생성한 클래스의 기준 패키지입니다. |
104
- | `target.targetPath` | 예 | 구성 요소별 하위 경로입니다. 경로를 지정한 구성 요소만 생성합니다. |
105
- | `template` | 아니요 | 구성 요소별 템플릿 상대 경로입니다. |
106
- | `supportClasses` | 아니요 | 생성 코드가 호출하는 애플리케이션 클래스의 전체 이름입니다. |
107
- | `generator.version` | 아니요 | 프로젝트가 요구하는 CLI 버전입니다. |
108
-
109
- ## 아키텍처
110
-
111
- ```
112
- simplix-cli/
113
- +-- bin/
114
- | +-- simplix-boot.js # Executable entry
115
- +-- src/
116
- | +-- cli.js # Command dispatch, help, exit codes
117
- | +-- commands/ # init, config, generate, promote, generated, templates, version
118
- | +-- lib/
119
- | +-- analysis/ # JPA entity source analysis
120
- | +-- config/ # Entity yml construction
121
- | +-- generate/ # File plan, search fields, template variables
122
- | +-- templates.js # Project template first, built-in template otherwise
123
- | +-- tracked-render.js # Render fingerprint, stored base, three-way merge
124
- +-- templates/ # Built-in templates
125
- +-- test/ # node:test suites and the fixture project
126
- ```
127
-
128
- ## 문서
129
-
130
- | 문서 | 설명 |
131
- |------|------|
132
- | [개요](docs/ko/overview.md) | 처리 흐름, 구성 요소, 설정 구조 |
133
- | [명령 가이드](docs/ko/command-guide.md) | 명령별 인자, 옵션, 종료 코드 |
134
- | [템플릿 가이드](docs/ko/template-guide.md) | 내장 템플릿, 프로젝트 템플릿, 템플릿 변수 |
135
- | [설정 레퍼런스](docs/ko/configuration.md) | `generator-simplix.json`과 엔티티 yml의 키 |
136
- | [전환 가이드](docs/ko/migration-guide.md) | `generator-simplix` 프로젝트에서 사용하는 방법 |
63
+ [Getting started](docs/en/getting-started.md) walks through the same steps with the configuration file, the yml edits and the output of each command.
137
64
 
138
- ## 요구 사항
65
+ ## Documentation
139
66
 
140
- - Node.js 20 이상
141
- - Git (`promote`의 3방향 병합에 `git merge-file`을 사용합니다)
67
+ | If you want to | Read |
68
+ |---|---|
69
+ | generate your first API step by step | [Getting started](docs/en/getting-started.md) |
70
+ | change what the generated code looks like | [Customizing templates](docs/en/customizing-templates.md) |
71
+ | regenerate after a template or yml change without losing edits | [Updating generated code](docs/en/updating-generated-code.md) |
72
+ | install the right line, pin a version, link a checkout | [Managing versions](docs/en/managing-versions.md) |
73
+ | move a project from generator-simplix | [Migrating from generator-simplix](docs/en/migrating-from-generator-simplix.md) |
74
+ | look up a command or an option | [Command reference](docs/en/command-reference.md) |
75
+ | look up a key of the configuration file or the entity yml | [Configuration reference](docs/en/configuration-reference.md) |
76
+ | look up a template variable or a built-in template | [Template reference](docs/en/template-reference.md) |
77
+ | understand what happens inside each command | [How it works](docs/en/how-it-works.md) |
78
+ | fix an error | [Troubleshooting](docs/en/troubleshooting.md) |
142
79
 
143
- ## 라이선스
80
+ ## License
144
81
 
145
- SimpleCORE License 1.0 (SCL-1.0)
82
+ SimpleCORE License 1.0 (SCL-1.0). See [LICENSE](../LICENSE).
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { main } from '../src/cli.js';
3
+ import { tolerateClosedReader } from '../src/lib/console.js';
3
4
 
5
+ tolerateClosedReader(process.stdout);
4
6
  process.exitCode = main(process.argv.slice(2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplix-boot/cli",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Command line tool that generates SimpliX Spring Boot code (services, controllers, DTOs, tests) from JPA entities",
5
5
  "type": "module",
6
6
  "bin": {
@@ -41,6 +41,7 @@
41
41
  },
42
42
  "license": "SEE LICENSE IN LICENSE",
43
43
  "publishConfig": {
44
- "access": "public"
44
+ "access": "public",
45
+ "tag": "latest"
45
46
  }
46
47
  }
@@ -52,6 +52,19 @@ export const symbols = {
52
52
  },
53
53
  };
54
54
 
55
+ /**
56
+ * Lets the process finish when the reader of a stream has gone, as in
57
+ * `simplix-boot generate Book | head`. A command has done its work by the time the failed write is
58
+ * reported, so the work and the exit code stand; any other stream error is still fatal.
59
+ *
60
+ * @param {import('node:stream').Writable} stream
61
+ */
62
+ export function tolerateClosedReader(stream) {
63
+ stream.on('error', error => {
64
+ if (error.code !== 'EPIPE') throw error;
65
+ });
66
+ }
67
+
55
68
  /**
56
69
  * Where a command writes: progress and reports as lines, and a machine-readable result as the one
57
70
  * line a script reads.
@@ -7,6 +7,7 @@ import {
7
7
  compareReleaseVersions,
8
8
  getGeneratorPackageName,
9
9
  getGeneratorVersion,
10
+ getReleaseTag,
10
11
  isSnapshotVersion,
11
12
  toReleaseVersion,
12
13
  } from './version-utils.js';
@@ -57,13 +58,13 @@ export function recordGeneratorVersion(configPath, version) {
57
58
  }
58
59
 
59
60
  /**
60
- * Latest version published to the npm registry, or null when the registry
61
- * cannot be reached or the package has never been published.
61
+ * Latest version of this build's release line published to the npm registry, or null when the
62
+ * registry cannot be reached or the line has never been published.
62
63
  */
63
- export function fetchLatestPublishedVersion(packageName = getGeneratorPackageName()) {
64
+ export function fetchLatestPublishedVersion(packageName = getGeneratorPackageName(), releaseTag = getReleaseTag()) {
64
65
  let output;
65
66
  try {
66
- output = execFileSync(NPM_BIN, ['view', packageName, 'version'], {
67
+ output = execFileSync(NPM_BIN, ['view', `${packageName}@${releaseTag}`, 'version'], {
67
68
  encoding: 'utf8',
68
69
  stdio: ['ignore', 'pipe', 'ignore'],
69
70
  timeout: NPM_LOOKUP_TIMEOUT_MS,
@@ -29,6 +29,14 @@ export function getGeneratorPackageName() {
29
29
  return readOwnPackageJson().name || '@simplix-boot/cli';
30
30
  }
31
31
 
32
+ /**
33
+ * The npm dist-tag this build's release line is published under. Each release line publishes
34
+ * under its own tag, so the newest version of one line is never offered to a project on another.
35
+ */
36
+ export function getReleaseTag() {
37
+ return readOwnPackageJson().publishConfig?.tag || 'latest';
38
+ }
39
+
32
40
  /**
33
41
  * Development builds carry a -SNAPSHOT suffix; released builds never do.
34
42
  */
@@ -250,9 +250,9 @@ class <%= classPrefix %>ServiceTest {
250
250
  entity.set<%= setterSuffix %>(true);
251
251
  <% }
252
252
  }
253
- }); %>
254
- entity.setCreatedAt(Instant.now());
255
- entity.setUpdatedAt(Instant.now());
253
+ }); %><% if (ymlConfig.fields?.createdAt) { %>
254
+ entity.setCreatedAt(Instant.now());<% } %><% if (ymlConfig.fields?.updatedAt) { %>
255
+ entity.setUpdatedAt(Instant.now());<% } %>
256
256
 
257
257
  // Setup DTOs
258
258
  createDto = new <%= classPrefix %>CreateDTO();
@@ -161,9 +161,9 @@ class <%= classPrefix %>TreeServiceTest {
161
161
  entity.set<%= field.name.charAt(0).toUpperCase() + field.name.slice(1) %>(true);
162
162
  <% }
163
163
  }
164
- }); %>
165
- entity.setCreatedAt(Instant.now());
166
- entity.setUpdatedAt(Instant.now());
164
+ }); %><% if (ymlConfig.fields?.createdAt) { %>
165
+ entity.setCreatedAt(Instant.now());<% } %><% if (ymlConfig.fields?.updatedAt) { %>
166
+ entity.setUpdatedAt(Instant.now());<% } %>
167
167
 
168
168
  // Setup child entity
169
169
  childEntity = new <%= entityName %>();
@@ -185,9 +185,9 @@ class <%= classPrefix %>TreeServiceTest {
185
185
  childEntity.set<%= field.name.charAt(0).toUpperCase() + field.name.slice(1) %>(true);
186
186
  <% }
187
187
  }
188
- }); %>
189
- childEntity.setCreatedAt(Instant.now());
190
- childEntity.setUpdatedAt(Instant.now());
188
+ }); %><% if (ymlConfig.fields?.createdAt) { %>
189
+ childEntity.setCreatedAt(Instant.now());<% } %><% if (ymlConfig.fields?.updatedAt) { %>
190
+ childEntity.setUpdatedAt(Instant.now());<% } %>
191
191
 
192
192
  // Setup DTOs
193
193
  createDto = new <%= classPrefix %>CreateDTO();