refactor: 迁移出若干模块

This commit is contained in:
力皓 2020-12-04 19:36:17 +08:00
parent 67651c899a
commit 0c11173bb3
3642 changed files with 68 additions and 839732 deletions

View File

@ -1,567 +0,0 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
<a name="0.13.1-29"></a>
## [0.13.1-29](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-28...v0.13.1-29) (2020-12-03)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-28"></a>
## [0.13.1-28](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-27...v0.13.1-28) (2020-12-03)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-27"></a>
## [0.13.1-27](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-26...v0.13.1-27) (2020-12-02)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-26"></a>
## [0.13.1-26](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-25...v0.13.1-26) (2020-12-02)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-25"></a>
## [0.13.1-25](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-24...v0.13.1-25) (2020-12-01)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-24"></a>
## [0.13.1-24](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-23...v0.13.1-24) (2020-11-26)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-23"></a>
## [0.13.1-23](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-22...v0.13.1-23) (2020-11-25)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-22"></a>
## [0.13.1-22](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-19...v0.13.1-22) (2020-11-25)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-19"></a>
## [0.13.1-19](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-18...v0.13.1-19) (2020-11-24)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-18"></a>
## [0.13.1-18](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-15...v0.13.1-18) (2020-11-20)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-15"></a>
## [0.13.1-15](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-11...v0.13.1-15) (2020-11-18)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-12"></a>
## [0.13.1-12](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-11...v0.13.1-12) (2020-11-18)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-11"></a>
## [0.13.1-11](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-10...v0.13.1-11) (2020-11-02)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-10"></a>
## [0.13.1-10](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-9...v0.13.1-10) (2020-10-26)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-9"></a>
## [0.13.1-9](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-7...v0.13.1-9) (2020-10-26)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-8"></a>
## [0.13.1-8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-7...v0.13.1-8) (2020-10-26)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-7"></a>
## [0.13.1-7](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-6...v0.13.1-7) (2020-10-23)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-6"></a>
## [0.13.1-6](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-5...v0.13.1-6) (2020-10-22)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-5"></a>
## [0.13.1-5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-4...v0.13.1-5) (2020-10-20)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-4"></a>
## [0.13.1-4](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-3...v0.13.1-4) (2020-10-20)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-3"></a>
## [0.13.1-3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-2...v0.13.1-3) (2020-10-19)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-2"></a>
## [0.13.1-2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.13.1-1...v0.13.1-2) (2020-10-19)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.1-1"></a>
## [0.13.1-1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-3...v0.13.1-1) (2020-10-12)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.12.1-3"></a>
## [0.12.1-3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-2...v0.12.1-3) (2020-10-12)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.12.1-2"></a>
## [0.12.1-2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v0.12.1-1...v0.12.1-2) (2020-09-23)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.12.1-1"></a>
## [0.12.1-1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.9-9...v0.12.1-1) (2020-09-22)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.9-9"></a>
## [1.0.9-9](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.9-8...v1.0.9-9) (2020-09-22)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.9-8"></a>
## [1.0.9-8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.9-7...v1.0.9-8) (2020-09-22)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.9-7"></a>
## [1.0.9-7](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.9-5...v1.0.9-7) (2020-09-18)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.9-6"></a>
## [1.0.9-6](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.9-5...v1.0.9-6) (2020-09-18)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.9-5"></a>
## [1.0.9-5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.9-2...v1.0.9-5) (2020-09-17)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.9-2"></a>
## [1.0.9-2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.9-1...v1.0.9-2) (2020-09-14)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.9-1"></a>
## [1.0.9-1](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/v1.0.9-0...v1.0.9-1) (2020-09-14)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.9-0"></a>
## 1.0.9-0 (2020-09-14)
### Bug Fixes
* 🐛 bugs about deps ([1eabd50](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/1eabd50))
* 🐛 children in props ([fe0ace8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/fe0ace8))
* 🐛 get deps info from slot ([6c3ae36](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/6c3ae36))
* 🐛 group chunks by filetype family ([db144a9](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/db144a9))
* 🐛 loop bug ([8f53910](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/8f53910))
* 🐛 repair children before deps analyze ([737d06e](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/737d06e))
* 🐛 support JSFunction type ([9061e4b](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/9061e4b))
* 🐛 更改复杂类型生成工具的接口形式,减少调用复杂度 ([ce616b5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/ce616b5))
* demo data ([b4a27fc](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/b4a27fc))
* enhance compile config ([2899149](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/2899149))
* factory api ([237b866](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/237b866))
* path resolve problem ([b12c0f8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/b12c0f8))
* post process file error ([389eaf7](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/389eaf7))
* rm demo in lib ([55630d6](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/55630d6))
* same name chunk case ([d6855e2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/d6855e2))
* use webpack for package ([b350a88](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/b350a88))
* 修复 condition 代码导出错误 ([57b30cf](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/57b30cf))
* 新增自定义模式 demo & 导出自定义需要的信息 ([07e2759](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/07e2759))
* 更改生成 id 的规则, 否则命中 recore 解析 id 的一个限制 ([5adff44](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/5adff44))
### Features
* 🎸 add node type mapping config for jsx plugin ([19a51b8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/19a51b8))
* 🎸 code generator fix slot support ([e51b9cb](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/e51b9cb))
* add prettier post processor ([49ac9a3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/49ac9a3))
* add recore project template ([267953b](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/267953b))
* add template create tool ([e906683](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/e906683))
* add zip publisher ([31156ed](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/31156ed))
* code generator main process ([021d6e0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/021d6e0))
* demo schema & complex children type ([a5ee6bd](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/a5ee6bd))
* export publisher ([4a53faa](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/4a53faa))
* fix gaps ([32af3d3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/32af3d3))
* prepare publish for code-generator ([93ff5c2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/93ff5c2))
* project builder fix & publish demo to disk ([26983b3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/26983b3))
* recore solution ([3bfe758](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/3bfe758))
* rewrite demo & export plugins and utils ([6cf7c3d](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/6cf7c3d))
<a name="1.0.8-0"></a>
## [1.0.8-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@1.0.7-0...@ali/lowcode-code-generator@1.0.8-0) (2020-09-09)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.7-0"></a>
## [1.0.7-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@1.0.6-0...@ali/lowcode-code-generator@1.0.7-0) (2020-09-02)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.6-0"></a>
## [1.0.6-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@1.0.5-0...@ali/lowcode-code-generator@1.0.6-0) (2020-09-02)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.5-0"></a>
## [1.0.5-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@1.0.4-0...@ali/lowcode-code-generator@1.0.5-0) (2020-08-20)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.4-0"></a>
## [1.0.4-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@1.0.3-0...@ali/lowcode-code-generator@1.0.4-0) (2020-08-20)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.3-0"></a>
## [1.0.3-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@1.0.2-0...@ali/lowcode-code-generator@1.0.3-0) (2020-08-20)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.2-0"></a>
## [1.0.2-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@1.0.1-0...@ali/lowcode-code-generator@1.0.2-0) (2020-08-20)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.1-0"></a>
## [1.0.1-0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@1.0.0...@ali/lowcode-code-generator@1.0.1-0) (2020-08-20)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="1.0.0"></a>
# [1.0.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@0.13.0...@ali/lowcode-code-generator@1.0.0) (2020-08-17)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.13.0"></a>
# [0.13.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@0.12.0...@ali/lowcode-code-generator@0.13.0) (2020-08-17)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.12.0"></a>
# [0.12.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@0.10.0...@ali/lowcode-code-generator@0.12.0) (2020-08-17)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.11.0"></a>
# [0.11.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@0.10.0...@ali/lowcode-code-generator@0.11.0) (2020-08-17)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.10.0"></a>
# [0.10.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@0.9.0...@ali/lowcode-code-generator@0.10.0) (2020-08-16)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.9.0"></a>
# [0.9.0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@0.8.10...@ali/lowcode-code-generator@0.9.0) (2020-08-14)
### Bug Fixes
* 🐛 bugs about deps ([1eabd50](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/1eabd50))
* 🐛 children in props ([fe0ace8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/fe0ace8))
* 🐛 get deps info from slot ([6c3ae36](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/6c3ae36))
* 🐛 group chunks by filetype family ([db144a9](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/db144a9))
* 🐛 loop bug ([8f53910](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/8f53910))
* 🐛 repair children before deps analyze ([737d06e](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/737d06e))
* 🐛 support JSFunction type ([9061e4b](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/9061e4b))
* 🐛 更改复杂类型生成工具的接口形式,减少调用复杂度 ([ce616b5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/ce616b5))
### Features
* 🎸 add node type mapping config for jsx plugin ([19a51b8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/19a51b8))
* 🎸 code generator fix slot support ([e51b9cb](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/e51b9cb))
<a name="0.8.10"></a>
## [0.8.10](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@0.8.9...@ali/lowcode-code-generator@0.8.10) (2020-07-21)
### Bug Fixes
* 修复 condition 代码导出错误 ([57b30cf](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/57b30cf))
* 新增自定义模式 demo & 导出自定义需要的信息 ([07e2759](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/07e2759))
### Features
* add zip publisher ([31156ed](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/31156ed))
* prepare publish for code-generator ([93ff5c2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/93ff5c2))
<a name="0.8.9"></a>
## [0.8.9](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@0.8.7...@ali/lowcode-code-generator@0.8.9) (2020-07-12)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.8.7"></a>
## [0.8.7](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@0.8.6...@ali/lowcode-code-generator@0.8.7) (2020-07-12)
### Bug Fixes
* demo data ([b4a27fc](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/b4a27fc))
* factory api ([237b866](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/237b866))
* same name chunk case ([d6855e2](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/d6855e2))
### Features
* add recore project template ([267953b](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/267953b))
* add template create tool ([e906683](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/e906683))
* recore solution ([3bfe758](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/3bfe758))
* rewrite demo & export plugins and utils ([6cf7c3d](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/6cf7c3d))
<a name="0.8.6"></a>
## [0.8.6](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@0.8.5...@ali/lowcode-code-generator@0.8.6) (2020-06-23)
### Bug Fixes
* 更改生成 id 的规则, 否则命中 recore 解析 id 的一个限制 ([5adff44](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/5adff44))
<a name="0.8.5"></a>
## [0.8.5](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@0.8.4...@ali/lowcode-code-generator@0.8.5) (2020-04-15)
### Bug Fixes
* enhance compile config ([2899149](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/2899149))
* path resolve problem ([b12c0f8](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/b12c0f8))
* post process file error ([389eaf7](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/389eaf7))
* rm demo in lib ([55630d6](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/55630d6))
* use webpack for package ([b350a88](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/b350a88))
### Features
* add prettier post processor ([49ac9a3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/49ac9a3))
* export publisher ([4a53faa](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/4a53faa))
<a name="0.8.4"></a>
## [0.8.4](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@0.8.3...@ali/lowcode-code-generator@0.8.4) (2020-03-30)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.8.3"></a>
## [0.8.3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/compare/@ali/lowcode-code-generator@0.8.2...@ali/lowcode-code-generator@0.8.3) (2020-03-30)
**Note:** Version bump only for package @ali/lowcode-code-generator
<a name="0.8.2"></a>
## 0.8.2 (2020-03-30)
### Features
* code generator main process ([021d6e0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/021d6e0))
* demo schema & complex children type ([a5ee6bd](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/a5ee6bd))
* fix gaps ([32af3d3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/32af3d3))
* project builder fix & publish demo to disk ([26983b3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/26983b3))
<a name="0.8.1"></a>
## 0.8.1 (2020-03-30)
### Features
* code generator main process ([021d6e0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/021d6e0))
* demo schema & complex children type ([a5ee6bd](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/a5ee6bd))
* fix gaps ([32af3d3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/32af3d3))
* project builder fix & publish demo to disk ([26983b3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/26983b3))
* code generator main process ([021d6e0](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/021d6e0fe9fb29a8b6c1c5d5f4d06ec71896faa5))
* demo schema & complex children type ([a5ee6bd](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/a5ee6bd55806fc9aea695096ccd4c7f50b8e31c4))
* fix gaps ([32af3d3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/32af3d3a3ca4d5aca15be25e05c840c8ea0cb6ae))
* project builder fix & publish demo to disk ([26983b3](https://gitlab.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/commit/26983b38c2b0f1d39d79964eb54d8ce60250dd82))

View File

@ -1,9 +0,0 @@
# 出码模块
## 安装接入
## 自定义导出
## 开始开发

File diff suppressed because it is too large Load Diff

View File

@ -1,171 +0,0 @@
const fs = require('fs');
// ../lib 可以替换成 @ali/lowcode-code-generator
const CodeGenerator = require('../lib').default;
function flatFiles(rootName, dir) {
const dirRoot = rootName ? `${rootName}/${dir.name}` : dir.name;
const files = dir.files.map((file) => ({
name: `${dirRoot}/${file.name}.${file.ext}`,
content: file.content,
ext: '',
}));
const filesInSub = dir.dirs.map((subDir) => flatFiles(`${dirRoot}`, subDir));
const result = files.concat(...filesInSub);
return result;
}
function displayResultInConsole(root, fileName) {
const files = flatFiles('.', root);
files.forEach((file) => {
if (!fileName || fileName === file.name) {
console.log(`========== ${file.name} Start ==========`);
console.log(file.content);
console.log(`========== ${file.name} End ==========`);
}
});
}
async function writeResultToDisk(root, path) {
const publisher = CodeGenerator.publishers.disk();
return publisher.publish({
project: root,
outputPath: path,
projectSlug: 'demo-project',
createProjectFolder: true,
});
}
function getComponentsMap() {
const assetJson = fs.readFileSync('./demo/assets.json', { encoding: 'utf8' });
const assets = JSON.parse(assetJson);
const { components } = assets;
const componentsMap = components
.filter((c) => !!c.npm)
.map((c) => ({
componentName: c.componentName,
...(c.npm || {}),
}));
return componentsMap;
}
function main() {
const schemaJson = fs.readFileSync('./demo/sampleSchema.json', { encoding: 'utf8' });
const createIceJsProjectBuilder = CodeGenerator.solutions.icejs;
const builder = createIceJsProjectBuilder();
builder.generateProject(schemaJson).then((result) => {
displayResultInConsole(result);
writeResultToDisk(result, 'output/lowcodeDemo').then((response) => console.log('Write to disk: ', JSON.stringify(response)));
return result;
});
}
function demo() {
const schemaJson = fs.readFileSync('./demo/schema.json', { encoding: 'utf8' });
const createIceJsProjectBuilder = CodeGenerator.solutions.icejs;
const builder = createIceJsProjectBuilder();
const componentsMap = getComponentsMap();
const root = JSON.parse(schemaJson);
const fullSchema = {
version: '1.0.0',
config: {
historyMode: 'hash',
targetRootID: 'J_Container',
},
meta: {
name: 'demoproject',
},
componentsTree: [root],
componentsMap,
};
builder.generateProject(fullSchema).then((result) => {
displayResultInConsole(result);
return result;
});
}
function exportModule() {
const schemaJson = fs.readFileSync('./demo/shenmaSample.json', { encoding: 'utf8' });
const moduleBuilder = CodeGenerator.createModuleBuilder({
plugins: [
CodeGenerator.plugins.react.reactCommonDeps(),
CodeGenerator.plugins.common.esmodule({
fileType: 'jsx',
}),
CodeGenerator.plugins.react.containerClass(),
CodeGenerator.plugins.react.containerInitState(),
CodeGenerator.plugins.react.containerLifeCycle(),
CodeGenerator.plugins.react.containerMethod(),
CodeGenerator.plugins.react.jsx(),
CodeGenerator.plugins.style.css(),
],
postProcessors: [CodeGenerator.postprocessor.prettier()],
mainFileName: 'index',
});
moduleBuilder.generateModuleCode(schemaJson).then((result) => {
displayResultInConsole(result);
return result;
});
}
function exportProject() {
const schemaJson = fs.readFileSync('./demo/sampleSchema.json', { encoding: 'utf8' });
const builder = CodeGenerator.createProjectBuilder({
template: CodeGenerator.solutionParts.icejs.template,
plugins: {
components: [
CodeGenerator.plugins.react.reactCommonDeps(),
CodeGenerator.plugins.common.esmodule({
fileType: 'jsx',
}),
CodeGenerator.plugins.react.containerClass(),
CodeGenerator.plugins.react.containerInitState(),
CodeGenerator.plugins.react.containerLifeCycle(),
CodeGenerator.plugins.react.containerMethod(),
CodeGenerator.plugins.react.jsx(),
CodeGenerator.plugins.style.css(),
],
pages: [
CodeGenerator.plugins.react.reactCommonDeps(),
CodeGenerator.plugins.common.esmodule({
fileType: 'jsx',
}),
CodeGenerator.plugins.react.containerClass(),
CodeGenerator.plugins.react.containerInitState(),
CodeGenerator.plugins.react.containerLifeCycle(),
CodeGenerator.plugins.react.containerMethod(),
CodeGenerator.plugins.react.jsx(),
CodeGenerator.plugins.style.css(),
],
router: [CodeGenerator.plugins.common.esmodule(), CodeGenerator.solutionParts.icejs.plugins.router()],
entry: [CodeGenerator.solutionParts.icejs.plugins.entry()],
constants: [CodeGenerator.plugins.project.constants()],
utils: [CodeGenerator.plugins.common.esmodule(), CodeGenerator.plugins.project.utils()],
i18n: [CodeGenerator.plugins.project.i18n()],
globalStyle: [CodeGenerator.solutionParts.icejs.plugins.globalStyle()],
htmlEntry: [CodeGenerator.solutionParts.icejs.plugins.entryHtml()],
packageJSON: [CodeGenerator.solutionParts.icejs.plugins.packageJSON()],
},
postProcessors: [CodeGenerator.postprocessor.prettier()],
});
builder.generateProject(schemaJson).then((result) => {
displayResultInConsole(result);
writeResultToDisk(result, 'output/lowcodeDemo').then((response) => console.log('Write to disk: ', JSON.stringify(response)));
return result;
});
}
// main();
// exportModule();
// exportProject();
demo();

View File

@ -1,243 +0,0 @@
{
"version": "1.0.0",
"componentsMap": [
{
"componentName": "Button",
"package": "@alifd/next",
"version": "1.19.18",
"destructuring": true,
"exportName": "Button"
},
{
"componentName": "Button.Group",
"package": "@alifd/next",
"version": "1.19.18",
"destructuring": true,
"exportName": "Button",
"subName": "Group"
},
{
"componentName": "Input",
"package": "@alifd/next",
"version": "1.19.18",
"destructuring": true,
"exportName": "Input"
},
{
"componentName": "Form",
"package": "@alifd/next",
"version": "1.19.18",
"destructuring": true,
"exportName": "Form"
},
{
"componentName": "Form.Item",
"package": "@alifd/next",
"version": "1.19.18",
"destructuring": true,
"exportName": "Form",
"subName": "Item"
},
{
"componentName": "NumberPicker",
"package": "@alifd/next",
"version": "1.19.18",
"destructuring": true,
"exportName": "NumberPicker"
},
{
"componentName": "Select",
"package": "@alifd/next",
"version": "1.19.18",
"destructuring": true,
"exportName": "Select"
}
],
"componentsTree": [
{
"componentName": "Page",
"id": "node$1",
"meta": {
"title": "测试",
"router": "/"
},
"props": {
"ref": "outterView",
"autoLoading": true
},
"fileName": "test",
"state": {
"text": "outter"
},
"lifeCycles": {
"componentDidMount": {
"type": "JSExpression",
"value": "function() { this.utils.request(this.props.url); }"
}
},
"children": [
{
"componentName": "Form",
"id": "node$2",
"props": {
"labelCol": {
"type": "JSExpression",
"value": "this.state.colNum"
},
"style": {},
"ref": "testForm"
},
"children": [
{
"componentName": "Form.Item",
"id": "node$3",
"props": {
"label": "姓名:",
"name": "name",
"initValue": "李雷"
},
"children": [
{
"componentName": "Input",
"id": "node$4",
"props": {
"placeholder": "请输入",
"size": "medium",
"style": {
"width": 320
}
}
}
]
},
{
"componentName": "Form.Item",
"id": "node$5",
"props": {
"label": "年龄:",
"name": "age",
"initValue": "22"
},
"children": [
{
"componentName": "NumberPicker",
"id": "node$6",
"props": {
"size": "medium",
"type": "normal"
}
}
]
},
{
"componentName": "Form.Item",
"id": "node$7",
"props": {
"label": "职业:",
"name": "profession"
},
"children": [
{
"componentName": "Select",
"id": "node$8",
"props": {
"dataSource": [
{
"label": "教师",
"value": "t"
},
{
"label": "医生",
"value": "d"
},
{
"label": "歌手",
"value": "s"
}
]
}
}
]
},
{
"componentName": "Div",
"id": "node$9",
"props": {
"style": {
"textAlign": "center"
}
},
"children": [
{
"componentName": "Button.Group",
"id": "node$a",
"props": {},
"children": [
{
"componentName": "Button",
"id": "node$b",
"props": {
"type": "primary",
"style": {
"margin": "0 5px 0 5px"
},
"htmlType": "submit"
},
"children": [
"提交"
]
},
{
"componentName": "Button",
"id": "node$d",
"props": {
"type": "normal",
"style": {
"margin": "0 5px 0 5px"
},
"htmlType": "reset"
},
"children": [
"重置"
]
}
]
}
]
}
]
}
]
}
],
"constants": {
"ENV": "prod",
"DOMAIN": "xxx.alibaba-inc.com"
},
"css": "body {font-size: 12px;} .table { width: 100px;}",
"config": {
"sdkVersion": "1.0.3",
"historyMode": "hash",
"targetRootID": "J_Container",
"layout": {
"componentName": "BasicLayout",
"props": {
"logo": "...",
"name": "测试网站"
}
},
"theme": {
"package": "@alife/theme-fusion",
"version": "^0.1.0",
"primary": "#ff9966"
}
},
"meta": {
"name": "demo应用",
"git_group": "appGroup",
"project_name": "app_demo",
"description": "这是一个测试应用",
"spma": "spa23d",
"creator": "月飞"
}
}

View File

@ -1,420 +0,0 @@
{
"componentName": "Page",
"id": "node_dockcviv8fo1",
"props": {
"ref": "outterView",
"autoLoading": true,
"style": {
"padding": "0 5px 0 5px"
}
},
"fileName": "test",
"dataSource": {
"list": []
},
"state": {
"text": "outter",
"isShowDialog": false
},
"css": "body {font-size: 12px;} .botton{width:100px;color:#ff00ff}",
"lifeCycles": {
"componentDidMount": {
"type": "JSFunction",
"value": "function() {\n console.log('did mount');\n }"
},
"componentWillUnmount": {
"type": "JSFunction",
"value": "function() {\n console.log('will umount');\n }"
}
},
"methods": {
"testFunc": {
"type": "JSFunction",
"value": "function() {\n console.log('test func');\n }"
},
"onClick": {
"type": "JSFunction",
"value": "function(){\n this.setState({\n isShowDialog:true\n })\n\t}"
}
},
"children": [{
"componentName": "Box",
"id": "node_dockcy8n9xed",
"props": {
"style": {
"backgroundColor": "rgba(31,56,88,0.1)",
"padding": "12px 12px 12px 12px"
}
},
"children": [{
"componentName": "Box",
"id": "node_dockcy8n9xee",
"props": {
"style": {
"padding": "12px 12px 12px 12px",
"backgroundColor": "#ffffff"
}
},
"children": [{
"componentName": "Breadcrumb",
"id": "node_dockcy8n9xef",
"props": {
"prefix": "next-",
"maxNode": 100,
"component": "nav"
},
"children": [{
"componentName": "Breadcrumb.Item",
"id": "node_dockcy8n9xeg",
"props": {
"prefix": "next-"
},
"children": ["首页"]
}, {
"componentName": "Breadcrumb.Item",
"id": "node_dockcy8n9xei",
"props": {
"prefix": "next-"
},
"children": ["品质中台"]
}, {
"componentName": "Breadcrumb.Item",
"id": "node_dockcy8n9xek",
"props": {
"prefix": "next-"
},
"children": ["商家品质页面管理"]
}, {
"componentName": "Breadcrumb.Item",
"id": "node_dockcy8n9xem",
"props": {
"prefix": "next-"
},
"children": ["质检知识条配置"]
}]
}]
}, {
"componentName": "Box",
"id": "node_dockcy8n9xeo",
"props": {
"style": {
"marginTop": "12px",
"backgroundColor": "#ffffff"
}
},
"children": [{
"componentName": "Form",
"id": "node_dockcy8n9xep",
"props": {
"inline": true,
"style": {
"marginTop": "12px",
"marginRight": "12px",
"marginLeft": "12px"
},
"__events": []
},
"children": [{
"componentName": "Form.Item",
"id": "node_dockcy8n9xeq",
"props": {
"style": {
"marginBottom": "0"
},
"label": "类目名:"
},
"children": [{
"componentName": "Select",
"id": "node_dockcy8n9xer",
"props": {
"mode": "single",
"hasArrow": true,
"cacheValue": true,
"style": {
"width": "150px"
}
}
}]
}, {
"componentName": "Form.Item",
"id": "node_dockcy8n9xes",
"props": {
"style": {
"marginBottom": "0"
},
"label": "项目类型:"
},
"children": [{
"componentName": "Select",
"id": "node_dockcy8n9xet",
"props": {
"mode": "single",
"hasArrow": true,
"cacheValue": true,
"style": {
"width": "200px"
}
}
}]
}, {
"componentName": "Form.Item",
"id": "node_dockcy8n9xeu",
"props": {
"style": {
"marginBottom": "0"
},
"label": "项目 ID"
},
"children": [{
"componentName": "Input",
"id": "node_dockcy8n9xev",
"props": {
"hasBorder": true,
"size": "medium",
"autoComplete": "off",
"style": {
"width": "200px"
}
}
}]
}, {
"componentName": "Button.Group",
"id": "node_dockcy8n9xew",
"props": {},
"children": [{
"componentName": "Button",
"id": "node_dockcy8n9xex",
"props": {
"type": "primary",
"style": {
"margin": "0 5px 0 5px"
},
"htmlType": "submit"
},
"children": [{
"componentName": "Icon",
"id": "node_dockcy8n9xey",
"props": {
"type": "success"
}
}, "搜索"]
}, {
"componentName": "Button",
"id": "node_dockcy8n9xe10",
"props": {
"type": "normal",
"style": {
"margin": "0 5px 0 5px"
},
"htmlType": "reset"
},
"children": ["清空"]
}]
}]
}]
}, {
"componentName": "Box",
"id": "node_dockcy8n9xe12",
"props": {
"style": {
"justifyContent": "flex-end",
"display": "flex",
"backgroundColor": "#ffffff",
"flexDirection": "row",
"paddingRight": "24px"
}
},
"children": [{
"componentName": "Button",
"id": "node_dockcy8n9xe13",
"props": {
"prefix": "next-",
"type": "primary",
"size": "medium",
"htmlType": "button",
"component": "button",
"style": {
"width": "100px"
},
"events": {
"onClick": {
"type": "JSFunction",
"value": "function(){ this.onClick() }",
"__eventData": {
"type": "componentEvent",
"name": "onClick",
"relatedEventName": "onClick"
}
}
},
"__events": [{
"type": "componentEvent",
"name": "onClick",
"relatedEventName": "onClick"
}],
"onClick": {
"type": "JSFunction",
"value": "function(){ this.onClick() }"
}
},
"children": ["新建配置"]
}]
}, {
"componentName": "Box",
"id": "node_dockcy8n9xe15",
"props": {
"style": {
"backgroundColor": "#ffffff"
}
},
"children": [{
"componentName": "Table",
"id": "node_dockcy8n9xe16",
"props": {
"dataSource": [{
"firstCategory": "其他",
"secondCategory": "新品预览",
"leafCategory": "",
"projectType": "标识判断",
"projectId": "",
"title": "其他类目->新品预览类目类型知识库",
"url": "其他",
"operation": "编辑"
}, {
"firstCategory": "其他",
"secondCategory": "新品预览",
"leafCategory": "",
"projectType": "",
"projectId": "1",
"title": "其他类目->新品预览项目Id知识库",
"url": "其他",
"operation": "编辑"
}],
"size": "medium",
"prefix": "next-",
"hasBorder": true,
"hasHeader": true,
"isZebra": false,
"loading": false,
"expandedIndexSimulate": false,
"primaryKey": "id",
"locale": "zhCN.Table",
"crossline": false,
"style": {
"margin": "24px 12px 24px 12px"
}
},
"children": [{
"componentName": "Table.Column",
"id": "node_dockcy8n9xe17",
"props": {
"title": "一级类目",
"dataIndex": "firstCategory"
}
}, {
"componentName": "Table.Column",
"id": "node_dockcy8n9xe18",
"props": {
"title": "二级类目",
"dataIndex": "secondCategory"
}
}, {
"componentName": "Table.Column",
"id": "node_dockcy8n9xe19",
"props": {
"title": "叶子类目",
"dataIndex": "leafCategory"
}
}, {
"componentName": "Table.Column",
"id": "node_dockcy8n9xe1a",
"props": {
"title": "项目类型",
"dataIndex": "projectType"
}
}, {
"componentName": "Table.Column",
"id": "node_dockcy8n9xe1b",
"props": {
"title": "项目 ID",
"dataIndex": "projectId"
}
}, {
"componentName": "Table.Column",
"id": "node_dockcy8n9xe1c",
"props": {
"title": "知识条标题",
"dataIndex": "title"
}
}, {
"componentName": "Table.Column",
"id": "node_dockcy8n9xe1d",
"props": {
"title": "知识条链接",
"dataIndex": "url"
}
}, {
"componentName": "Table.Column",
"id": "node_dockcy8n9xe1e",
"props": {
"title": "操作",
"dataIndex": "operation"
}
}]
}]
}, {
"componentName": "Box",
"id": "node_dockcy8n9xe1f",
"props": {
"style": {
"backgroundColor": "#ffffff",
"paddingBottom": "24px"
}
},
"children": [{
"componentName": "Pagination",
"id": "node_dockcy8n9xe1g",
"props": {
"prefix": "next-",
"type": "normal",
"shape": "normal",
"size": "medium",
"defaultCurrent": 1,
"total": 100,
"pageShowCount": 5,
"pageSize": 10,
"pageSizePosition": "start",
"showJump": true,
"style": {
"display": "flex",
"justifyContent": "flex-end"
}
}
}]
}]
}, {
"componentName": "Dialog",
"id": "node_dockcy8n9xe1h",
"props": {
"prefix": "next-",
"footerAlign": "right",
"footerActions": ["ok", "cancel"],
"closeable": "esc,close",
"hasMask": true,
"align": "cc cc",
"minMargin": 40,
"visible": {
"type": "JSExpression",
"value": "this.state.isShowDialog"
},
"children": {
"type": "JSSlot"
},
"title": "标题",
"footer": {
"type": "JSSlot"
},
"events": []
}
}]
}

View File

@ -1,36 +0,0 @@
{
"version": "1.0.0",
"componentsMap": [
{
"componentName": "Demo",
"package": "@ali/demo",
"version": "1.19.18",
"destructuring": true,
"exportName": "Demo"
}
],
"id": "page_kc326r8m",
"componentsTree": [{
"componentName": "Page",
"id": "node_kc326r8h",
"props": {},
"condition": true,
"loopArgs": ["item", "index"],
"children": [{
"componentName": "Demo",
"id": "node_kc326r8i",
"props": {
"value": "文本内容",
"color": "#ffffff",
"ui_maxLine": 2,
"url": "",
"ui_type": "xs",
"style": {},
"className": ""
},
"condition": true,
"loopArgs": ["item", "index"]
}]
}],
"params": {}
}

View File

@ -1,51 +0,0 @@
{
"name": "@ali/lowcode-code-generator",
"version": "0.13.1-29",
"description": "出码引擎 for LowCode Engine",
"main": "lib/index.js",
"files": [
"lib",
"demo"
],
"scripts": {
"build": "rimraf lib && tsc",
"demo": "node ./demo/demo.js",
"test": "ava",
"template": "node ./tools/createTemplate.js"
},
"dependencies": {
"@ali/am-eslint-config": "*",
"@ali/my-prettier": "^1.0.0",
"@babel/generator": "^7.9.5",
"@babel/parser": "^7.9.4",
"@babel/traverse": "^7.9.5",
"@babel/types": "^7.9.5",
"@types/prettier": "^1.19.1",
"change-case": "^3.1.0",
"jszip": "^3.5.0",
"prettier": "^2.0.2",
"short-uuid": "^3.1.1"
},
"devDependencies": {
"@types/babel__traverse": "^7.0.10",
"ava": "^1.0.1",
"rimraf": "^3.0.2",
"ts-loader": "^6.2.2",
"ts-node": "^7.0.1",
"tsconfig-paths": "^3.9.0"
},
"ava": {
"compileEnhancements": false,
"snapshotDir": "test/fixtures/__snapshots__",
"extensions": [
"ts"
],
"require": [
"ts-node/register"
]
},
"publishConfig": {
"registry": "http://registry.npm.alibaba-inc.com"
},
"license": "MIT"
}

View File

@ -1,6 +0,0 @@
// / <reference types="node" />
declare module '@ali/my-prettier' {
function format(text: string, type: string): string;
export default format;
}

View File

@ -1,3 +0,0 @@
import { FileType } from '../types/core';
export const FILE_TYPE_FAMILY = [[FileType.TSX, FileType.TS, FileType.JSX, FileType.JS]];

View File

@ -1,114 +0,0 @@
export const COMMON_CHUNK_NAME = {
ExternalDepsImport: 'CommonExternalDependencyImport',
InternalDepsImport: 'CommonInternalDependencyImport',
FileVarDefine: 'CommonFileScopeVarDefine',
FileUtilDefine: 'CommonFileScopeMethodDefine',
FileMainContent: 'CommonFileMainContent',
FileExport: 'CommonFileExport',
StyleDepsImport: 'CommonStyleDepsImport',
StyleCssContent: 'CommonStyleCssContent',
HtmlContent: 'CommonHtmlContent',
CustomContent: 'CommonCustomContent',
};
export const CLASS_DEFINE_CHUNK_NAME = {
Start: 'CommonClassDefineStart',
ConstructorStart: 'CommonClassDefineConstructorStart',
ConstructorContent: 'CommonClassDefineConstructorContent',
ConstructorEnd: 'CommonClassDefineConstructorEnd',
StaticVar: 'CommonClassDefineStaticVar',
StaticMethod: 'CommonClassDefineStaticMethod',
InsVar: 'CommonClassDefineInsVar',
InsVarMethod: 'CommonClassDefineInsVarMethod',
InsMethod: 'CommonClassDefineInsMethod',
End: 'CommonClassDefineEnd',
};
export const DEFAULT_LINK_AFTER = {
[COMMON_CHUNK_NAME.ExternalDepsImport]: [],
[COMMON_CHUNK_NAME.InternalDepsImport]: [COMMON_CHUNK_NAME.ExternalDepsImport],
[COMMON_CHUNK_NAME.FileVarDefine]: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
],
[COMMON_CHUNK_NAME.FileUtilDefine]: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileVarDefine,
],
[CLASS_DEFINE_CHUNK_NAME.Start]: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileVarDefine,
COMMON_CHUNK_NAME.FileUtilDefine,
],
[CLASS_DEFINE_CHUNK_NAME.ConstructorStart]: [
CLASS_DEFINE_CHUNK_NAME.Start,
CLASS_DEFINE_CHUNK_NAME.StaticVar,
CLASS_DEFINE_CHUNK_NAME.StaticMethod,
CLASS_DEFINE_CHUNK_NAME.InsVar,
CLASS_DEFINE_CHUNK_NAME.InsVarMethod,
],
[CLASS_DEFINE_CHUNK_NAME.ConstructorContent]: [
CLASS_DEFINE_CHUNK_NAME.ConstructorStart,
],
[CLASS_DEFINE_CHUNK_NAME.ConstructorEnd]: [
CLASS_DEFINE_CHUNK_NAME.ConstructorStart,
CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
],
[CLASS_DEFINE_CHUNK_NAME.StaticVar]: [
CLASS_DEFINE_CHUNK_NAME.Start,
],
[CLASS_DEFINE_CHUNK_NAME.StaticMethod]: [
CLASS_DEFINE_CHUNK_NAME.Start,
CLASS_DEFINE_CHUNK_NAME.StaticVar,
],
[CLASS_DEFINE_CHUNK_NAME.InsVar]: [
CLASS_DEFINE_CHUNK_NAME.Start,
CLASS_DEFINE_CHUNK_NAME.StaticVar,
CLASS_DEFINE_CHUNK_NAME.StaticMethod,
],
[CLASS_DEFINE_CHUNK_NAME.InsVarMethod]: [
CLASS_DEFINE_CHUNK_NAME.Start,
CLASS_DEFINE_CHUNK_NAME.StaticVar,
CLASS_DEFINE_CHUNK_NAME.StaticMethod,
CLASS_DEFINE_CHUNK_NAME.InsVar,
],
[CLASS_DEFINE_CHUNK_NAME.InsMethod]: [
CLASS_DEFINE_CHUNK_NAME.Start,
CLASS_DEFINE_CHUNK_NAME.StaticVar,
CLASS_DEFINE_CHUNK_NAME.StaticMethod,
CLASS_DEFINE_CHUNK_NAME.InsVar,
CLASS_DEFINE_CHUNK_NAME.InsVarMethod,
CLASS_DEFINE_CHUNK_NAME.ConstructorEnd,
],
[CLASS_DEFINE_CHUNK_NAME.End]: [
CLASS_DEFINE_CHUNK_NAME.Start,
CLASS_DEFINE_CHUNK_NAME.StaticVar,
CLASS_DEFINE_CHUNK_NAME.StaticMethod,
CLASS_DEFINE_CHUNK_NAME.InsVar,
CLASS_DEFINE_CHUNK_NAME.InsVarMethod,
CLASS_DEFINE_CHUNK_NAME.InsMethod,
CLASS_DEFINE_CHUNK_NAME.ConstructorEnd,
],
[COMMON_CHUNK_NAME.FileMainContent]: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileVarDefine,
COMMON_CHUNK_NAME.FileUtilDefine,
CLASS_DEFINE_CHUNK_NAME.End,
],
[COMMON_CHUNK_NAME.FileExport]: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileVarDefine,
COMMON_CHUNK_NAME.FileUtilDefine,
CLASS_DEFINE_CHUNK_NAME.End,
COMMON_CHUNK_NAME.FileMainContent,
],
[COMMON_CHUNK_NAME.StyleDepsImport]: [],
[COMMON_CHUNK_NAME.StyleCssContent]: [COMMON_CHUNK_NAME.StyleDepsImport],
[COMMON_CHUNK_NAME.HtmlContent]: [],
};
export const COMMON_SUB_MODULE_NAME = 'index';

View File

@ -1,9 +0,0 @@
export const NATIVE_ELE_PKG = 'native';
export const CONTAINER_TYPE = {
COMPONENT: 'Component',
BLOCK: 'Block',
PAGE: 'Page',
};
export const SUPPORT_SCHEMA_VERSION_LIST = ['0.0.1'];

View File

@ -1,118 +0,0 @@
import { BuilderComponentPlugin, IChunkBuilder, ICodeChunk, ICodeStruct, FileType } from '../types';
import { COMMON_SUB_MODULE_NAME } from '../const/generator';
import { FILE_TYPE_FAMILY } from '../const/file';
type ChunkGroupInfo = {
chunk: ICodeChunk;
familyIdx?: number;
};
function whichFamily(type: FileType): [number, FileType[]] | undefined {
const idx = FILE_TYPE_FAMILY.findIndex((family) => family.indexOf(type) >= 0);
if (idx < 0) {
return undefined;
}
return [idx, FILE_TYPE_FAMILY[idx]];
}
export const groupChunks = (chunks: ICodeChunk[]): ICodeChunk[][] => {
const tmp: Record<string, Record<number, number>> = {};
const col = chunks.reduce((chunksSet: Record<string, ChunkGroupInfo[]>, chunk) => {
const fileKey = chunk.subModule || COMMON_SUB_MODULE_NAME;
if (!chunksSet[fileKey]) {
chunksSet[fileKey] = [];
}
const res = whichFamily(chunk.fileType as FileType);
const info: ChunkGroupInfo = {
chunk,
};
if (res) {
const [familyIdx, family] = res;
const rank = family.indexOf(chunk.fileType as FileType);
if (tmp[fileKey]) {
if (tmp[fileKey][familyIdx] !== undefined) {
if (tmp[fileKey][familyIdx] > rank) {
tmp[fileKey][familyIdx] = rank;
}
} else {
tmp[fileKey][familyIdx] = rank;
}
} else {
tmp[fileKey] = {};
tmp[fileKey][familyIdx] = rank;
}
info.familyIdx = familyIdx;
}
chunksSet[fileKey].push(info);
return chunksSet;
}, {});
const result: ICodeChunk[][] = [];
Object.keys(col).forEach((key) => {
const byType: Record<string, ICodeChunk[]> = {};
col[key].forEach((info) => {
let t: string = info.chunk.fileType;
if (info.familyIdx !== undefined) {
t = FILE_TYPE_FAMILY[info.familyIdx][tmp[key][info.familyIdx]];
info.chunk.fileType = t;
}
if (!byType[t]) {
byType[t] = [];
}
byType[t].push(info.chunk);
});
result.push(...Object.keys(byType).map((t) => byType[t]));
});
return result;
};
/**
*
*
* @export
* @class ChunkBuilder
* @template T
*/
export default class ChunkBuilder implements IChunkBuilder {
private plugins: BuilderComponentPlugin[];
constructor(plugins: BuilderComponentPlugin[] = []) {
this.plugins = plugins;
}
async run(
ir: unknown,
initialStructure: ICodeStruct = {
ir,
chunks: [],
depNames: [],
},
) {
const structure = initialStructure;
const finalStructure: ICodeStruct = await this.plugins.reduce(
async (previousPluginOperation: Promise<ICodeStruct>, plugin) => {
const modifiedStructure = await previousPluginOperation;
return plugin(modifiedStructure);
},
Promise.resolve(structure),
);
const chunks = groupChunks(finalStructure.chunks);
return {
chunks,
};
}
getPlugins() {
return this.plugins;
}
addPlugin(plugin: BuilderComponentPlugin) {
this.plugins.push(plugin);
}
}

View File

@ -1,100 +0,0 @@
import {
ChunkContent,
ChunkType,
CodeGeneratorError,
CodeGeneratorFunction,
ICodeBuilder,
ICodeChunk,
} from '../types';
export default class Builder implements ICodeBuilder {
private chunkDefinitions: ICodeChunk[] = [];
private generators: { [key: string]: CodeGeneratorFunction<ChunkContent> } = {
[ChunkType.STRING]: (str: string) => str, // no-op for string chunks
[ChunkType.JSON]: (json: object) => JSON.stringify(json), // stringify json to string
};
constructor(chunkDefinitions: ICodeChunk[] = []) {
this.chunkDefinitions = chunkDefinitions;
}
/**
* Links all chunks together based on their requirements. Returns an array
* of ordered chunk names which need to be compiled and glued together.
*/
public link(chunkDefinitions: ICodeChunk[] = []): string {
const chunks = chunkDefinitions || this.chunkDefinitions;
if (chunks.length <= 0) {
return '';
}
const unprocessedChunks = chunks.map(chunk => {
return {
name: chunk.name,
type: chunk.type,
content: chunk.content,
linkAfter: this.cleanupInvalidChunks(chunk.linkAfter, chunks),
};
});
const resultingString: string[] = [];
while (unprocessedChunks.length > 0) {
let indexToRemove = 0;
for (let index = 0; index < unprocessedChunks.length; index++) {
if (unprocessedChunks[index].linkAfter.length <= 0) {
indexToRemove = index;
break;
}
}
if (unprocessedChunks[indexToRemove].linkAfter.length > 0) {
throw new CodeGeneratorError(
'Operation aborted. Reason: cyclic dependency between chunks.',
);
}
const { type, content, name } = unprocessedChunks[indexToRemove];
const compiledContent = this.generateByType(type, content);
if (compiledContent) {
resultingString.push(`${compiledContent }\n`);
}
unprocessedChunks.splice(indexToRemove, 1);
if (!unprocessedChunks.some(ch => ch.name === name)) {
unprocessedChunks.forEach(
// remove the processed chunk from all the linkAfter arrays from the remaining chunks
ch => (ch.linkAfter = ch.linkAfter.filter(after => after !== name)),
);
}
}
return resultingString.join('\n');
}
public generateByType(type: string, content: unknown): string {
if (!content) {
return '';
}
if (Array.isArray(content)) {
return content
.map(contentItem => this.generateByType(type, contentItem))
.join('\n');
}
if (!this.generators[type]) {
throw new Error(
`Attempted to generate unknown type ${type}. Please register a generator for this type in builder/index.ts`,
);
}
return this.generators[type](content);
}
// remove invalid chunks (which did not end up being created) from the linkAfter fields
// one use-case is when you want to remove the import plugin
private cleanupInvalidChunks(linkAfter: string[], chunks: ICodeChunk[]) {
return linkAfter.filter(chunkName => chunks.some(chunk => chunk.name === chunkName));
}
}

View File

@ -1,102 +0,0 @@
import {
BuilderComponentPlugin,
CodeGeneratorError,
IBasicSchema,
ICodeChunk,
ICompiledModule,
IModuleBuilder,
IParseResult,
IResultDir,
IResultFile,
ISchemaParser,
PostProcessor,
} from '../types';
import { COMMON_SUB_MODULE_NAME } from '../const/generator';
import SchemaParser from '../parser/SchemaParser';
import ChunkBuilder from './ChunkBuilder';
import CodeBuilder from './CodeBuilder';
import ResultDir from '../model/ResultDir';
import ResultFile from '../model/ResultFile';
export function createModuleBuilder(
options: {
plugins: BuilderComponentPlugin[];
postProcessors: PostProcessor[];
mainFileName?: string;
} = {
plugins: [],
postProcessors: [],
},
): IModuleBuilder {
const chunkGenerator = new ChunkBuilder(options.plugins);
const linker = new CodeBuilder();
const generateModule = async (input: unknown): Promise<ICompiledModule> => {
const moduleMainName = options.mainFileName || COMMON_SUB_MODULE_NAME;
if (chunkGenerator.getPlugins().length <= 0) {
throw new CodeGeneratorError('No plugins found. Component generation cannot work without any plugins!');
}
let files: IResultFile[] = [];
const { chunks } = await chunkGenerator.run(input);
chunks.forEach((fileChunkList) => {
const content = linker.link(fileChunkList);
const file = new ResultFile(fileChunkList[0].subModule || moduleMainName, fileChunkList[0].fileType, content);
files.push(file);
});
if (options.postProcessors.length > 0) {
files = files.map((file) => {
let { content } = file;
const type = file.ext;
options.postProcessors.forEach((processer) => {
content = processer(content, type);
});
return new ResultFile(file.name, type, content);
});
}
return {
files,
};
};
const generateModuleCode = async (schema: IBasicSchema | string): Promise<IResultDir> => {
// Init
const schemaParser: ISchemaParser = new SchemaParser();
const parseResult: IParseResult = schemaParser.parse(schema);
const containerInfo = parseResult.containers[0];
const { files } = await generateModule(containerInfo);
const dir = new ResultDir(containerInfo.moduleName);
files.forEach((file) => dir.addFile(file));
return dir;
};
const linkCodeChunks = (chunks: Record<string, ICodeChunk[]>, fileName: string) => {
const files: IResultFile[] = [];
Object.keys(chunks).forEach((fileKey) => {
const fileChunkList = chunks[fileKey];
const content = linker.link(fileChunkList);
const file = new ResultFile(fileChunkList[0].subModule || fileName, fileChunkList[0].fileType, content);
files.push(file);
});
return files;
};
return {
generateModule,
generateModuleCode,
linkCodeChunks,
addPlugin: chunkGenerator.addPlugin.bind(chunkGenerator),
};
}

View File

@ -1,228 +0,0 @@
import {
IModuleBuilder,
IParseResult,
IProjectBuilder,
IProjectPlugins,
IProjectSchema,
IProjectTemplate,
IResultDir,
IResultFile,
ISchemaParser,
PostProcessor,
} from '../types';
import ResultDir from '../model/ResultDir';
import SchemaParser from '../parser/SchemaParser';
import { createModuleBuilder } from '../generator/ModuleBuilder';
interface IModuleInfo {
moduleName?: string;
path: string[];
files: IResultFile[];
}
function getDirFromRoot(root: IResultDir, path: string[]): IResultDir {
let current: IResultDir = root;
path.forEach((p) => {
const exist = current.dirs.find((d) => d.name === p);
if (exist) {
current = exist;
} else {
const newDir = new ResultDir(p);
current.addDirectory(newDir);
current = newDir;
}
});
return current;
}
export class ProjectBuilder implements IProjectBuilder {
private template: IProjectTemplate;
private plugins: IProjectPlugins;
private postProcessors: PostProcessor[];
constructor({
template,
plugins,
postProcessors,
}: {
template: IProjectTemplate;
plugins: IProjectPlugins;
postProcessors: PostProcessor[];
}) {
this.template = template;
this.plugins = plugins;
this.postProcessors = postProcessors;
}
async generateProject(schema: IProjectSchema | string): Promise<IResultDir> {
// Init
const schemaParser: ISchemaParser = new SchemaParser();
const builders = this.createModuleBuilders();
const projectRoot = this.template.generateTemplate();
// Validate
// Parse / Format
// Preprocess
// Collect Deps
// Parse JSExpression
const parseResult: IParseResult = schemaParser.parse(schema);
let buildResult: IModuleInfo[] = [];
// Generator Code module
// components
// pages
const containerBuildResult: IModuleInfo[] = await Promise.all<IModuleInfo>(
parseResult.containers.map(async (containerInfo) => {
let builder: IModuleBuilder;
let path: string[];
if (containerInfo.containerType === 'Page') {
builder = builders.pages;
path = this.template.slots.pages.path;
} else {
builder = builders.components;
path = this.template.slots.components.path;
}
const { files } = await builder.generateModule(containerInfo);
return {
moduleName: containerInfo.moduleName,
path,
files,
};
}),
);
buildResult = buildResult.concat(containerBuildResult);
// router
if (parseResult.globalRouter && builders.router) {
const { files } = await builders.router.generateModule(parseResult.globalRouter);
buildResult.push({
path: this.template.slots.router.path,
files,
});
}
// entry
if (parseResult.project && builders.entry) {
const { files } = await builders.entry.generateModule(parseResult.project);
buildResult.push({
path: this.template.slots.entry.path,
files,
});
}
// constants?
if (parseResult.project && builders.constants && this.template.slots.constants) {
const { files } = await builders.constants.generateModule(parseResult.project);
buildResult.push({
path: this.template.slots.constants.path,
files,
});
}
// utils?
if (parseResult.globalUtils && builders.utils && this.template.slots.utils) {
const { files } = await builders.utils.generateModule(parseResult.globalUtils);
buildResult.push({
path: this.template.slots.utils.path,
files,
});
}
// i18n?
if (parseResult.globalI18n && builders.i18n && this.template.slots.i18n) {
const { files } = await builders.i18n.generateModule(parseResult.globalI18n);
buildResult.push({
path: this.template.slots.i18n.path,
files,
});
}
// globalStyle
if (parseResult.project && builders.globalStyle) {
const { files } = await builders.globalStyle.generateModule(parseResult.project);
buildResult.push({
path: this.template.slots.globalStyle.path,
files,
});
}
// htmlEntry
if (parseResult.project && builders.htmlEntry) {
const { files } = await builders.htmlEntry.generateModule(parseResult.project);
buildResult.push({
path: this.template.slots.htmlEntry.path,
files,
});
}
// packageJSON
if (parseResult.project && builders.packageJSON) {
const { files } = await builders.packageJSON.generateModule(parseResult.project);
buildResult.push({
path: this.template.slots.packageJSON.path,
files,
});
}
// Post Process
// Combine Modules
buildResult.forEach((moduleInfo) => {
let targetDir = getDirFromRoot(projectRoot, moduleInfo.path);
if (moduleInfo.moduleName) {
const dir = new ResultDir(moduleInfo.moduleName);
targetDir.addDirectory(dir);
targetDir = dir;
}
moduleInfo.files.forEach((file) => targetDir.addFile(file));
});
return projectRoot;
}
private createModuleBuilders(): Record<string, IModuleBuilder> {
const builders: Record<string, IModuleBuilder> = {};
Object.keys(this.plugins).forEach((pluginName) => {
if (this.plugins[pluginName].length > 0) {
const options: { mainFileName?: string } = {};
if (this.template.slots[pluginName] && this.template.slots[pluginName].fileName) {
options.mainFileName = this.template.slots[pluginName].fileName;
}
builders[pluginName] = createModuleBuilder({
plugins: this.plugins[pluginName],
postProcessors: this.postProcessors,
...options,
});
}
});
return builders;
}
}
export function createProjectBuilder({
template,
plugins,
postProcessors,
}: {
template: IProjectTemplate;
plugins: IProjectPlugins;
postProcessors: PostProcessor[];
}): IProjectBuilder {
return new ProjectBuilder({
template,
plugins,
postProcessors,
});
}

View File

@ -1,101 +0,0 @@
/**
* Schema
*
*/
import { createProjectBuilder } from './generator/ProjectBuilder';
import { createModuleBuilder } from './generator/ModuleBuilder';
import { createDiskPublisher } from './publisher/disk';
import { createZipPublisher } from './publisher/zip';
import createIceJsProjectBuilder from './solutions/icejs';
import createRecoreProjectBuilder from './solutions/recore';
// 引入说明
import { REACT_CHUNK_NAME } from './plugins/component/react/const';
import { COMMON_CHUNK_NAME, CLASS_DEFINE_CHUNK_NAME, DEFAULT_LINK_AFTER } from './const/generator';
// 引入通用插件组
import esmodule from './plugins/common/esmodule';
import requireUtils from './plugins/common/requireUtils';
import containerClass from './plugins/component/react/containerClass';
import containerDataSource from './plugins/component/react/containerDataSource';
import containerInitState from './plugins/component/react/containerInitState';
import containerInjectUtils from './plugins/component/react/containerInjectUtils';
import containerLifeCycle from './plugins/component/react/containerLifeCycle';
import containerMethod from './plugins/component/react/containerMethod';
import jsx from './plugins/component/react/jsx';
import reactCommonDeps from './plugins/component/react/reactCommonDeps';
import css from './plugins/component/style/css';
import constants from './plugins/project/constants';
import i18n from './plugins/project/i18n';
import utils from './plugins/project/utils';
import prettier from './postprocessor/prettier';
// 引入常用工具
import * as utilsCommon from './utils/common';
import * as utilsCompositeType from './utils/compositeType';
import * as utilsJsExpression from './utils/jsExpression';
import * as utilsNodeToJSX from './utils/nodeToJSX';
import * as utilsTemplateHelper from './utils/templateHelper';
// 引入内置解决方案模块
import icejs from './plugins/project/framework/icejs';
export * from './types';
export default {
createProjectBuilder,
createModuleBuilder,
solutions: {
icejs: createIceJsProjectBuilder,
recore: createRecoreProjectBuilder,
},
solutionParts: {
icejs,
},
publishers: {
disk: createDiskPublisher,
zip: createZipPublisher,
},
plugins: {
common: {
esmodule,
requireUtils,
},
react: {
containerClass,
containerDataSource,
containerInitState,
containerInjectUtils,
containerLifeCycle,
containerMethod,
jsx,
reactCommonDeps,
},
style: {
css,
},
project: {
constants,
i18n,
utils,
},
},
postprocessor: {
prettier,
},
utils: {
common: utilsCommon,
compositeType: utilsCompositeType,
jsExpression: utilsJsExpression,
nodeToJSX: utilsNodeToJSX,
templateHelper: utilsTemplateHelper,
},
chunkNames: {
COMMON_CHUNK_NAME,
CLASS_DEFINE_CHUNK_NAME,
REACT_CHUNK_NAME,
},
defaultLinkAfter: {
COMMON_DEFAULT_LINK_AFTER: DEFAULT_LINK_AFTER,
},
};

View File

@ -1,33 +0,0 @@
import { CodeGeneratorError, IResultDir, IResultFile } from '../types';
export default class ResultDir implements IResultDir {
public name: string;
public dirs: IResultDir[];
public files: IResultFile[];
constructor(name: string) {
this.name = name;
this.dirs = [];
this.files = [];
}
public addDirectory(dir: IResultDir): void {
if (this.dirs.findIndex(d => d.name === dir.name) < 0) {
this.dirs.push(dir);
} else {
throw new CodeGeneratorError('Adding same directory to one directory');
}
}
public addFile(file: IResultFile): void {
if (
this.files.findIndex(f => f.name === file.name && f.ext === file.ext) < 0
) {
this.files.push(file);
} else {
throw new CodeGeneratorError('Adding same file to one directory');
}
}
}

View File

@ -1,15 +0,0 @@
import { IResultFile } from '../types';
export default class ResultFile implements IResultFile {
public name: string;
public ext: string;
public content: string;
constructor(name: string, ext = 'jsx', content = '') {
this.name = name;
this.ext = ext;
this.content = content;
}
}

View File

@ -1,234 +0,0 @@
/**
* 使
* schema
*/
import { SUPPORT_SCHEMA_VERSION_LIST } from '../const';
import { handleSubNodes } from '../utils/nodeToJSX';
import { uniqueArray } from '../utils/common';
import {
ChildNodeType,
CodeGeneratorError,
CompatibilityError,
DependencyType,
IBasicSchema,
IComponentNodeItem,
IContainerInfo,
IContainerNodeItem,
IExternalDependency,
IInternalDependency,
InternalDependencyType,
IPageMeta,
IParseResult,
IProjectSchema,
ISchemaParser,
IUtilItem,
INpmPackage,
} from '../types';
const defaultContainer: IContainerInfo = {
containerType: 'Component',
componentName: 'Component',
moduleName: 'Index',
fileName: 'Index',
css: '',
props: {},
};
class SchemaParser implements ISchemaParser {
validate(schema: IBasicSchema): boolean {
if (SUPPORT_SCHEMA_VERSION_LIST.indexOf(schema.version) < 0) {
throw new CompatibilityError(`Not support schema with version [${schema.version}]`);
}
return true;
}
parse(schemaSrc: IProjectSchema | string): IParseResult {
// TODO: collect utils depends in JSExpression
const compDeps: Record<string, IExternalDependency> = {};
const internalDeps: Record<string, IInternalDependency> = {};
let utilsDeps: IExternalDependency[] = [];
let schema: IProjectSchema;
if (typeof schemaSrc === 'string') {
try {
schema = JSON.parse(schemaSrc);
} catch (error) {
throw new CodeGeneratorError(`Parse schema failed: ${error.message || 'unknown reason'}`);
}
} else {
schema = schemaSrc;
}
// 解析三方组件依赖
schema.componentsMap.forEach((info) => {
info.dependencyType = DependencyType.External;
info.importName = info.componentName;
compDeps[info.componentName] = info;
});
let containers: IContainerInfo[];
// Test if this is a lowcode component without container
if (schema.componentsTree.length > 0) {
const firstRoot: IContainerNodeItem = schema.componentsTree[0] as IContainerNodeItem;
if (!firstRoot.fileName) {
// 整个 schema 描述一个容器,且无根节点定义
const container: IContainerInfo = {
...defaultContainer,
children: schema.componentsTree as IComponentNodeItem[],
};
containers = [container];
} else {
// 普通带 1 到多个容器的 schema
containers = schema.componentsTree.map((n) => {
const subRoot = n as IContainerNodeItem;
const container: IContainerInfo = {
...subRoot,
containerType: subRoot.componentName,
moduleName: subRoot.fileName, // TODO: 驼峰化名称
};
return container;
});
}
} else {
throw new CodeGeneratorError('Can\'t find anything to generate.');
}
// 建立所有容器的内部依赖索引
containers.forEach((container) => {
let type;
switch (container.containerType) {
case 'Page':
type = InternalDependencyType.PAGE;
break;
case 'Block':
type = InternalDependencyType.BLOCK;
break;
default:
type = InternalDependencyType.COMPONENT;
break;
}
const dep: IInternalDependency = {
type,
moduleName: container.moduleName,
destructuring: false,
exportName: container.moduleName,
dependencyType: DependencyType.Internal,
};
internalDeps[dep.moduleName] = dep;
});
// TODO: 不应该在出码部分解决?
// 处理 children 写在了 props 里的情况
containers.forEach((container) => {
if (container.children) {
handleSubNodes<string>(
container.children,
{
node: (i: IComponentNodeItem) => {
if (i.props && i.props.children && !i.children) {
i.children = i.props.children as ChildNodeType;
}
return [''];
},
},
{
rerun: true,
},
);
}
});
// 分析容器内部组件依赖
containers.forEach((container) => {
if (container.children) {
const depNames = this.getComponentNames(container.children);
container.deps = uniqueArray<string>(depNames, (i: string) => i)
.map((depName) => internalDeps[depName] || compDeps[depName])
.filter((dep) => !!dep);
// container.deps = Object.keys(compDeps).map((depName) => compDeps[depName]);
}
});
// 分析路由配置
const routes = containers
.filter((container) => container.containerType === 'Page')
.map((page) => {
const meta = page.meta as IPageMeta;
if (meta) {
return {
path: meta.router,
componentName: page.moduleName,
};
}
return {
path: '',
componentName: page.moduleName,
};
});
const routerDeps = routes
.map((r) => internalDeps[r.componentName] || compDeps[r.componentName])
.filter((dep) => !!dep);
// 分析 Utils 依赖
let utils: IUtilItem[];
if (schema.utils) {
utils = schema.utils;
utilsDeps = schema.utils.filter((u) => u.type !== 'function').map((u) => u.content as IExternalDependency);
} else {
utils = [];
}
// 分析项目 npm 依赖
let npms: INpmPackage[] = [];
containers.forEach((con) => {
const p = (con.deps || [])
.map((dep) => (dep.dependencyType === DependencyType.External ? dep : null))
.filter((dep) => dep !== null);
npms.push(...((p as unknown) as INpmPackage[]));
});
npms = uniqueArray<INpmPackage>(npms, (i) => i.package);
return {
containers,
globalUtils: {
utils,
deps: utilsDeps,
},
globalI18n: schema.i18n,
globalRouter: {
routes,
deps: routerDeps,
},
project: {
meta: schema.meta,
config: schema.config,
css: schema.css,
constants: schema.constants,
i18n: schema.i18n,
packages: npms,
},
};
}
getComponentNames(children: ChildNodeType): string[] {
return handleSubNodes<string>(
children,
{
node: (i: IComponentNodeItem) => [i.componentName],
},
{
rerun: true,
},
);
}
}
export default SchemaParser;

View File

@ -1,161 +0,0 @@
import { COMMON_CHUNK_NAME } from '../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
CodeGeneratorError,
DependencyType,
FileType,
ICodeChunk,
ICodeStruct,
IDependency,
IExternalDependency,
IInternalDependency,
IWithDependency,
} from '../../types';
import { isValidIdentifier } from '../../utils/validate';
function groupDepsByPack(deps: IDependency[]): Record<string, IDependency[]> {
const depMap: Record<string, IDependency[]> = {};
const addDep = (pkg: string, dep: IDependency) => {
if (!depMap[pkg]) {
depMap[pkg] = [];
}
depMap[pkg].push(dep);
};
// TODO: main 这个信息到底怎么用,是不是外部包不需要使用?
// deps.forEach(dep => {
// if (dep.dependencyType === DependencyType.Internal) {
// addDep(
// `${(dep as IInternalDependency).moduleName}${`/${dep.main}` || ''}`,
// dep,
// );
// } else {
// addDep(`${(dep as IExternalDependency).package}${`/${dep.main}` || ''}`, dep);
// }
// });
deps.forEach((dep) => {
if (dep.dependencyType === DependencyType.Internal) {
addDep(`${(dep as IInternalDependency).moduleName}`, dep);
} else {
addDep(`${(dep as IExternalDependency).package}`, dep);
}
});
return depMap;
}
function buildPackageImport(pkg: string, deps: IDependency[], targetFileType: string): ICodeChunk[] {
const chunks: ICodeChunk[] = [];
let defaultImport = '';
let defaultImportAs = '';
const imports: Record<string, string> = {};
deps.forEach((dep) => {
const srcName = dep.exportName;
let targetName = dep.importName || dep.exportName;
if (dep.subName) {
if (targetName !== `${srcName}.${dep.subName}`) {
if (!isValidIdentifier(targetName)) {
throw new CodeGeneratorError(`Invalid Identifier [${targetName}]`);
}
chunks.push({
type: ChunkType.STRING,
fileType: targetFileType,
name: COMMON_CHUNK_NAME.FileVarDefine,
content: `const ${targetName} = ${srcName}.${dep.subName};`,
linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport, COMMON_CHUNK_NAME.InternalDepsImport],
});
}
targetName = srcName;
}
if (dep.destructuring) {
imports[srcName] = targetName;
} else if (defaultImport) {
throw new CodeGeneratorError(`[${pkg}] has more than one default export.`);
} else {
defaultImport = srcName;
defaultImportAs = targetName;
}
});
const items = Object.keys(imports).map((src) => (src === imports[src] ? src : `${src} as ${imports[src]}`));
const statementL = ['import'];
if (defaultImport) {
statementL.push(defaultImportAs);
if (items.length > 0) {
statementL.push(',');
}
}
if (items.length > 0) {
statementL.push(`{ ${items.join(', ')} }`);
}
statementL.push('from');
if (deps[0].dependencyType === DependencyType.Internal) {
// TODO: Internal Deps path use project slot setting
statementL.push(`'@/${(deps[0] as IInternalDependency).type}/${pkg}';`);
chunks.push({
type: ChunkType.STRING,
fileType: targetFileType,
name: COMMON_CHUNK_NAME.InternalDepsImport,
content: statementL.join(' '),
linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport],
});
} else {
statementL.push(`'${pkg}';`);
chunks.push({
type: ChunkType.STRING,
fileType: targetFileType,
name: COMMON_CHUNK_NAME.ExternalDepsImport,
content: statementL.join(' '),
linkAfter: [],
});
}
return chunks;
}
type PluginConfig = {
fileType: string;
};
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?: PluginConfig) => {
const cfg: PluginConfig = {
fileType: FileType.JS,
...config,
};
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IWithDependency;
if (ir && ir.deps && ir.deps.length > 0) {
const packs = groupDepsByPack(ir.deps);
Object.keys(packs).forEach((pkg) => {
const chunks = buildPackageImport(pkg, packs[pkg], cfg.fileType);
next.chunks.push(...chunks);
});
}
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,31 +0,0 @@
import { COMMON_CHUNK_NAME } from '../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
} from '../../types';
// TODO: How to merge this logic to common deps
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JSX,
name: COMMON_CHUNK_NAME.InternalDepsImport,
content: 'import * from \'react\';',
linkAfter: [],
});
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,9 +0,0 @@
export const REACT_CHUNK_NAME = {
ClassRenderStart: 'ReactComponentClassRenderStart',
ClassRenderPre: 'ReactComponentClassRenderPre',
ClassRenderEnd: 'ReactComponentClassRenderEnd',
ClassRenderJSX: 'ReactComponentClassRenderJSX',
ClassDidMountStart: 'ReactComponentClassDidMountStart',
ClassDidMountEnd: 'ReactComponentClassDidMountEnd',
ClassDidMountContent: 'ReactComponentClassDidMountContent',
};

View File

@ -1,104 +0,0 @@
import { COMMON_CHUNK_NAME, CLASS_DEFINE_CHUNK_NAME } from '../../../const/generator';
import { REACT_CHUNK_NAME } from './const';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IContainerInfo,
} from '../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IContainerInfo;
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JSX,
name: CLASS_DEFINE_CHUNK_NAME.Start,
content: `class ${ir.moduleName} extends React.Component {`,
linkAfter: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileVarDefine,
COMMON_CHUNK_NAME.FileUtilDefine,
],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JSX,
name: CLASS_DEFINE_CHUNK_NAME.End,
content: '}',
linkAfter: [CLASS_DEFINE_CHUNK_NAME.Start, REACT_CHUNK_NAME.ClassRenderEnd],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JSX,
name: CLASS_DEFINE_CHUNK_NAME.ConstructorStart,
content: 'constructor(props, context) { super(props); ',
linkAfter: [CLASS_DEFINE_CHUNK_NAME.Start],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JSX,
name: CLASS_DEFINE_CHUNK_NAME.ConstructorEnd,
content: '}',
linkAfter: [
CLASS_DEFINE_CHUNK_NAME.ConstructorStart,
CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JSX,
name: REACT_CHUNK_NAME.ClassRenderStart,
content: 'render() {',
linkAfter: [
CLASS_DEFINE_CHUNK_NAME.Start,
CLASS_DEFINE_CHUNK_NAME.ConstructorEnd,
CLASS_DEFINE_CHUNK_NAME.InsMethod,
],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JSX,
name: REACT_CHUNK_NAME.ClassRenderEnd,
content: '}',
linkAfter: [
REACT_CHUNK_NAME.ClassRenderStart,
REACT_CHUNK_NAME.ClassRenderPre,
REACT_CHUNK_NAME.ClassRenderJSX,
],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JSX,
name: COMMON_CHUNK_NAME.FileExport,
content: `export default ${ir.moduleName};`,
linkAfter: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileVarDefine,
COMMON_CHUNK_NAME.FileUtilDefine,
CLASS_DEFINE_CHUNK_NAME.End,
],
});
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,52 +0,0 @@
import { CLASS_DEFINE_CHUNK_NAME } from '../../../const/generator';
import { generateCompositeType } from '../../../utils/compositeType';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IContainerInfo,
} from '../../../types';
type PluginConfig = {
fileType: string;
};
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
const cfg: PluginConfig = {
fileType: FileType.JSX,
...config,
};
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IContainerInfo;
if (ir.state) {
const { state } = ir;
const fields = Object.keys(state).map<string>((stateName) => {
const value = generateCompositeType(state[stateName]);
return `${stateName}: ${value},`;
});
next.chunks.push({
type: ChunkType.STRING,
fileType: cfg.fileType,
name: CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
content: `this.state = { ${fields.join('')} };`,
linkAfter: [CLASS_DEFINE_CHUNK_NAME.ConstructorStart],
});
}
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,64 +0,0 @@
import { CLASS_DEFINE_CHUNK_NAME, DEFAULT_LINK_AFTER } from '../../../const/generator';
import { generateCompositeType } from '../../../utils/compositeType';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IContainerInfo,
} from '../../../types';
type PluginConfig = {
fileType: string;
implementType: 'inConstructor' | 'insMember' | 'hooks';
};
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
const cfg: PluginConfig = {
fileType: FileType.JSX,
implementType: 'inConstructor',
...config,
};
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IContainerInfo;
if (ir.state) {
const { state } = ir;
const fields = Object.keys(state).map<string>((stateName) => {
const value = generateCompositeType(state[stateName]);
return `${stateName}: ${value},`;
});
if (cfg.implementType === 'inConstructor') {
next.chunks.push({
type: ChunkType.STRING,
fileType: cfg.fileType,
name: CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
content: `this.state = { ${fields.join('')} };`,
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.ConstructorContent]],
});
} else if (cfg.implementType === 'insMember') {
next.chunks.push({
type: ChunkType.STRING,
fileType: cfg.fileType,
name: CLASS_DEFINE_CHUNK_NAME.InsVar,
content: `state = { ${fields.join('')} };`,
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.InsVar]],
});
}
}
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,39 +0,0 @@
import { CLASS_DEFINE_CHUNK_NAME } from '../../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
} from '../../../types';
type PluginConfig = {
fileType: string;
};
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
const cfg: PluginConfig = {
fileType: FileType.JSX,
...config,
};
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
next.chunks.push({
type: ChunkType.STRING,
fileType: cfg.fileType,
name: CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
content: 'this.utils = utils;',
linkAfter: [CLASS_DEFINE_CHUNK_NAME.ConstructorStart],
});
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,78 +0,0 @@
import { CLASS_DEFINE_CHUNK_NAME, DEFAULT_LINK_AFTER } from '../../../const/generator';
import { REACT_CHUNK_NAME } from './const';
import { generateFunction } from '../../../utils/jsExpression';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeChunk,
ICodeStruct,
IContainerInfo,
} from '../../../types';
type PluginConfig = {
fileType: string;
exportNameMapping: Record<string, string>;
normalizeNameMapping: Record<string, string>;
};
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
const cfg: PluginConfig = {
fileType: FileType.JSX,
exportNameMapping: {},
normalizeNameMapping: {},
...config,
};
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IContainerInfo;
if (ir.lifeCycles) {
const { lifeCycles } = ir;
const chunks = Object.keys(lifeCycles).map<ICodeChunk>((lifeCycleName) => {
const normalizeName = cfg.normalizeNameMapping[lifeCycleName] || lifeCycleName;
const exportName = cfg.exportNameMapping[lifeCycleName] || lifeCycleName;
if (normalizeName === 'constructor') {
return {
type: ChunkType.STRING,
fileType: cfg.fileType,
name: CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
content: generateFunction(lifeCycles[lifeCycleName], { isBlock: true }),
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.ConstructorStart]],
};
}
if (normalizeName === 'render') {
return {
type: ChunkType.STRING,
fileType: cfg.fileType,
name: REACT_CHUNK_NAME.ClassRenderPre,
content: generateFunction(lifeCycles[lifeCycleName], { isBlock: true }),
linkAfter: [REACT_CHUNK_NAME.ClassRenderStart],
};
}
return {
type: ChunkType.STRING,
fileType: cfg.fileType,
name: CLASS_DEFINE_CHUNK_NAME.InsMethod,
content: generateFunction(lifeCycles[lifeCycleName], { name: exportName, isMember: true }),
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.InsMethod]],
};
});
next.chunks.push(...chunks);
}
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,50 +0,0 @@
import { CLASS_DEFINE_CHUNK_NAME, DEFAULT_LINK_AFTER } from '../../../const/generator';
import { generateFunction } from '../../../utils/jsExpression';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeChunk,
ICodeStruct,
IContainerInfo,
} from '../../../types';
type PluginConfig = {
fileType: string;
};
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
const cfg: PluginConfig = {
fileType: FileType.JSX,
...config,
};
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IContainerInfo;
if (ir.methods) {
const { methods } = ir;
const chunks = Object.keys(methods).map<ICodeChunk>((methodName) => ({
type: ChunkType.STRING,
fileType: cfg.fileType,
name: CLASS_DEFINE_CHUNK_NAME.InsMethod,
content: generateFunction(methods[methodName], { name: methodName, isMember: true }),
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.InsMethod]],
}));
next.chunks.push(...chunks);
}
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,52 +0,0 @@
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IContainerInfo,
} from '../../../types';
import { REACT_CHUNK_NAME } from './const';
import { createReactNodeGenerator } from '../../../utils/nodeToJSX';
type PluginConfig = {
fileType?: string;
nodeTypeMapping?: Record<string, string>;
};
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
const cfg = {
fileType: FileType.JSX,
nodeTypeMapping: {},
...config,
};
const generator = createReactNodeGenerator({ nodeTypeMapping: cfg.nodeTypeMapping });
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IContainerInfo;
const jsxContent = generator(ir);
next.chunks.push({
type: ChunkType.STRING,
fileType: cfg.fileType,
name: REACT_CHUNK_NAME.ClassRenderJSX,
content: `return ${jsxContent};`,
linkAfter: [
REACT_CHUNK_NAME.ClassRenderStart,
REACT_CHUNK_NAME.ClassRenderPre,
],
});
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,31 +0,0 @@
import { COMMON_CHUNK_NAME } from '../../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IContainerInfo,
} from '../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JSX,
name: COMMON_CHUNK_NAME.ExternalDepsImport,
content: 'import React from \'react\';',
linkAfter: [],
});
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,3 +0,0 @@
export const RECORE_CHUNK_NAME = {
};

View File

@ -1,66 +0,0 @@
import { CLASS_DEFINE_CHUNK_NAME, DEFAULT_LINK_AFTER } from '../../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IContainerInfo,
IJSExpression,
CompositeValue,
} from '../../../types';
import { generateCompositeType } from '../../../utils/compositeType';
import { generateExpression } from '../../../utils/jsExpression';
function packJsExpression(exp: unknown): string {
const expression = exp as IJSExpression;
const funcStr = generateExpression(expression);
return `function() { return (${funcStr}); }`;
}
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IContainerInfo;
if (ir.dataSource) {
const { dataSource } = ir;
const { list, ...rest } = dataSource;
let attrs: string[] = [];
const extConfigs = Object.keys(rest).map((extConfigName) => {
const value = (rest as Record<string, CompositeValue>)[extConfigName];
const valueStr = generateCompositeType(value);
return `${extConfigName}: ${valueStr}`;
});
attrs = [...attrs, ...extConfigs];
const listProp = generateCompositeType((list as unknown) as CompositeValue, {
handlers: {
expression: packJsExpression,
},
});
attrs.push(`list: ${listProp}`);
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.TS,
name: CLASS_DEFINE_CHUNK_NAME.InsVar,
content: `dataSourceOptions = { ${attrs.join(',\n')} };`,
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.InsVar]],
});
}
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,81 +0,0 @@
import { COMMON_CHUNK_NAME, CLASS_DEFINE_CHUNK_NAME, DEFAULT_LINK_AFTER } from '../../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IContainerInfo,
} from '../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IContainerInfo;
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.TS,
name: COMMON_CHUNK_NAME.ExternalDepsImport,
content: 'import { BaseController } from \'@ali/recore-renderer\';',
linkAfter: [],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.TS,
name: CLASS_DEFINE_CHUNK_NAME.Start,
content: `class ${ir.moduleName} extends BaseController {`,
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.Start]],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.TS,
name: CLASS_DEFINE_CHUNK_NAME.End,
content: '}',
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.End]],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.TS,
name: CLASS_DEFINE_CHUNK_NAME.ConstructorStart,
content: 'init() {',
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.ConstructorStart]],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.TS,
name: CLASS_DEFINE_CHUNK_NAME.ConstructorEnd,
content: '}',
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.ConstructorEnd]],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.TS,
name: CLASS_DEFINE_CHUNK_NAME.InsVar,
content: 'globalProps = (window as any)?.g_config?.globalProps || {};',
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.InsVar]],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.TS,
name: COMMON_CHUNK_NAME.FileExport,
content: `export default ${ir.moduleName};`,
linkAfter: [...DEFAULT_LINK_AFTER[COMMON_CHUNK_NAME.FileExport]],
});
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,35 +0,0 @@
import { CLASS_DEFINE_CHUNK_NAME, DEFAULT_LINK_AFTER } from '../../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
ICodeStruct,
FileType,
IContainerInfo,
} from '../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IContainerInfo;
if (ir.css) {
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.TS,
name: CLASS_DEFINE_CHUNK_NAME.StaticVar,
content: `static cssText = '${ir.css.replace(/\'/g, '\\\'')}';`,
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.StaticVar]],
});
}
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,85 +0,0 @@
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
ICodeStruct,
IContainerInfo,
IComponentNodeItem,
INodeGeneratorContext,
CodePiece,
PIECE_TYPE,
} from '../../../types';
import { COMMON_CHUNK_NAME } from '../../../const/generator';
import { createNodeGenerator, generateString } from '../../../utils/nodeToJSX';
import { generateExpression } from '../../../utils/jsExpression';
import { generateCompositeType } from '../../../utils/compositeType';
const generateGlobalProps = (ctx: INodeGeneratorContext, nodeItem: IComponentNodeItem): CodePiece[] => {
return [
{
value: `{...globalProps.${nodeItem.componentName}}`,
type: PIECE_TYPE.ATTR,
},
];
};
const generateCtrlLine = (ctx: INodeGeneratorContext, nodeItem: IComponentNodeItem): CodePiece[] => {
const pieces: CodePiece[] = [];
if (nodeItem.loop && nodeItem.loopArgs) {
const loopDataExp = generateCompositeType(nodeItem.loop);
pieces.push({
type: PIECE_TYPE.ATTR,
value: `x-for={${loopDataExp}}`,
});
pieces.push({
type: PIECE_TYPE.ATTR,
value: `x-each="${nodeItem.loopArgs[0]},${nodeItem.loopArgs[1]}"`,
});
}
if (nodeItem.condition) {
const conditionExp = generateCompositeType(nodeItem.condition);
pieces.push({
type: PIECE_TYPE.ATTR,
value: `x-if={${conditionExp}}`,
});
}
return pieces;
};
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const generator = createNodeGenerator(
{
string: generateString,
expression: (input) => [generateExpression(input)],
},
[generateGlobalProps, generateCtrlLine],
);
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IContainerInfo;
const vxContent = generator(ir);
next.chunks.push({
type: ChunkType.STRING,
fileType: 'vx',
name: COMMON_CHUNK_NAME.CustomContent,
content: vxContent,
linkAfter: [],
});
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,29 +0,0 @@
import { COMMON_CHUNK_NAME } from '../../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
ICodeStruct,
} from '../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
next.chunks.push({
type: ChunkType.STRING,
fileType: 'vx',
name: COMMON_CHUNK_NAME.CustomContent,
content: '<div {...globalProps.div} className="recore-loading" x-if={this.__loading} />',
linkAfter: [],
});
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,52 +0,0 @@
import { COMMON_CHUNK_NAME } from '../../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IContainerInfo,
} from '../../../types';
type PluginConfig = {
fileType: string;
moduleFileType: string;
};
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
const cfg: PluginConfig = {
fileType: FileType.CSS,
moduleFileType: FileType.JSX,
...config,
};
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IContainerInfo;
next.chunks.push({
type: ChunkType.STRING,
fileType: cfg.fileType,
name: COMMON_CHUNK_NAME.StyleCssContent,
content: ir.css,
linkAfter: [COMMON_CHUNK_NAME.StyleDepsImport],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: cfg.moduleFileType,
name: COMMON_CHUNK_NAME.InternalDepsImport,
content: `import './index.${cfg.fileType}';`,
linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport],
});
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,54 +0,0 @@
import { COMMON_CHUNK_NAME } from '../../const/generator';
import { generateCompositeType } from '../../utils/compositeType';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IProjectInfo,
} from '../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IProjectInfo;
if (ir.constants) {
const constantStr = generateCompositeType(ir.constants);
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JS,
name: COMMON_CHUNK_NAME.FileVarDefine,
content: `
const constantConfig = ${constantStr};
`,
linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport, COMMON_CHUNK_NAME.InternalDepsImport],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JS,
name: COMMON_CHUNK_NAME.FileExport,
content: `
export default constantConfig;
`,
linkAfter: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileVarDefine,
COMMON_CHUNK_NAME.FileUtilDefine,
COMMON_CHUNK_NAME.FileMainContent,
],
});
}
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,17 +0,0 @@
import template from './template';
import entry from './plugins/entry';
import entryHtml from './plugins/entryHtml';
import globalStyle from './plugins/globalStyle';
import packageJSON from './plugins/packageJSON';
import router from './plugins/router';
export default {
template,
plugins: {
entry,
entryHtml,
globalStyle,
packageJSON,
router,
},
};

View File

@ -1,58 +0,0 @@
import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IProjectInfo,
} from '../../../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IProjectInfo;
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JS,
name: COMMON_CHUNK_NAME.ExternalDepsImport,
content: `
import { createApp } from 'ice';
`,
linkAfter: [],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JS,
name: COMMON_CHUNK_NAME.FileMainContent,
content: `
const appConfig = {
app: {
rootId: '${ir.config.targetRootID}',
},
router: {
type: '${ir.config.historyMode}',
},
};
createApp(appConfig);
`,
linkAfter: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileVarDefine,
COMMON_CHUNK_NAME.FileUtilDefine,
],
});
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,46 +0,0 @@
import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IProjectInfo,
} from '../../../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IProjectInfo;
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.HTML,
name: COMMON_CHUNK_NAME.HtmlContent,
content: `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1" />
<meta name="viewport" content="width=device-width" />
<title>${ir.meta.name}</title>
</head>
<body>
<div id="${ir.config.targetRootID}"></div>
</body>
</html>
`,
linkAfter: [],
});
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,56 +0,0 @@
import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IProjectInfo,
} from '../../../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IProjectInfo;
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.SCSS,
name: COMMON_CHUNK_NAME.StyleDepsImport,
content: `
// 引入默认全局样式
@import '@alifd/next/reset.scss';
`,
linkAfter: [],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.SCSS,
name: COMMON_CHUNK_NAME.StyleCssContent,
content: `
body {
-webkit-font-smoothing: antialiased;
}
`,
linkAfter: [COMMON_CHUNK_NAME.StyleDepsImport],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.SCSS,
name: COMMON_CHUNK_NAME.StyleCssContent,
content: ir.css || '',
linkAfter: [COMMON_CHUNK_NAME.StyleDepsImport],
});
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,91 +0,0 @@
import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IPackageJSON,
IProjectInfo,
} from '../../../../../types';
interface IIceJsPackageJSON extends IPackageJSON {
ideMode: {
name: string;
};
iceworks: {
type: string;
adapter: string;
};
originTemplate: string;
}
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IProjectInfo;
const packageJson: IIceJsPackageJSON = {
name: '@alifd/scaffold-lite-js',
version: '0.1.5',
description: '轻量级模板,使用 JavaScript仅包含基础的 Layout。',
dependencies: {
moment: '^2.24.0',
react: '^16.4.1',
'react-dom': '^16.4.1',
'@alifd/theme-design-pro': '^0.x',
},
devDependencies: {
'@ice/spec': '^1.0.0',
'build-plugin-fusion': '^0.1.0',
'build-plugin-moment-locales': '^0.1.0',
eslint: '^6.0.1',
'ice.js': '^1.0.0',
stylelint: '^13.2.0',
'@ali/build-plugin-ice-def': '^0.1.0',
},
scripts: {
start: 'icejs start',
build: 'icejs build',
lint: 'npm run eslint && npm run stylelint',
eslint: 'eslint --cache --ext .js,.jsx ./',
stylelint: 'stylelint ./**/*.scss',
},
ideMode: {
name: 'ice-react',
},
iceworks: {
type: 'react',
adapter: 'adapter-react-v3',
},
engines: {
node: '>=8.0.0',
},
repository: {
type: 'git',
url: 'http://gitlab.alibaba-inc.com/msd/leak-scan/tree/master',
},
private: true,
originTemplate: '@alifd/scaffold-lite-js',
};
ir.packages.forEach((packageInfo) => (packageJson.dependencies[packageInfo.package] = packageInfo.version));
next.chunks.push({
type: ChunkType.JSON,
fileType: FileType.JSON,
name: COMMON_CHUNK_NAME.FileMainContent,
content: packageJson,
linkAfter: [],
});
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,82 +0,0 @@
import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IRouterInfo,
} from '../../../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IRouterInfo;
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JS,
name: COMMON_CHUNK_NAME.InternalDepsImport,
content: `
import BasicLayout from '@/layouts/BasicLayout';
`,
linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JS,
name: COMMON_CHUNK_NAME.FileVarDefine,
content: `
const routerConfig = [
{
path: '/',
component: BasicLayout,
children: [
${ir.routes
.map(
route => `
{
path: '${route.path}',
component: ${route.componentName},
}
`,
)
.join(',')}
],
},
];
`,
linkAfter: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileUtilDefine,
],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JS,
name: COMMON_CHUNK_NAME.FileExport,
content: `
export default routerConfig;
`,
linkAfter: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileUtilDefine,
COMMON_CHUNK_NAME.FileVarDefine,
COMMON_CHUNK_NAME.FileMainContent,
],
});
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,73 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'README',
'md',
`
## Scaffold Lite
> 使 JavaScript Layout
## 使
\`\`\`bash
#
$ npm install
#
$ npm start # visit http://localhost:3333
\`\`\`
[More docs](https://ice.work/docs/guide/about).
##
\`\`\`md
build/ #
mock/ #
index.[j,t]s
public/
index.html # HTML
favicon.png # Favicon
src/ #
components/ #
Guide/
index.[j,t]sx
index.module.scss
layouts/ #
BasicLayout/
index.[j,t]sx
index.module.scss
pages/ #
Home/ # home
components/ #
models.[j,t]sx #
index.[j,t]sx #
index.module.scss #
configs/ # []
menu.[j,t]s # []
models/ # []
user.[j,t]s
utils/ # []
global.scss #
routes.[j,t]s #
app.[j,t]s[x] #
build.json #
README.md
package.json
.editorconfig
.eslintignore
.eslintrc.[j,t]s
.gitignore
.stylelintignore
.stylelintrc.[j,t]s
.gitignore
[j,t]sconfig.json
\`\`\`
`,
);
return [[], file];
}

View File

@ -1,17 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'abc',
'json',
`
{
"type": "ice-app",
"builder": "@ali/builder-ice-app"
}
`,
);
return [[], file];
}

View File

@ -1,33 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'build',
'json',
`
{
"entry": "src/app.js",
"plugins": [
[
"build-plugin-fusion",
{
"themePackage": "@alifd/theme-design-pro"
}
],
[
"build-plugin-moment-locales",
{
"locales": [
"zh-cn"
]
}
],
"@ali/build-plugin-ice-def"
]
}
`,
);
return [[], file];
}

View File

@ -1,25 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'.editorconfig',
'',
`
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
`,
);
return [[], file];
}

View File

@ -1,28 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'.eslintignore',
'',
`
#
build/
tests/
demo/
.ice/
# node
coverage/
#
**/*-min.js
**/*.min.js
package-lock.json
yarn.lock
`,
);
return [[], file];
}

View File

@ -1,16 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'.eslintrc',
'js',
`
const { eslint } = require('@ice/spec');
module.exports = eslint;
`,
);
return [[], file];
}

View File

@ -1,36 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'.gitignore',
'',
`
# See https://help.github.com/ignore-files/ for more about ignoring files.
# dependencies
node_modules/
# production
build/
dist/
tmp/
lib/
# misc
.idea/
.happypack
.DS_Store
*.swp
*.dia~
.ice
npm-debug.log*
yarn-debug.log*
yarn-error.log*
index.module.scss.d.ts
`,
);
return [[], file];
}

View File

@ -1,24 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'jsconfig',
'json',
`
{
"compilerOptions": {
"baseUrl": ".",
"jsx": "react",
"paths": {
"@/*": ["./src/*"],
"ice": [".ice/index.ts"],
"ice/*": [".ice/pages/*"]
}
}
}
`,
);
return [[], file];
}

View File

@ -1,22 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'.prettierignore',
'',
`
build/
tests/
demo/
.ice/
coverage/
**/*-min.js
**/*.min.js
package-lock.json
yarn.lock
`,
);
return [[], file];
}

View File

@ -1,16 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'.prettierrc',
'js',
`
const { prettier } = require('@ice/spec');
module.exports = prettier;
`,
);
return [[], file];
}

View File

@ -1,25 +0,0 @@
import ResultFile from '../../../../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'index',
'jsx',
`
import React from 'react';
import styles from './index.module.scss';
export default function Footer() {
return (
<p className={styles.footer}>
<span className={styles.logo}>Alibaba Fusion</span>
<br />
<span className={styles.copyright}>© 2019- Alibaba Fusion & ICE</span>
</p>
);
}
`,
);
return [['src', 'layouts', 'BasicLayout', 'components', 'Footer'], file];
}

View File

@ -1,26 +0,0 @@
import ResultFile from '../../../../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'index',
'module.scss',
`
.footer {
line-height: 20px;
text-align: center;
}
.logo {
font-weight: bold;
font-size: 16px;
}
.copyright {
font-size: 12px;
}
`,
);
return [['src', 'layouts', 'BasicLayout', 'components', 'Footer'], file];
}

View File

@ -1,27 +0,0 @@
import ResultFile from '../../../../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'index',
'jsx',
`
import React from 'react';
import { Link } from 'ice';
import styles from './index.module.scss';
export default function Logo({ image, text, url }) {
return (
<div className="logo">
<Link to={url || '/'} className={styles.logo}>
{image && <img src={image} alt="logo" />}
<span>{text}</span>
</Link>
</div>
);
}
`,
);
return [['src', 'layouts', 'BasicLayout', 'components', 'Logo'], file];
}

View File

@ -1,31 +0,0 @@
import ResultFile from '../../../../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'index',
'module.scss',
`
.logo{
display: flex;
align-items: center;
justify-content: center;
color: $color-text1-1;
font-weight: bold;
font-size: 14px;
line-height: 22px;
&:visited, &:link {
color: $color-text1-1;
}
img {
height: 24px;
margin-right: 10px;
}
}
`,
);
return [['src', 'layouts', 'BasicLayout', 'components', 'Logo'], file];
}

View File

@ -1,81 +0,0 @@
import ResultFile from '../../../../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'index',
'jsx',
`
import React from 'react';
import PropTypes from 'prop-types';
import { Link, withRouter } from 'ice';
import { Nav } from '@alifd/next';
import { asideMenuConfig } from '../../menuConfig';
const { SubNav } = Nav;
const NavItem = Nav.Item;
function getNavMenuItems(menusData) {
if (!menusData) {
return [];
}
return menusData
.filter(item => item.name && !item.hideInMenu)
.map((item, index) => getSubMenuOrItem(item, index));
}
function getSubMenuOrItem(item, index) {
if (item.children && item.children.some(child => child.name)) {
const childrenItems = getNavMenuItems(item.children);
if (childrenItems && childrenItems.length > 0) {
const subNav = (
<SubNav key={index} icon={item.icon} label={item.name}>
{childrenItems}
</SubNav>
);
return subNav;
}
return null;
}
const navItem = (
<NavItem key={item.path} icon={item.icon}>
<Link to={item.path}>{item.name}</Link>
</NavItem>
);
return navItem;
}
const Navigation = (props, context) => {
const { location } = props;
const { pathname } = location;
const { isCollapse } = context;
return (
<Nav
type="primary"
selectedKeys={[pathname]}
defaultSelectedKeys={[pathname]}
embeddable
openMode="single"
iconOnly={isCollapse}
hasArrow={false}
mode={isCollapse ? 'popup' : 'inline'}
>
{getNavMenuItems(asideMenuConfig)}
</Nav>
);
};
Navigation.contextTypes = {
isCollapse: PropTypes.bool,
};
const PageNav = withRouter(Navigation);
export default PageNav;
`,
);
return [['src', 'layouts', 'BasicLayout', 'components', 'PageNav'], file];
}

View File

@ -1,92 +0,0 @@
import ResultFile from '../../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'index',
'jsx',
`
import React, { useState } from 'react';
import { Shell, ConfigProvider } from '@alifd/next';
import PageNav from './components/PageNav';
import Logo from './components/Logo';
import Footer from './components/Footer';
(function() {
const throttle = function(type, name, obj = window) {
let running = false;
const func = () => {
if (running) {
return;
}
running = true;
requestAnimationFrame(() => {
obj.dispatchEvent(new CustomEvent(name));
running = false;
});
};
obj.addEventListener(type, func);
};
throttle('resize', 'optimizedResize');
})();
export default function BasicLayout({ children }) {
const getDevice = width => {
const isPhone =
typeof navigator !== 'undefined' && navigator && navigator.userAgent.match(/phone/gi);
if (width < 680 || isPhone) {
return 'phone';
}
if (width < 1280 && width > 680) {
return 'tablet';
}
return 'desktop';
};
const [device, setDevice] = useState(getDevice(NaN));
window.addEventListener('optimizedResize', e => {
setDevice(getDevice(e && e.target && e.target.innerWidth));
});
return (
<ConfigProvider device={device}>
<Shell
type="dark"
style={{
minHeight: '100vh',
}}
>
<Shell.Branding>
<Logo
image="https://img.alicdn.com/tfs/TB1.ZBecq67gK0jSZFHXXa9jVXa-904-826.png"
text="Logo"
/>
</Shell.Branding>
<Shell.Navigation
direction="hoz"
style={{
marginRight: 10,
}}
></Shell.Navigation>
<Shell.Action></Shell.Action>
<Shell.Navigation>
<PageNav />
</Shell.Navigation>
<Shell.Content>{children}</Shell.Content>
<Shell.Footer>
<Footer />
</Shell.Footer>
</Shell>
</ConfigProvider>
);
}
`,
);
return [['src', 'layouts', 'BasicLayout'], file];
}

View File

@ -1,22 +0,0 @@
import ResultFile from '../../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'menuConfig',
'js',
`
const headerMenuConfig = [];
const asideMenuConfig = [
{
name: 'Dashboard',
path: '/',
icon: 'smile',
},
];
export { headerMenuConfig, asideMenuConfig };
`,
);
return [['src', 'layouts', 'BasicLayout'], file];
}

View File

@ -1,20 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'.stylelintignore',
'',
`
#
build/
tests/
demo/
# node
coverage/
`,
);
return [[], file];
}

View File

@ -1,16 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'.stylelintrc',
'js',
`
const { stylelint } = require('@ice/spec');
module.exports = stylelint;
`,
);
return [[], file];
}

View File

@ -1,46 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'tsconfig',
'json',
`
{
"compileOnSave": false,
"buildOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"outDir": "build",
"module": "esnext",
"target": "es6",
"jsx": "react",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"lib": ["es6", "dom"],
"sourceMap": true,
"allowJs": true,
"rootDir": "./",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": false,
"importHelpers": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./src/*"],
"ice": [".ice/index.ts"],
"ice/*": [".ice/pages/*"]
}
},
"include": ["src/*", ".ice"],
"exclude": ["node_modules", "build", "public"]
}
`,
);
return [[], file];
}

View File

@ -1,99 +0,0 @@
import ResultDir from '../../../../../model/ResultDir';
import {
IProjectTemplate,
IResultDir,
} from '../../../../../types';
import { runFileGenerator } from '../../../../../utils/templateHelper';
import file12 from './files/abc.json';
import file11 from './files/build.json';
import file10 from './files/editorconfig';
import file9 from './files/eslintignore';
import file8 from './files/eslintrc.js';
import file7 from './files/gitignore';
import file6 from './files/jsconfig.json';
import file5 from './files/prettierignore';
import file4 from './files/prettierrc.js';
import file13 from './files/README.md';
import file16 from './files/src/layouts/BasicLayout/components/Footer/index.jsx';
import file17 from './files/src/layouts/BasicLayout/components/Footer/index.module.scss';
import file18 from './files/src/layouts/BasicLayout/components/Logo/index.jsx';
import file19 from './files/src/layouts/BasicLayout/components/Logo/index.module.scss';
import file20 from './files/src/layouts/BasicLayout/components/PageNav/index.jsx';
import file14 from './files/src/layouts/BasicLayout/index.jsx';
import file15 from './files/src/layouts/BasicLayout/menuConfig.js';
import file3 from './files/stylelintignore';
import file2 from './files/stylelintrc.js';
import file1 from './files/tsconfig.json';
const icejsTemplate: IProjectTemplate = {
slots: {
components: {
path: ['src', 'components'],
},
pages: {
path: ['src', 'pages'],
},
router: {
path: ['src'],
fileName: 'routes',
},
entry: {
path: ['src'],
fileName: 'app',
},
constants: {
path: ['src'],
fileName: 'constants',
},
utils: {
path: ['src'],
fileName: 'utils',
},
i18n: {
path: ['src'],
fileName: 'i18n',
},
globalStyle: {
path: ['src'],
fileName: 'global',
},
htmlEntry: {
path: ['public'],
fileName: 'index',
},
packageJSON: {
path: [],
fileName: 'package',
},
},
generateTemplate(): IResultDir {
const root = new ResultDir('.');
runFileGenerator(root, file1);
runFileGenerator(root, file2);
runFileGenerator(root, file3);
runFileGenerator(root, file4);
runFileGenerator(root, file5);
runFileGenerator(root, file6);
runFileGenerator(root, file7);
runFileGenerator(root, file8);
runFileGenerator(root, file9);
runFileGenerator(root, file10);
runFileGenerator(root, file11);
runFileGenerator(root, file12);
runFileGenerator(root, file13);
runFileGenerator(root, file14);
runFileGenerator(root, file15);
runFileGenerator(root, file16);
runFileGenerator(root, file17);
runFileGenerator(root, file18);
runFileGenerator(root, file19);
runFileGenerator(root, file20);
return root;
},
};
export default icejsTemplate;

View File

@ -1,32 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'.editorconfig',
'',
`
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Tab indentation
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
`,
);
return [[], file];
}

View File

@ -1,26 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'.eslintignore',
'',
`
.idea
.vscode
.theia
.recore
build/
.*
~*
node_modules
packages/solution
`,
);
return [[], file];
}

View File

@ -1,57 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'.gitignore',
'',
`
node_modules/
coverage/
build/
dist/
.idea/
.vscode/
.theia/
.recore/
.Trash-*/
~*
package-lock.json
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Logs and databases #
######################
*.log
*.sql
*.sqlite
# OS generated files #
######################
.DS_Store
*.swp
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
`,
);
return [[], file];
}

View File

@ -1,22 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'.prettierrc',
'',
`
{
"semi": true,
"singleQuote": true,
"printWidth": 120,
"trailingComma": "all"
}
`,
);
return [[], file];
}

View File

@ -1,35 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'README',
'md',
`
# runtime-code
##
\`\`\`bash
# install dependencies
tnpm install
# serve with hot reload at localhost:8080
npm start
# test projects
npm test
# local build
npm run build
\`\`\`
`,
);
return [[], file];
}

View File

@ -1,27 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'abc',
'json',
`
{
"name": "test",
"assets": {
"type": "command",
"command": {
"cmd": [
"tnpm ii",
"tnpm run build"
]
}
}
}
`,
);
return [[], file];
}

View File

@ -1,31 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'build',
'json',
`
{
"entry": "src/index",
"alias": {
"@": "./src"
},
"publicPath": "./",
"outputAssetsPath": {
"js": "",
"css": ""
},
"plugins": [
"build-plugin-react-app",
"@ali/build-plugin-recore-lowcode"
],
"externals": { "react": "window.React", "react-dom": "window.ReactDOM", "@ali/recore": "window.Recore" }
}
`,
);
return [[], file];
}

View File

@ -1,65 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'package',
'json',
`
{
"name": "test",
"version": "1.0.0",
"description": "test",
"scripts": {
"start": "build-scripts start",
"build": "build-scripts build",
"test": "build-scripts test"
},
"engines": {
"node": ">= 8.9.0",
"npm": ">=6.1.0"
},
"dependencies": {
"@ali/lowcode-runtime": "^0.8.0",
"@ali/recore": "^1.6.10",
"@ali/recore-renderer": "^0.0.3",
"@ali/vc-block": "^3.0.3-beta.1",
"@ali/vc-deep": "1.2.38",
"@ali/vc-div": "^1.0.1",
"@ali/vc-page": "^1.0.5",
"@ali/vc-shell": "1.3.1",
"@ali/vc-slot": "^2.0.1",
"@ali/vc-text": "^4.0.1",
"@ali/vu-dataSource": "^1.0.4",
"@ali/vu-formatter": "^2.0.0",
"@ali/vu-fusion": "^2.0.1-beta.0",
"@ali/vu-legao-builtin": "^1.4.0-beta.2",
"@ali/vu-toolkit": "^1.0.5",
"react": "^16"
},
"devDependencies": {
"@ali/build-plugin-recore-lowcode": "^0.0.3",
"@ali/recore-lowcode-loader": "^0.0.4",
"@alib/build-scripts": "^0.1.0",
"@types/node": "^7",
"@types/react": "^16",
"build-plugin-react-app": "^1.0.15",
"eslint": "^6.5.1",
"prettier": "^1.18.2",
"tslib": "^1.9.3",
"typescript": "^3.1.3"
},
"lint-staged": {
"./src/**/*.{ts,tsx}": [
"tslint --fix",
"git add"
]
}
}
`,
);
return [[], file];
}

View File

@ -1,50 +0,0 @@
import ResultFile from '../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'index',
'html',
`
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, maximum-scale=1.0, user-scalable=no" />
<title>lowcode-runtime-test</title>
<link rel="shortcut icon" type="image/png" href="https://img.alicdn.com/tfs/TB1zgoCemrqK1RjSZK9XXXyypXa-96-96.png" />
<link rel="stylesheet" id="" href="//g.alicdn.com/legao-comp/csxs/1.0.2/web.css?t=1f">
<script
src="https://g.alicdn.com/code/lib/??react/16.9.0/umd/react.production.min.js,react-dom/16.9.0/umd/react-dom.production.min.js,prop-types/15.7.2/prop-types.js"></script>
<!-- React 非压缩版代码,可根据需要替换或通过代理替换后方便调试 -->
<!-- <script src="https://g.alicdn.com/code/lib/??react/16.9.0/umd/react.development.js,react-dom/16.9.0/umd/react-dom.development.js,prop-types/15.7.2/prop-types.js"></script> -->
<script src="https://g.alicdn.com/mylib/@ali/recore/1.6.8/umd/recore.min.js"></script>
<script>
React.PropTypes = PropTypes;
</script>
<style type="text/css">
body {
-webkit-overflow-scrolling: touch;
}
</style>
</head>
<body>
<script>
window.g_config = {
appKey: 'test', // 乐高应用的 AppKey
// isSectionalRender: true, // 必填,标记当前为局部使用
// autoRender: true,
// index: 'search_form',
};
</script>
</body>
</html>
`,
);
return [['public'], file];
}

View File

@ -1,76 +0,0 @@
import ResultFile from '../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'app',
'ts',
`
export default {
"sdkVersion": "1.0.3",
"history": "hash", // 浏览器路由brower 哈希路由hash
"containerId": "app",
"layout": {
"componentName": "BasicLayout",
"props": {
"navConfig": {
"showLanguageChange": true,
"data": [
{
"hidden": false,
"navUuid": "FORM-CP5669B1-3AW9DCLHZAY8EIY6WE6X1-GFZM3V1K-6",
"children": [],
"icon": "",
"targetNew": false,
"title": "测试基础表格",
"inner": true,
"relateUuid": "FORM-CP5669B1-3AW9DCLHZAY8EIY6WE6X1-GFZM3V1K-6",
"slug": "qihfg"
},
{
"hidden": false,
"navUuid": "FORM-CP5669B1-8AW9XCUT4PCH15SMDWUM3-ZPQP3V1K-1",
"children": [],
"icon": "",
"targetNew": false,
"title": "测试查询表格",
"inner": true,
"relateUuid": "zqhej",
"slug": "zqhej"
}
],
"systemLink": "/my_dev_center_code/0.1.0",
"appName": "乐高转码demo",
"isFoldHorizontal": "n",
"showAppTitle": true,
"isFold": "n",
"searchBarType": "icon",
"singletons": {},
"navTheme": "default",
"type": "top_side_fold",
"navStyle": "orange",
"layout": "auto",
"bgColor": "white",
"languageChangeUrl": "/common/account/changeAccountLanguage.json",
"showSearch": "n",
"openSubMode": false,
"showCrumb": true,
"isFixed": "y",
"showIcon": false,
"showNav": true
}
},
},
"theme": {
"package": "@alife/theme-fusion",
"version": "^0.1.0"
},
"compDependencies": []
}
`,
);
return [['src', 'config'], file];
}

View File

@ -1,42 +0,0 @@
import ResultFile from '../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'components',
'ts',
`
/**
*
*/
import Div from '@ali/vc-div/build/view';
import Text from '@ali/vc-text/build/view';
import Slot from '@ali/vc-slot/build/view';
import Deep from '@ali/vc-deep/build/view';
import Page from '@ali/vc-page/build/view';
import Block from '@ali/vc-block/build/view';
const components = [Div, Text, Slot, Deep, Page, Block];
const componentsMap = {
};
const processComponents = (deps) => {
deps.forEach((dep) => {
if (Array.isArray(dep)) {
processComponents(dep);
} else {
componentsMap[dep.displayName] = dep;
}
});
};
processComponents(components);
export default componentsMap;
`,
);
return [['src', 'config'], file];
}

View File

@ -1,28 +0,0 @@
import ResultFile from '../../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'utils',
'ts',
`
import toolkit from '@ali/vu-toolkit';
import fusion from '@ali/vu-fusion';
import dataSource from '@ali/vu-dataSource';
import legaoBuiltin from '@ali/vu-legao-builtin';
import formatter from '@ali/vu-formatter';
export default {
...toolkit,
...fusion,
legaoBuiltin,
dataSource,
formatter
}
`,
);
return [['src', 'config'], file];
}

View File

@ -1,100 +0,0 @@
import ResultFile from '../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'index',
'ts',
`
import { app } from '@ali/lowcode-runtime';
import { ReactProvider } from '@ali/lowcode-runtime';
import Shell from '@ali/vc-shell';
import StaticRender from './plugins/provider';
import Router from '@/router';
import appConfig from '@/config/app';
import components from '@/config/components';
import utils from '@/config/utils';
// 定制加载应用配置的逻辑
class StaticRender extends ReactProvider {
// 初始化时调用如可以在这里注入全局API
init() {
const gConfig = (window as any).g_config || {};
const LeGao = {
__ctx__: {},
createContext: (cfg: any) => {
const { schema } = cfg || {};
// 1. 根据参数拉取schema
if (schema && typeof schema === 'string') {
this.setHomePage(schema);
}
const { isSectionalRender, autoRender } = gConfig || {};
if (isSectionalRender && !autoRender) {
// 2. 渲染
this.setSectionalRender();
this.ready();
}
const provider = this;
class Context {
get utils() {
return provider.getUtils();
}
get components() {
return provider.getComponents();
}
}
const ctx = new Context();
(LeGao.__ctx__ as any)[this.getContainerId()] = ctx;
return ctx;
},
getContext: (id: string) => {
if (!id) {
for (id in LeGao.__ctx__) {
return (LeGao.__ctx__ as any)[id];
}
}
return (LeGao.__ctx__ as any)[id];
}
};
(window as any).LeGao = LeGao;
if (gConfig.index) {
this.setHomePage(gConfig.index);
}
if (gConfig.isSectionalRender) {
this.setSectionalRender();
if (!gConfig.autoRender) {
return;
}
}
this.ready();
}
// 定制获取、处理应用配置(组件、插件、路由模式、布局等)的逻辑
getAppData() {
return {
...appConfig,
components,
utils: utils,
}
}
getRouterView() {
return Router;
}
}
// 注册布局组件,可注册多个
app.registerLayout(Shell, {
componentName: 'BasicLayout',
});
app.registerProvider(StaticRender);
app.run();
`,
);
return [['src'], file];
}

View File

@ -1,21 +0,0 @@
import ResultFile from '../../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'router',
'ts',
`
export default {
baseDir: './pages',
exact: true,
routes: [
{ main: './page_index', path: '/' },
],
};
`,
);
return [['src'], file];
}

View File

@ -1,52 +0,0 @@
import ResultFile from '../../../../../../model/ResultFile';
import { IResultFile } from '../../../../../../types';
export default function getFile(): [string[], IResultFile] {
const file = new ResultFile(
'tsconfig',
'json',
`
{
"compilerOptions": {
"lib": ["es2015", "dom"],
// Target latest version of ECMAScript.
"target": "esnext",
// Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'.
"module": "esnext",
// Search under node_modules for non-relative imports.
"moduleResolution": "node",
// Process & infer types from .js files.
"allowJs": true,
// Report errors in .js files.
"checkJs": false,
// Don't emit; allow Babel to transform files.
"noEmit": true,
// Enable strictest settings like strictNullChecks & noImplicitAny.
"strict": true,
// Allow default imports from modules with no default export. This does not affect code emit, just typechecking.
"allowSyntheticDefaultImports": true,
// Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'.
"esModuleInterop": true,
// Specify JSX code generation: 'preserve', 'react-native', or 'react'.
"jsx": "preserve",
// Import emit helpers (e.g. __extends, __rest, etc..) from tslib
"importHelpers": true,
// Enables experimental support for ES7 decorators.
"experimentalDecorators": true,
// Generates corresponding .map file.
"sourceMap": true,
// Disallow inconsistently-cased references to the same file.
"forceConsistentCasingInFileNames": true,
// Allow json import
"resolveJsonModule": true,
// skip type checking of declaration files
"skipLibCheck": true,
}
}
`,
);
return [[], file];
}

View File

@ -1,54 +0,0 @@
import ResultDir from '../../../../../model/ResultDir';
import {
IProjectTemplate,
IResultDir,
} from '../../../../../types';
import { runFileGenerator } from '../../../../../utils/templateHelper';
import file1 from './files/abc.json';
import file2 from './files/build.json';
import file3 from './files/.editorconfig';
import file4 from './files/.eslintignore';
import file5 from './files/.gitignore';
import file6 from './files/.prettierrc';
import file7 from './files/README.md';
import file8 from './files/package.json';
import file9 from './files/public/index.html';
import file10 from './files/src/index.ts';
import file11 from './files/src/router.ts';
import file13 from './files/src/config/app.ts';
import file14 from './files/src/config/components.ts';
import file15 from './files/src/config/utils.ts';
import file16 from './files/tsconfig.json';
const icejsTemplate: IProjectTemplate = {
slots: {
pages: {
path: ['src', 'pages'],
},
},
generateTemplate(): IResultDir {
const root = new ResultDir('.');
runFileGenerator(root, file1);
runFileGenerator(root, file2);
runFileGenerator(root, file3);
runFileGenerator(root, file4);
runFileGenerator(root, file5);
runFileGenerator(root, file6);
runFileGenerator(root, file7);
runFileGenerator(root, file8);
runFileGenerator(root, file9);
runFileGenerator(root, file10);
runFileGenerator(root, file11);
runFileGenerator(root, file13);
runFileGenerator(root, file14);
runFileGenerator(root, file15);
runFileGenerator(root, file16);
return root;
},
};
export default icejsTemplate;

View File

@ -1,69 +0,0 @@
import { COMMON_CHUNK_NAME } from '../../const/generator';
import { generateCompositeType } from '../../utils/compositeType';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IProjectInfo,
} from '../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IProjectInfo;
if (ir.i18n) {
const i18nStr = generateCompositeType(ir.i18n);
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JS,
name: COMMON_CHUNK_NAME.FileMainContent,
content: `
const i18nConfig = ${i18nStr};
let locale = 'en_US';
const changeLocale = (target) => {
locale = target;
};
const i18n = key => i18nConfig && i18nConfig[locale] && i18nConfig[locale][key] || '';
`,
linkAfter: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileVarDefine,
COMMON_CHUNK_NAME.FileUtilDefine,
],
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JS,
name: COMMON_CHUNK_NAME.FileExport,
content: `
export {
changeLocale,
i18n,
};
`,
linkAfter: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileVarDefine,
COMMON_CHUNK_NAME.FileUtilDefine,
COMMON_CHUNK_NAME.FileMainContent,
],
});
}
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,92 +0,0 @@
import { COMMON_CHUNK_NAME } from '../../const/generator';
import {
BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType,
FileType,
ICodeStruct,
IUtilInfo,
} from '../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
};
const ir = next.ir as IUtilInfo;
if (ir.utils) {
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JS,
name: COMMON_CHUNK_NAME.FileExport,
content: `
export default {
`,
linkAfter: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileVarDefine,
COMMON_CHUNK_NAME.FileUtilDefine,
COMMON_CHUNK_NAME.FileMainContent,
],
});
ir.utils.forEach(util => {
if (util.type === 'function') {
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JS,
name: COMMON_CHUNK_NAME.FileVarDefine,
content: `
const ${util.name} = ${util.content};
`,
linkAfter: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
],
});
}
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JS,
name: COMMON_CHUNK_NAME.FileExport,
content: `
${util.name},
`,
linkAfter: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileVarDefine,
COMMON_CHUNK_NAME.FileUtilDefine,
COMMON_CHUNK_NAME.FileMainContent,
],
});
});
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JS,
name: COMMON_CHUNK_NAME.FileExport,
content: `
};
`,
linkAfter: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
COMMON_CHUNK_NAME.FileVarDefine,
COMMON_CHUNK_NAME.FileUtilDefine,
COMMON_CHUNK_NAME.FileMainContent,
],
});
}
return next;
};
return plugin;
};
export default pluginFactory;

View File

@ -1,3 +0,0 @@
import prettier from './prettier';
export { prettier };

View File

@ -1,42 +0,0 @@
import prettier from 'prettier';
import mypretter from '@ali/my-prettier';
import { PostProcessor, PostProcessorFactory } from '../../types';
const PARSERS = ['css', 'scss', 'less', 'json', 'html', 'vue'];
type ProcessorConfig = {
customFileTypeParser: Record<string, string>;
};
const factory: PostProcessorFactory<ProcessorConfig> = (config?: ProcessorConfig) => {
const cfg: ProcessorConfig = {
customFileTypeParser: {},
...config,
};
const codePrettier: PostProcessor = (content: string, fileType: string) => {
let parser: prettier.BuiltInParserName;
if (fileType === 'js' || fileType === 'jsx') {
parser = 'babel';
} else if (fileType === 'ts' || fileType === 'tsx') {
parser = 'typescript';
} else if (PARSERS.indexOf(fileType) >= 0) {
parser = fileType as prettier.BuiltInParserName;
} else if (cfg.customFileTypeParser[fileType]) {
parser = cfg.customFileTypeParser[fileType] as prettier.BuiltInParserName;
} else if (fileType === 'vx') {
return mypretter(content, fileType);
} else {
return content;
}
return prettier.format(content, {
parser,
});
};
return codePrettier;
};
export default factory;

View File

@ -1,78 +0,0 @@
import {
IResultDir,
PublisherFactory,
IPublisher,
IPublisherFactoryParams,
PublisherError,
} from '../../types';
import { writeFolder } from './utils';
export interface IDiskFactoryParams extends IPublisherFactoryParams {
outputPath?: string;
projectSlug?: string;
createProjectFolder?: boolean;
}
export interface IDiskPublisher extends IPublisher<IDiskFactoryParams, string> {
getOutputPath: () => string;
setOutputPath: (path: string) => void;
}
export const createDiskPublisher: PublisherFactory<
IDiskFactoryParams,
IDiskPublisher
> = (params: IDiskFactoryParams = {}): IDiskPublisher => {
let { project, outputPath = './' } = params;
const getProject = (): IResultDir => {
if (!project) {
throw new PublisherError('Missing Project');
}
return project;
};
const setProject = (projectToSet: IResultDir): void => {
project = projectToSet;
};
const getOutputPath = (): string => {
return outputPath;
};
const setOutputPath = (path: string): void => {
outputPath = path;
};
const publish = async (options: IDiskFactoryParams = {}) => {
const projectToPublish = options.project || project;
if (!projectToPublish) {
throw new PublisherError('Missing Project');
}
const projectOutputPath = options.outputPath || outputPath;
const overrideProjectSlug = options.projectSlug || params.projectSlug;
const createProjectFolder =
options.createProjectFolder || params.createProjectFolder;
if (overrideProjectSlug) {
projectToPublish.name = overrideProjectSlug;
}
try {
await writeFolder(
projectToPublish,
projectOutputPath,
createProjectFolder,
);
return { success: true, payload: projectOutputPath };
} catch (error) {
throw new PublisherError(error);
}
};
return {
publish,
getProject,
setProject,
getOutputPath,
setOutputPath,
};
};

View File

@ -1,71 +0,0 @@
import { existsSync, mkdir, writeFile } from 'fs';
import { join } from 'path';
import { IResultDir, IResultFile } from '../../types';
export const writeFolder = async (
folder: IResultDir,
currentPath: string,
createProjectFolder = true,
): Promise<void> => {
const { name, files, dirs } = folder;
const folderPath = createProjectFolder
? join(currentPath, name)
: currentPath;
if (!existsSync(folderPath)) {
await createDirectory(folderPath);
}
const promises = [
writeFilesToFolder(folderPath, files),
writeSubFoldersToFolder(folderPath, dirs),
];
await Promise.all(promises);
};
const writeFilesToFolder = async (
folderPath: string,
files: IResultFile[],
): Promise<void> => {
const promises = files.map(file => {
const fileName = file.ext ? `${file.name}.${file.ext}` : file.name;
const filePath = join(folderPath, fileName);
return writeContentToFile(filePath, file.content);
});
await Promise.all(promises);
};
const writeSubFoldersToFolder = async (
folderPath: string,
subFolders: IResultDir[],
): Promise<void> => {
const promises = subFolders.map(subFolder => {
return writeFolder(subFolder, folderPath);
});
await Promise.all(promises);
};
const createDirectory = (pathToDir: string): Promise<void> => {
return new Promise((resolve, reject) => {
mkdir(pathToDir, { recursive: true }, err => {
err ? reject(err) : resolve();
});
});
};
const writeContentToFile = (
filePath: string,
fileContent: string,
encoding = 'utf8',
): Promise<void> => {
return new Promise((resolve, reject) => {
writeFile(filePath, fileContent, encoding, err => {
err ? reject(err) : resolve();
});
});
};

View File

@ -1,69 +0,0 @@
import {
IResultDir,
PublisherFactory,
IPublisher,
IPublisherFactoryParams,
PublisherError,
} from '../../types';
import { isNodeProcess, writeZipToDisk, generateProjectZip } from './utils';
// export type ZipBuffer = Buffer | Blob;
export type ZipBuffer = Buffer;
declare type ZipPublisherResponse = string | ZipBuffer;
export interface ZipFactoryParams extends IPublisherFactoryParams {
outputPath?: string;
projectSlug?: string;
}
export interface ZipPublisher extends IPublisher<ZipFactoryParams, ZipPublisherResponse> {
getOutputPath: () => string | undefined;
setOutputPath: (path: string) => void;
}
export const createZipPublisher: PublisherFactory<ZipFactoryParams, ZipPublisher> = (
params: ZipFactoryParams = {},
): ZipPublisher => {
let { project, outputPath } = params;
const getProject = () => project;
const setProject = (projectToSet: IResultDir) => {
project = projectToSet;
};
const getOutputPath = () => outputPath;
const setOutputPath = (path: string) => {
outputPath = path;
};
const publish = async (options: ZipFactoryParams = {}) => {
const projectToPublish = options.project || project;
if (!projectToPublish) {
throw new PublisherError('MissingProject');
}
const zipName = options.projectSlug || params.projectSlug || projectToPublish.name;
try {
const zipContent = await generateProjectZip(projectToPublish);
// If not output path is provided, zip is not written to disk
const projectOutputPath = options.outputPath || outputPath;
if (projectOutputPath && isNodeProcess()) {
await writeZipToDisk(projectOutputPath, zipContent, zipName);
}
return { success: true, payload: zipContent };
} catch (error) {
throw new PublisherError(error);
}
};
return {
publish,
getProject,
setProject,
getOutputPath,
setOutputPath,
};
};

View File

@ -1,60 +0,0 @@
import JSZip from 'jszip';
import { IResultDir, IResultFile } from '../../types';
import { ZipBuffer } from './index';
export const isNodeProcess = (): boolean => {
return (
typeof process === 'object' &&
typeof process.versions === 'object' &&
typeof process.versions.node !== 'undefined'
);
};
export const writeZipToDisk = (
zipFolderPath: string,
content: ZipBuffer,
zipName: string,
): void => {
const fs = require('fs');
const path = require('path');
if (!fs.existsSync(zipFolderPath)) {
fs.mkdirSync(zipFolderPath, { recursive: true });
}
const zipPath = path.join(zipFolderPath, `${zipName}.zip`);
const writeStream = fs.createWriteStream(zipPath);
writeStream.write(content);
writeStream.end();
};
export const generateProjectZip = async (project: IResultDir): Promise<ZipBuffer> => {
let zip = new JSZip();
zip = writeFolderToZip(project, zip, true);
// const zipType = isNodeProcess() ? 'nodebuffer' : 'blob';
const zipType = 'nodebuffer'; // 目前先只支持 node 调用
return zip.generateAsync({ type: zipType });
};
const writeFolderToZip = (
folder: IResultDir,
parentFolder: JSZip,
ignoreFolder = false,
) => {
const zipFolder = ignoreFolder ? parentFolder : parentFolder.folder(folder.name);
if (zipFolder !== null) {
folder.files.forEach((file: IResultFile) => {
// const options = file.contentEncoding === 'base64' ? { base64: true } : {};
const options = {};
const fileName = file.ext ? `${file.name}.${file.ext}` : file.name;
zipFolder.file(fileName, file.content, options);
});
folder.dirs.forEach((subFolder: IResultDir) => {
writeFolderToZip(subFolder, zipFolder);
});
}
return parentFolder;
};

View File

@ -1,78 +0,0 @@
import { IProjectBuilder } from '../types';
import { createProjectBuilder } from '../generator/ProjectBuilder';
import esmodule from '../plugins/common/esmodule';
import containerClass from '../plugins/component/react/containerClass';
import containerInitState from '../plugins/component/react/containerInitState';
// import containerInjectUtils from '../plugins/component/react/containerInjectUtils';
import containerLifeCycle from '../plugins/component/react/containerLifeCycle';
import containerMethod from '../plugins/component/react/containerMethod';
import jsx from '../plugins/component/react/jsx';
import reactCommonDeps from '../plugins/component/react/reactCommonDeps';
import css from '../plugins/component/style/css';
import constants from '../plugins/project/constants';
import i18n from '../plugins/project/i18n';
import utils from '../plugins/project/utils';
import icejs from '../plugins/project/framework/icejs';
import { prettier } from '../postprocessor';
export default function createIceJsProjectBuilder(): IProjectBuilder {
return createProjectBuilder({
template: icejs.template,
plugins: {
components: [
reactCommonDeps(),
esmodule({
fileType: 'jsx',
}),
containerClass(),
// containerInjectUtils(),
containerInitState(),
containerLifeCycle(),
containerMethod(),
jsx({
nodeTypeMapping: {
Div: 'div',
Component: 'div',
Page: 'div',
Block: 'div',
},
}),
css(),
],
pages: [
reactCommonDeps(),
esmodule({
fileType: 'jsx',
}),
containerClass(),
// containerInjectUtils(),
containerInitState(),
containerLifeCycle(),
containerMethod(),
jsx({
nodeTypeMapping: {
Div: 'div',
Component: 'div',
Page: 'div',
Block: 'div',
// Box: 'div',
},
}),
css(),
],
router: [esmodule(), icejs.plugins.router()],
entry: [icejs.plugins.entry()],
constants: [constants()],
utils: [esmodule(), utils()],
i18n: [i18n()],
globalStyle: [icejs.plugins.globalStyle()],
htmlEntry: [icejs.plugins.entryHtml()],
packageJSON: [icejs.plugins.packageJSON()],
},
postProcessors: [prettier()], // prettier()
});
}

View File

@ -1,51 +0,0 @@
import { IProjectBuilder } from '../types';
import { createProjectBuilder } from '../generator/ProjectBuilder';
// import esmodule from '../plugins/common/esmodule';
import containerInitState from '../plugins/component/react/containerInitState';
import containerLifeCycle from '../plugins/component/react/containerLifeCycle';
import containerMethod from '../plugins/component/react/containerMethod';
import pageFrame from '../plugins/component/recore/pageFrame';
import pageStyle from '../plugins/component/recore/pageStyle';
import pageVmHeader from '../plugins/component/recore/pageVmHeader';
import pageVmBody from '../plugins/component/recore/pageVmBody';
import pageDataSource from '../plugins/component/recore/pageDataSource';
import template from '../plugins/project/framework/recore/template';
import { prettier } from '../postprocessor';
export default function createRecoreProjectBuilder(): IProjectBuilder {
return createProjectBuilder({
template,
plugins: {
pages: [
pageFrame(),
pageStyle(),
containerInitState({
fileType: 'ts',
implementType: 'insMember',
}),
containerLifeCycle({
fileType: 'ts',
exportNameMapping: {
constructor: 'init',
componentDidMount: 'didMount',
willUnmount: 'willUnMount',
componentWillUnmount: 'willUnMount',
},
normalizeNameMapping: {
init: 'constructor',
},
}),
containerMethod({
fileType: 'ts',
}),
pageDataSource(),
pageVmHeader(),
pageVmBody(),
],
},
postProcessors: [prettier()],
});
}

View File

@ -1,201 +0,0 @@
import {
IBasicSchema,
IParseResult,
IProjectSchema,
IResultDir,
IResultFile,
IComponentNodeItem,
IJSExpression,
} from './index';
export enum FileType {
CSS = 'css',
SCSS = 'scss',
HTML = 'html',
JS = 'js',
JSX = 'jsx',
TS = 'ts',
TSX = 'tsx',
JSON = 'json',
}
export enum ChunkType {
AST = 'ast',
STRING = 'string',
JSON = 'json',
}
export enum PluginType {
COMPONENT = 'component',
UTILS = 'utils',
I18N = 'i18n',
}
export type ChunkContent = string | any;
export type CodeGeneratorFunction<T> = (content: T) => string;
export interface ICodeChunk {
type: ChunkType;
fileType: string;
name: string;
subModule?: string;
content: ChunkContent;
linkAfter: string[];
}
export interface IBaseCodeStruct {
chunks: ICodeChunk[];
depNames: string[];
}
export interface ICodeStruct extends IBaseCodeStruct {
ir: any;
chunks: ICodeChunk[];
}
export type BuilderComponentPlugin = (initStruct: ICodeStruct) => Promise<ICodeStruct>;
export type BuilderComponentPluginFactory<T> = (config?: T) => BuilderComponentPlugin;
export interface IChunkBuilder {
run(ir: any, initialStructure?: ICodeStruct): Promise<{ chunks: ICodeChunk[][] }>;
getPlugins(): BuilderComponentPlugin[];
addPlugin(plugin: BuilderComponentPlugin): void;
}
export interface ICodeBuilder {
link(chunkDefinitions: ICodeChunk[]): string;
generateByType(type: string, content: unknown): string;
}
export interface ICompiledModule {
files: IResultFile[];
}
export interface IModuleBuilder {
generateModule(input: unknown): Promise<ICompiledModule>;
generateModuleCode(schema: IBasicSchema | string): Promise<IResultDir>;
linkCodeChunks(chunks: Record<string, ICodeChunk[]>, fileName: string): IResultFile[];
addPlugin(plugin: BuilderComponentPlugin): void;
}
/**
*
*
* @export
* @interface ICodeGenerator
*/
export interface ICodeGenerator {
/**
* Schema
*
* @param {(IBasicSchema)} schema Schema
* @returns {IResultDir}
* @memberof ICodeGenerator
*/
toCode(schema: IBasicSchema): Promise<IResultDir>;
}
export interface ISchemaParser {
validate(schema: IBasicSchema): boolean;
parse(schema: IBasicSchema | string): IParseResult;
}
export interface IProjectTemplate {
slots: Record<string, IProjectSlot>;
generateTemplate(): IResultDir;
}
export interface IProjectSlot {
path: string[];
fileName?: string;
}
// export interface IProjectSlots {
// components: IProjectSlot;
// pages: IProjectSlot;
// router: IProjectSlot;
// entry: IProjectSlot;
// constants?: IProjectSlot;
// utils?: IProjectSlot;
// i18n?: IProjectSlot;
// globalStyle: IProjectSlot;
// htmlEntry: IProjectSlot;
// packageJSON: IProjectSlot;
// }
export interface IProjectPlugins {
[slotName: string]: BuilderComponentPlugin[];
}
export interface IProjectBuilder {
generateProject(schema: IProjectSchema | string): Promise<IResultDir>;
}
export type PostProcessorFactory<T> = (config?: T) => PostProcessor;
export type PostProcessor = (content: string, fileType: string) => string;
// TODO: temp interface, need modify
export interface IPluginOptions {
fileDirDepth: number;
}
export enum PIECE_TYPE {
BEFORE = 'NodeCodePieceBefore',
TAG = 'NodeCodePieceTag',
ATTR = 'NodeCodePieceAttr',
CHILDREN = 'NodeCodePieceChildren',
AFTER = 'NodeCodePieceAfter',
}
export interface CodePiece {
value: string;
type: PIECE_TYPE;
}
export interface HandlerSet<T> {
string?: (input: string) => T[];
expression?: (input: IJSExpression) => T[];
node?: (input: IComponentNodeItem) => T[];
common?: (input: unknown) => T[];
}
export type ExtGeneratorPlugin = (ctx: INodeGeneratorContext, nodeItem: IComponentNodeItem) => CodePiece[];
export interface INodeGeneratorConfig {
nodeTypeMapping?: Record<string, string>;
}
export type NodeGenerator = (nodeItem: IComponentNodeItem) => string;
export interface INodeGeneratorContext {
generator: NodeGenerator;
}
// export interface InteratorScope {
// [$item: string]: string; // $item 默认取值 "item"
// [$index: string]: string | number; // $index 默认取值 "index"
// __proto__: BlockInstance;
// }
export type CompositeValueCustomHandler = (data: unknown) => string;
export type CompositeTypeContainerHandler = (value: string) => string;
export interface CompositeValueCustomHandlerSet {
boolean?: CompositeValueCustomHandler;
number?: CompositeValueCustomHandler;
string?: CompositeValueCustomHandler;
array?: CompositeValueCustomHandler;
object?: CompositeValueCustomHandler;
expression?: CompositeValueCustomHandler;
}
export interface CompositeTypeContainerHandlerSet {
default?: CompositeTypeContainerHandler;
string?: CompositeValueCustomHandler;
}
export interface CompositeValueGeneratorOptions {
handlers?: CompositeValueCustomHandlerSet;
containerHandlers?: CompositeTypeContainerHandlerSet;
nodeGenerator?: NodeGenerator;
}

View File

@ -1,38 +0,0 @@
export interface INpmPackage {
package: string; // 组件包的名称
version: string; // 组件包的版本
}
/**
*
*
* @export
* @interface IExternalDependency
*/
export interface IExternalDependency extends INpmPackage, IDependency {}
export enum InternalDependencyType {
PAGE = 'pages',
BLOCK = 'components',
COMPONENT = 'components',
UTILS = 'utils',
}
export enum DependencyType {
External = 'External',
Internal = 'Internal',
}
export interface IInternalDependency extends IDependency {
type: InternalDependencyType;
moduleName: string;
}
export interface IDependency {
destructuring: boolean; // 组件是否是解构方式方式导出
exportName: string; // 导出命名
subName?: string; // 下标子组件名称
main?: string; // 包导出组件入口文件路径 /lib/input
dependencyType?: DependencyType; // 依赖类型 内/外
importName?: string; // 导入后名称
}

View File

@ -1,27 +0,0 @@
export class CodeGeneratorError extends Error {
constructor(message: string) {
super(message);
this.name = this.constructor.name;
}
}
// tslint:disable-next-line: max-classes-per-file
export class ComponentValidationError extends CodeGeneratorError {
constructor(errorString: string) {
super(errorString);
}
}
// tslint:disable-next-line: max-classes-per-file
export class CompatibilityError extends CodeGeneratorError {
constructor(errorString: string) {
super(errorString);
}
}
// tslint:disable-next-line: max-classes-per-file
export class PublisherError extends CodeGeneratorError {
constructor(errorString: string) {
super(errorString);
}
}

View File

@ -1,7 +0,0 @@
export * from './core';
export * from './deps';
export * from './error';
export * from './result';
export * from './schema';
export * from './intermediate';
export * from './publisher';

View File

@ -1,66 +0,0 @@
import {
IAppConfig,
IAppMeta,
IContainerNodeItem,
IDependency,
II18nMap,
IInternalDependency,
INpmPackage,
IUtilItem,
} from './index';
export interface IParseResult {
containers: IContainerInfo[];
globalUtils?: IUtilInfo;
globalI18n?: II18nMap;
globalRouter?: IRouterInfo;
project?: IProjectInfo;
}
export interface IContainerInfo extends IContainerNodeItem, IWithDependency {
containerType: string;
moduleName: string;
}
export interface IWithDependency {
deps?: IDependency[];
}
export interface IUtilInfo extends IWithDependency {
utils: IUtilItem[];
}
export interface IRouterInfo extends IWithDependency {
routes: Array<{
path: string;
componentName: string;
}>;
}
export interface IProjectInfo {
config: IAppConfig;
meta: IAppMeta;
css?: string;
constants?: Record<string, string>;
i18n?: II18nMap;
packages: INpmPackage[];
}
/**
* From meta
* page title
* router
* spmb
*
* Utils
*
* constants
*
* i18n
*
* components
*
* pages
*
* layout
*/

View File

@ -1,19 +0,0 @@
import {
IResultDir,
} from './index';
export type PublisherFactory<T, U> = (configuration?: Partial<T>) => U;
export interface IPublisher<T, U> {
publish: (options?: T) => Promise<IPublisherResponse<U>>;
getProject: () => IResultDir | void;
setProject: (project: IResultDir) => void;
}
export interface IPublisherFactoryParams {
project?: IResultDir;
}
export interface IPublisherResponse<T> {
success: boolean;
payload?: T;
}

View File

@ -1,88 +0,0 @@
/**
*
*
* @export
* @interface IResultDir
*/
export interface IResultDir {
/**
* Root .
*
* @type {string}
* @memberof IResultDir
*/
name: string;
/**
*
*
* @type {IResultDir[]}
* @memberof IResultDir
*/
dirs: IResultDir[];
/**
*
*
* @type {IResultFile[]}
* @memberof IResultDir
*/
files: IResultFile[];
/**
*
*
* @param {IResultFile} file
* @memberof IResultDir
*/
addFile(file: IResultFile): void;
/**
*
*
* @param {IResultDir} dir
* @memberof IResultDir
*/
addDirectory(dir: IResultDir): void;
}
/**
*
*
* @export
* @interface IResultFile
*/
export interface IResultFile {
/**
*
*
* @type {string}
* @memberof IResultFile
*/
name: string;
/**
* .js .less
*
* @type {string}
* @memberof IResultFile
*/
ext: string;
/**
*
*
* @type {string}
* @memberof IResultFile
*/
content: string;
}
export interface IPackageJSON {
name: string;
version: string;
description?: string;
dependencies: Record<string, string>;
devDependencies: Record<string, string>;
scripts?: Record<string, string>;
engines?: Record<string, string>;
repository?: {
type: string;
url: string;
};
private?: boolean;
}

View File

@ -1,241 +0,0 @@
// 搭建基础协议、搭建入料协议的数据规范
import { IExternalDependency } from './index';
/**
* -
*
* @export
* @interface IJSExpression
*/
export interface IJSExpression {
type: 'JSExpression';
value: string;
[extConfigName: string]: any;
}
/**
* -
*
* @export
* @interface IJSFunction
*/
export interface IJSFunction {
type: 'JSFunction';
value: string;
[extConfigName: string]: any;
}
/**
* -
*
* @export
* @interface IJSSlot
*/
export interface IJSSlot {
type: 'JSSlot';
value: IComponentNodeItem[];
params?: string[];
[extConfigName: string]: any;
}
// JSON 基本类型
export interface IJSONObject {
[key: string]: JSONValue;
}
export type JSONValue = boolean | string | number | null | JSONArray | IJSONObject;
export type JSONArray = JSONValue[];
export type CompositeArray = CompositeValue[];
export interface ICompositeObject {
[key: string]: CompositeValue;
}
// 复合类型
export type CompositeValue = JSONValue | IJSExpression | IJSFunction | IJSSlot | CompositeArray | ICompositeObject;
/**
* -
*
* @export
* @interface II18nMap
*/
export interface II18nMap {
[lang: string]: {
[key: string]: string;
};
}
/**
*
*
* @export
* @interface IBasicSchema
*/
export interface IBasicSchema {
version: string; // 当前协议版本号
componentsMap: IComponentsMapItem[]; // 组件映射关系
componentsTree: Array<IContainerNodeItem | IComponentNodeItem>; // 描述模版/页面/区块/低代码业务组件的组件树 低代码业务组件树描述固定长度为1且顶层为低代码业务组件容器描述
utils?: IUtilItem[]; // 工具类扩展映射关系 低代码业务组件不包含
i18n?: II18nMap; // 国际化语料
}
export interface IProjectSchema extends IBasicSchema {
constants: Record<string, string>; // 应用范围内的全局常量;
css: string; // 应用范围内的全局样式;
config: IAppConfig; // 当前应用配置信息
meta: IAppMeta; // 当前应用元数据信息
}
/**
* -
*
* @export
* @interface IComponentsMapItem
*/
export interface IComponentsMapItem extends IExternalDependency {
componentName: string; // 组件名称
}
export interface IUtilItem {
name: string;
type: 'npm' | 'tnpm' | 'function';
content: IExternalDependency | IJSExpression;
}
export type ChildNodeItem = string | IJSExpression | IComponentNodeItem;
export type ChildNodeType = ChildNodeItem | ChildNodeItem[];
/**
* -
* .jsx React Class render jsx
*
* @export
* @interface IComponentNodeItem
*/
export interface IComponentNodeItem {
// TODO: 不需要 id 字段,暂时简单兼容
id?: string;
componentName: string; // 组件名称 必填、首字母大写
props: {
[propName: string]: CompositeValue; // 业务属性
}; // 组件属性对象
condition?: CompositeValue; // 渲染条件
loop?: CompositeValue; // 循环数据
loopArgs?: [string, string]; // 循环迭代对象、索引名称 ["item", "index"]
children?: ChildNodeType; // 子节点
}
/**
* -
*
* @export
* @interface IContainerNodeItem
* @extends {IComponentNodeItem}
*/
export interface IContainerNodeItem extends IComponentNodeItem {
componentName: 'Page' | 'Block' | 'Component'; // 'Page' | 'Block' | 'Component' 组件类型 必填、首字母大写
fileName: string; // 文件名称 必填、英文
state?: {
[stateName: string]: CompositeValue; // 容器初始数据
};
css?: string; // 样式文件 用于描述容器组件内部节点的样式,对应生成一个独立的样式文件,在对应容器组件生成的 .jsx 文件中 import 引入;
/**
* LifeCycle
* constructor(props, context)
* state值
* render()
* React Class的render方法最前this对象上props上属性绑定render()return返回值
* componentDidMount()
* componentDidUpdate(prevProps, prevState, snapshot)
* componentWillUnmount()
* componentDidCatch(error, info)
*/
lifeCycles?: Record<string, IJSExpression | IJSFunction>; // 生命周期Hook方法
methods?: Record<string, IJSExpression | IJSFunction>; // 自定义方法设置
dataSource?: {
list: IDataSourceConfig[];
}; // 异步数据源配置
meta?: IBasicMeta | IPageMeta;
}
/**
* -
*
* @export
* @interface IDataSourceConfig
*/
export interface IDataSourceConfig {
id: string; // 数据请求ID标识
isInit: boolean; // 是否为初始数据 支持表达式 值为true时将在组件初始化渲染时自动发送当前数据请求
type: string; // 数据请求类型 'fetch' | 'mtop' | 'jsonp' | 'custom'
requestHandler?: IJSExpression | IJSFunction; // 自定义扩展的外部请求处理器 仅type='custom'时生效
options?: IFetchOptions; // 请求参数配置 每种请求类型对应不同参数
dataHandler?: IJSExpression | IJSFunction; // 数据结果处理函数,形如:(data, err) => Object
}
/**
* -
*
* @export
* @interface IFetchOptions
*/
export interface IFetchOptions {
url: string; // 请求地址 支持表达式
params?: {
// 请求参数
[key: string]: any;
};
method: 'GET' | 'POST';
isCors?: boolean; // 是否支持跨域对应credentials = 'include'
timeout?: number; // 超时时长
headers?: {
// 自定义请求头
[key: string]: string;
};
[extConfigName: string]: any;
}
export interface IBasicMeta {
title: string; // 标题描述
}
export interface IPageMeta extends IBasicMeta {
router: string; // 页面路由
spmb?: string; // spm
}
// "theme": {
// //for Fusion use dpl defined
// "package": "@alife/theme-fusion",
// "version": "^0.1.0",
// //for Antd use variable
// "primary": "#ff9966"
// }
// "layout": {
// "componentName": "BasicLayout",
// "props": {
// "logo": "...",
// "name": "测试网站"
// },
// },
export interface IAppConfig {
sdkVersion: string; // 渲染模块版本
historyMode: 'brower' | 'hash'; // 浏览器路由brower 哈希路由hash
targetRootID: string; // 渲染根节点 ID
layout: IComponentNodeItem;
theme: object; // 主题配置,根据接入的主题模块不同
}
export interface IAppMeta {
name: string; // 应用中文名称
git_group?: string; // 应用对应git分组名
project_name?: string; // 应用对应git的project名称
description?: string; // 应用描述
spma?: string; // 应用spma A位信息
creator?: string; // author
[otherAttrName: string]: any;
}

Some files were not shown because too many files have changed in this diff Show More