add custom doc (#9)

* add custom doc
This commit is contained in:
TheoneFx
2022-12-09 14:23:33 +08:00
committed by GitHub
parent f19169d1ca
commit 7438838bed
8 changed files with 184 additions and 0 deletions

76
docs/CODE_OF_CONDUCT.md Normal file
View File

@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at cloud-native-app-initializer@googlegroups.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1,
available at https://www.contributor-covenant.org/version/2/1/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

36
docs/CONTRIBUTING-zh.md Normal file
View File

@@ -0,0 +1,36 @@
# 代码贡献
我们致力于在云原生时代,构建一个开源、中立、功能强大、社区生态繁荣的脚手架工具。社区欢迎外部用户参与到社区建设中来!
## 如何贡献
在贡献代码之前,请您稍微花一些时间了解为 cloud-native-app-initializer 贡献代码的流程。
### 贡献什么?
我们随时都欢迎任何贡献无论是简单的错别字修正BUG 修复还是增加新功能。请踊跃提出问题或发起 PR。我们同样重视文档以及与其它开源项目的整合欢迎在这方面做出贡献。
如果是一个比较复杂的修改,建议先在 Issue 中添加一个 Feature 标识,并简单描述一下设计和修改点。
### Fork 仓库
* 点击 本项目 右上角的 Fork 图标 将 alibaba/cloud-native-app-initializer fork 到自己的空间。
* 将自己账号下的 cloud-native-app-initializer 仓库 clone 到本地,例如我的账号的 steverao那就是执行 git clone https://github.com/steverao/cloud-native-app-initializer.git 进行 clone 操作。
### 配置 Github 信息
* 在自己的机器执行 git config --list ,查看 git 的全局用户名和邮箱。
* 检查显示的 user.name 和 user.email 是不是与自己 github 的用户名和邮箱相匹配。
* 如果公司内部有自己的 gitlab 或者使用了其他商业化的 gitlab则可能会出现不匹配的情况。这时候你需要为 cloud-native-app-initializer 项目单独设置用户名和邮箱。
* 设置用户名和邮箱的方式请参考 github 官方文档,设置用户名,设置邮箱。
### Merge 最新代码
fork 出来的代码后,原仓库 Master 分支可能出现了新的提交,这时候为了避免提交的 PR 和 Main 中的提交出现冲突,需要及时 merge Main 分支。
### 配置代码格式规范
作为一个 Spring 相关项目,在后端代码规范方面直接沿用了 Spring Cloud 项目规范,在正式开始之前请参考相关 [代码格式规范说明](https://github.com/spring-cloud/spring-cloud-build#checkstyle) ,提交代码前需要先配置好代码格式规范。
### 开发、提交、Push
开发自己的功能,开发完毕后建议使用 mvn clean install 命令确保能修改后的代码能在本地编译通过。执行该命令的同时还能以 spring 的方式自动格式化代码。然后再提交代码
### merge 最新代码
同样,提交 PR 前,需要 rebase master 分支的代码,具体操作步骤请参考之前的章节。
如果出现冲突,需要先解决冲突。
### 提交Pull Request(PR)
提交 PR根据 Pull request template 写明修改点和实现的功能,等待 code review 和 合并,成为 Cloud Native App Initializer Contributor为更好用的脚手架一起努力

37
docs/CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,37 @@
# Code Contribution
We are committed to building an open source, neutral, powerful, and community ecologically prosperous scaffolding tool in the cloud-native era. The community welcomes external users to participate in community construction!
## How to contribute
Before contributing, please take a moment to understand the process of contributing to cloud-native-app-initializer.
### Contribute what?
We welcome any contribution at any time, whether it's a simple typo fix, bug fix, or new feature addition. Feel free to ask questions or initiate PRs. We also value documentation and integration with other open source projects, and welcome contributions in this regard.
If it is a more complex modification, it is recommended to add a Feature flag to the Issue first, and briefly describe the design and modification points.
### Fork Repo
* Click the Fork icon in the upper right corner of this project to fork alibaba/cloud-native-app-initializer to your own space.
* Clone the cloud-native-app-initializer warehouse under your own account to the local, such as the steverao of my account, that is to execute git clone https://github.com/steverao/cloud-native-app-initializer.git to clone operate.
### Configure Github
* Execute git config --list on your own machine to view the global username and mailbox of git.
* Check if the displayed user.name and user.email match your github username and email.
* If the company has its own gitlab or uses other commercial gitlabs, there may be a mismatch. At this time, you need to set the username and email address separately for the cloud-native-app-initializer project.
* For how to set user name and email address, please refer to github official documentation, set user name, set email address.
### Merge latest code
After forking the code, a new submission may appear in the Master branch of the original warehouse. At this time, in order to avoid conflicts between the submitted PR and the submission in Main, it is necessary to merge the Main branch in time.
### Configuration Code Conversion
As a Spring-related project, it directly follows the Spring Cloud project specification in terms of back-end code specification. Please refer to the relevant [code format specification description](https://github.com/spring-cloud/spring-cloud- build#checkstyle) , you need to configure the code format specification before submitting the code.
### Develop, Submit, Push
Develop your own functions. After the development is complete, it is recommended to use the `mvn clean install` command to ensure that the modified code can be compiled locally. While executing this command, the code can be automatically formatted in the way of spring. Then submit the code
### Merge latest code
Similarly, before submitting a PR, you need to rebase the code of the master branch. For specific steps, please refer to the previous chapter.
If conflicts arise, they need to be resolved first.
### 提交Pull Request(PR)
Submit a PR, specify the modification points and implemented functions according to the Pull request template, wait for code review and merge, become a Cloud Native App Initializer Contributor, and work together for better scaffolding!

167
docs/howToCustom-zh.md Normal file
View File

@@ -0,0 +1,167 @@
# 如何自定义脚手架内容
云原生应用脚手架默认包含的依赖和代码并不一定适合所有用户的使用。例如有些同学需要增加一些自己的依赖或者实例代码又或者是修改父pom并在自己的环境中使用。
大部分情况下,对平台数据的定制是非常主要的定制诉求,其次才是其他功能性的定制需求,本文着重介绍如何自定义平台的数据部分。
![image.png](img/preview.png)
脚手架的数据分为以下两个部分:
- 元数据一组以yaml格式维护的数据集包含Spring Boot 版本、Jdk 版本、可选依赖等等相关信息;
- 代码模板:一系列使用 mustache 语法,按照组件维度维护的代码片段,在选择对应的组件时自动渲染这部分示例代码;
## 元数据
默认的版本中自带了一套默认的元数据配置,存放在 `initializer-generator/src/main/resources/metadata.yaml`下。
如果需要修改这个配置的加载路径,可以通过更改参数 `application.metadata-path`的值来实现。例如,如果在本地有一个元数据配置文件,存放在 `/home/theonefx/meta.yaml`,则将这个值设置到`application.metadata-path`上即可。
当然你也可以使用 Spring Boot 的 profile 以及配置加载机制来实现更多的配置方式。不过需要注意的是,设置了自定义配置文件以后,原有的元数据配置将不再生效;
### 元数据配置字段
| 字段 key | 说明 |
| --- | --- |
| initializr.env.boms | 以 Bom 方式引入的依赖信息,关键维护了 bom 的坐标,以及跟 Spring Boot 版本的映射关系; |
| initializr.env.gradle | gradle的基本配置默认即可 |
| initializr.env.platform | 平台API的版本默认即可 |
| initializr.env.repositories | 依赖中,如果有需要单独声明的所在仓库信息,这里是对应的仓库列表 |
| initializr.dependencies | 分组管理的平台可选依赖,这里是数据定制的重要配置。 详见下文 |
| initializr.types | 构建工具以及输出的工程格式配置maven、gradle |
| initializr.packagings | 指定最终的编译打包方式jar 包或者是 war 包 |
| initializr.javaVersions | java 的可选版本,以及默认值 |
| initializr.languages | 项目使用的语言java 、kotlin、groovy |
| initializr.bootVersions | Spring Boot 的可选版本以及默认值 |
| initializr.architecture | 架构的可选项,以及相关模块配置。默认的 none 单模块一定要有 详见下文 |
### 版本范围
由于平台使用了 spring.initializr 作为底层框架,所以必须依赖于其提供的版本范围概念(该范围特指 Spring Boot 的版本)。这里可以直接访问 Spring 的文档以确认版本范围的规范:
[Spring 范围文档](https://docs.spring.io/initializr/docs/current-SNAPSHOT/reference/html/#dependencies-compatibility-range)
### 组件依赖配置
```yaml
dependencies:
- name: Spring Cloud Alibaba
bom: spring-cloud-alibaba
compatibilityRange: "[2.0.0.RELEASE,2.6.11]"
content:
- name: Nacos Service Discovery
id: sca-nacos-discovery
description: 通过nacos实现的服务发现平台.
groupId: com.alibaba.cloud
artifactId: spring-cloud-starter-alibaba-nacos-discovery
starter: false
links:
- rel: reference
href: https://spring-cloud-alibaba-group.github.io/github-pages/hoxton/en-us/index.html#_spring_cloud_alibaba_nacos_discovery
- rel: guide
href: https://github.com/alibaba/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme.md
description: Nacos Service Discovery Example
```
组件依赖,有两层配置,外层称为“依赖分组”,内层为具体的组件依赖:
- 依赖分组
- name 分组名称;
- bom对应引入的 bom可选如果配置了 bom 则版本依赖全部由 bom 控制;
- compatibilityRange版本范围可选。如果配置该值代表支持的 Spring Boot 版本范围如果不配置则不关注Spring Boot 版本;
- content具体组件依赖
- 组件依赖
- name依赖名称展示用
- id依赖的唯一标识需要全局唯一
- description依赖描述展示用
- groupId、artifactId依赖坐标
- starter是否是 Spring Boot 的 starter
- links用于生成 help 文档中放置的关联连接
### 架构配置
```yaml
architecture:
- id: none
name: 单模块
default: true
- id: mvc
name: MVC架构
subModules:
- name: start
description: 入口模块,引导工程启动以及基础配置
main: true
- name: web
description: web 模块,对应 MVC 的 V 概念,存放视图层的逻辑
- name: service
description: service 模块,对应 MVC 的 M 概念,存放核心业务逻辑代码
```
支持多个架构
- id架构的唯一标识默认的 none 必须有
- name架构名称
- default是否默认架构该值影响到浏览器默认选择
- subModules多架构的子模块配置
- name子模块名称
- description子模块说明
- main是否是入口模块
## 代码模板
### 模板加载&目录
默认情况下,代码模板存放在 `initializer-generator/src/main/resources/templates/codes`目录下,如下图:
![image.png](img/code_template.png)
如果需要在另外的地方维护代码模板,可以通过设置 `application.democode-path`参数实现。
代码模板目录下, 按照 `组件依赖.id`来隔离各个组件的代码模板,其一层目录是根据语言、类型存放模板文件,如下:
```
.
├── groovy
│ ├── BasicController.groovy.mustache
│ ├── PathVariableController.groovy.mustache
│ └── User.groovy.mustache
├── java
│ ├── BasicController.java.mustache
│ ├── PathVariableController.java.mustache
│ └── User.java.mustache
└── resources
├── application.properties.mustache
└── static
└── index.html.mustache
```
- java存放 java 语言的代码模板
- groovy 存放 groofy 语言的代码模板
- kotlin存放 kotlin 语言的代码模板
- resources通用的配置文件放在目标工程的 resource 目录下
由于 java 语言要求 .java 文件必须放在与包名一致的文件目录下,在维护代码模板时,这个规范会导致模板目录层数过多。所以这里给出了一个便捷方法,代码模板不需要按照包名维护,只需要声明好 package 即可,生成代码时会根据 package 的值自动创建正确的目录。
### 模板变量
平台默认支持一些模板变量,用于代码模板的编写:
| 变量 | 说明 | 实例值 |
| --- | --- | --- |
| appShotName | 项目简短名称 | app |
| applicationName | 项目全名 | Application |
| basePackage | 项目的base包路径 | com.theonef.testapp |
| version | 项目版本 | 1.0 |
| spring-boot.version | Spring Boot 版本 | 2.2.6.RELEASE |
| java.version | jdk 版本 | 1.8 |
| artifactId | 项目坐标 | testapp |
| groupId | 项目坐标 | com.theonef |
| module | 当前模块 | web |
# 运行方式自定义
## JDK 本地启动
这个很简单jdk 的启动方式、maven 的启动方式都可以用来启动脚手架工程:
### jdk
```bash
mvn package
java -jar initializer-generator/target/initializer-generator-0.8.jar
```
### maven
```bash
cd initializer-generator
mvn spring-boot:run
```
## Docker 启动
```bash
docker pull registry.cn-hangzhou.aliyuncs.com/cloud-native-app-initializer/initializer:latest
docker run -it -p 127.0.0.1:7001:7001 registry.cn-hangzhou.aliyuncs.com/cloud-native-app-initializer/initializer:latest
```
当然,你可以通过参数的方式,通过指定 DEMOCODE_PATH 和 METADATA_PATH 的方式来修改元数据以及代码模板的配置;

BIN
docs/img/code_template.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB

BIN
docs/img/preview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB