codegen
所属分类:自动编程
开发工具:Python
文件大小:10KB
下载次数:0
上传日期:2021-02-24 07:55:49
上 传 者:
sh-1993
说明: 一个最小但功能强大的工具,可以用任何编程语言生成代码
(A minimal but powerful tool to generate code in any programming languages)
文件列表:
LICENSE (1068, 2021-02-24)
codegen.py (4698, 2021-02-24)
example_gen.sh (198, 2021-02-24)
templates (0, 2021-02-24)
templates\__ComponentName__View.jsx (143, 2021-02-24)
templates\ios (0, 2021-02-24)
templates\ios\MVVM (0, 2021-02-24)
templates\ios\MVVM\__ModuleName__Cell (0, 2021-02-24)
templates\ios\MVVM\__ModuleName__Cell\__ModuleName__TableViewCell.swift (124, 2021-02-24)
templates\ios\MVVM\__ModuleName__ViewController.swift (220, 2021-02-24)
templates\ios\MVVM\__ModuleName__ViewModel.swift (163, 2021-02-24)
templates\ios\VIPER (0, 2021-02-24)
templates\ios\VIPER\__ModuleName__Interactor.swift (318, 2021-02-24)
templates\ios\VIPER\__ModuleName__Interfaces.swift (432, 2021-02-24)
templates\ios\VIPER\__ModuleName__Presenter.swift (804, 2021-02-24)
templates\ios\VIPER\__ModuleName__ViewController.swift (522, 2021-02-24)
templates\ios\VIPER\__ModuleName__Wireframe.swift (759, 2021-02-24)
templates\react-native (0, 2021-02-24)
templates\react-native\hooks-component (0, 2021-02-24)
templates\react-native\hooks-component\__ComponentName__.tsx (214, 2021-02-24)
# codegen
A minimal but powerful tool to generate code in any programming languages
## Usage
Download `codegen.py` file at https://raw.githubusercontent.com/dinhquan/codegen/main/codegen.py
Run this command to generate code:
```
python codegen.py -t
= = ...
```
For example:
```
python codegen.py -t templates/__ComponentName__View.jsx ComponentName=Article
```
In the below example, the template is a folder so everything inside this template will be generated:
```
python codegen.py \
-t templates/ios/VIPER \
ModuleName=User \
FileName={FILENAME} \
ProjectName=MyProject \
UserName=Quan \
Date=02/01/2021 \
Year=2021 \
OrganizationName=MyCompany
```
Use `{FILENAME}` to get the current file name as the value.
## Options
-h, --help Print the help text.
-t, --template Path to the template file or folder. It can be relative or absolute path.
-o, --output Output directory. Optional. Default is the directory of codegen.py.
It can be relative or absolute path.
## Create templates
Templates are required to generate code. You must create your template or use existing templates in this repo.
Templates can be a file or folder so you can generate code for a file or a group of files/folders in a folder by one command.
A template file can contain one or many variables. A variable must be wrap with double underscore `____`;
For example we have this template:
```jsx
// File: __ComponentName__View.jsx
import React from 'react';
function __ComponentName__View() {
return (
);
}
export default React.memo(__ComponentName__View);
```
To generate code for this file, you need to execute this command:
```
python codegen.py -t templates/__ComponentName__View.jsx ComponentName=Article
```
Then you will have this file:
```jsx
// File: ArticleView.jsx
import React from 'react';
function ArticleView() {
return (
);
}
export default React.memo(ArticleView);
```
## Best practice
You should have `codegen.py` in the root directory of your project, and the templates inside your project.
Python is built in MacOS, Linux and Windows, you and your teammates don't have to install anything.
Just one line command `python codegen.py -t ....`, files/folders with same structure as your template are generated in less than 1 second.
## Contribution
Because the purpose of this tool is able to generate code in various programming languages, it should have a large number of templates in lots of languages.
Your contributions for templates / pull request are appreciated and welcomed.
近期下载者:
相关文件:
收藏者: