Skip to content

Commit 9943b91

Browse files
author
mazhaobo
committed
chore: init modules
1 parent fd83a8e commit 9943b91

File tree

1,444 files changed

+91697
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,444 files changed

+91697
-0
lines changed

modules/code-generator/.gitignore

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# project custom
2+
build
3+
es
4+
dist
5+
output
6+
package-lock.json
7+
yarn.lock
8+
deploy-space/packages
9+
deploy-space/.env
10+
/demo/
11+
/demo-output*/
12+
/generated/
13+
14+
# IDE
15+
.vscode
16+
.idea
17+
18+
# Logs
19+
logs
20+
*.log
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
lerna-debug.log*
25+
26+
# Runtime data
27+
pids
28+
*.pid
29+
*.seed
30+
*.pid.lock
31+
32+
33+
# Directory for instrumented libs generated by jscoverage/JSCover
34+
lib-cov
35+
36+
# Coverage directory used by tools like istanbul
37+
coverage
38+
39+
# nyc test coverage
40+
.nyc_output
41+
42+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
43+
.grunt
44+
45+
# Bower dependency directory (https://bower.io/)
46+
bower_components
47+
48+
# node-waf configuration
49+
.lock-wscript
50+
51+
# Compiled binary addons (https://nodejs.org/api/addons.html)
52+
build/Release
53+
lib
54+
55+
# Dependency directories
56+
node_modules/
57+
jspm_packages/
58+
59+
# TypeScript v1 declaration files
60+
typings/
61+
62+
# Optional npm cache directory
63+
.npm
64+
65+
# Optional eslint cache
66+
.eslintcache
67+
68+
# Optional REPL history
69+
.node_repl_history
70+
71+
# Output of 'npm pack'
72+
*.tgz
73+
74+
# Yarn Integrity file
75+
.yarn-integrity
76+
77+
# dotenv environment variables file
78+
.env
79+
.env.test
80+
81+
# parcel-bundler cache (https://parceljs.org/)
82+
.cache
83+
84+
# next.js build output
85+
.next
86+
87+
# nuxt.js build output
88+
.nuxt
89+
90+
# vuepress build output
91+
.vuepress/dist
92+
93+
# Serverless directories
94+
.serverless/
95+
96+
# FuseBox cache
97+
.fusebox/
98+
99+
# DynamoDB Local files
100+
.dynamodb/
101+
102+
# mac config files
103+
.DS_Store
104+
105+
# codealike
106+
codealike.json
107+
.node
108+
109+
# def publish
110+
.package
111+
112+
# types
113+
/types
114+
115+
# backup files
116+
*.bak
117+
118+
# tests
119+
tests/fixtures/**/actual
120+
121+
122+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
printWidth: 100,
3+
tabWidth: 2,
4+
semi: true,
5+
singleQuote: true,
6+
trailingComma: 'all',
7+
};

modules/code-generator/.versionrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"releaseCommitMessageFormat": "chore(release): code-generator - {{currentTag}}"
3+
}

modules/code-generator/CHANGELOG.md

Lines changed: 266 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# 如何共建
2+
3+
1. 拉取最新代码,切换到 develop 分支,基于 develop 分支切出一个 feature 或 hotfix 分支
4+
2.`lowcode-engine` 项目根目录下,执行 `lerna bootstrap && lerna run build --scope "@felce/lowcode-types"` 来安装依赖并构建
5+
3.`lowcode-engine/modules/code-generator`下,安装依赖(`npm i`),然后先跑一遍 `npm test` 看看是否所有用例都能通过 (如果网络条件不太好,建议使用 [cnpm - 淘宝提供的中国 NPM 镜像](https://npmmirror.com/))
6+
4. 在 tests 目录下编写您的需求/问题的测试用例
7+
5. 修改 src 下的一些代码,然后运行 `npm test``npm start` 启动 jest 进行调测
8+
6. 确保所有的测试用例都能通过时,提 MR 给 @牧毅 -- MR 将在 1 个工作日内给您回复意见。
9+
10+
当然,欢迎提前私聊沟通 @牧毅,或加入 低代码渲染/出码服务金牌用户群 讨论沟通。
11+
12+
# FAQ
13+
14+
## 如何查看单测覆盖率?
15+
16+
执行 `npm test:cov` 命令,这样会自动生成单测覆盖率的报告到 `coverage` 目录下。
17+
18+
## 如何只执行一个测试用例?
19+
20+
```sh
21+
npm test -t 'demo2-utils-name-alias'
22+
```
23+
24+
## 更新特定测试用例的 expected:
25+
26+
```sh
27+
npm test:update-snapshots -t 'demo2-utils-name-alias'
28+
```
29+
30+
## 如何只执行某个测试用例文件?
31+
32+
执行 `npx jest 测试用例的文件路径` 即可,如:
33+
34+
```sh
35+
npx jest tests/plugins/common/requireUtils.test.ts
36+
```
37+
38+
## 如何调试某个测试用例?
39+
40+
建议需要打断点的地方通过 VSCode 打上断点,然后打开 VSCode 的 JavaScript Debug Terminal,在其中执行 `npx jest tests/path/to/your/test/file.ts``npx jest -t your-test-case-title` 来执行你的测试用例 -- 这样执行到打了断点的语句时会自动断住,以便调试。

modules/code-generator/README.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# 出码
2+
3+
所谓出码,即将低代码编排出的 schema 进行解析并转换成最终可执行的代码的过程。本模块提供有 Icejs 和 Rax 两套框架的出码方案,并提供了强大而灵活的扩展机制。
4+
5+
## 使用方法
6+
7+
### 1) 通过命令行快速体验
8+
9+
欢迎使用命令行工具快速体验:`npx @felce/lowcode-code-generator -i example-schema.json -o generated -s icejs`
10+
11+
--其中 example-schema.json 可以从[这里下载](https://unpkg.com/@felce/lowcode-code-generator@beta/example-schema.json)
12+
13+
### 2) 通过设计器插件快速体验
14+
15+
1. 安装依赖: `npm install --save @alilc/lowcode-plugin-code-generator`
16+
2. 注册插件:
17+
18+
```ts
19+
import { plugins } from '@felce/lowcode-engine';
20+
import CodeGenPlugin from '@alilc/lowcode-plugin-code-generator';
21+
22+
// 在你的初始化函数中:
23+
await plugins.register(CodeGenPlugin);
24+
25+
// 如果您不希望自动加上出码按钮,则可以这样注册
26+
await plugins.register(CodeGenPlugin, { disableCodeGenActionBtn: true });
27+
```
28+
29+
然后运行你的低代码编辑器项目即可 -- 在设计器的右上角会出现一个“出码”按钮,点击即可在浏览器中出码并预览。
30+
31+
### 3)服务端出码接入
32+
33+
此代码生成器一开始就是为服务端出码设计的,你可以直接这样来在 node.js 环境中使用:
34+
35+
1. 安装依赖: `npm install --save @felce/lowcode-code-generator`
36+
2. 引入代码生成器:
37+
38+
```js
39+
import CodeGenerator from '@felce/lowcode-code-generator';
40+
```
41+
42+
3. 创建项目构建器:
43+
44+
```js
45+
const projectBuilder = CodeGenerator.solutions.icejs();
46+
```
47+
48+
4. 生成代码
49+
50+
```js
51+
const project = await projectBuilder.generateProject(
52+
schema, // 编排搭建出来的 schema
53+
);
54+
```
55+
56+
5. 将生成的代码写入到磁盘中(也可以生成一个 zip 包)
57+
58+
```js
59+
// 写入磁盘
60+
await CodeGenerator.publishers.disk().publish({
61+
project, // 上一步生成的 project
62+
outputPath: '/path/to/your/output/dir', // 输出目录
63+
projectSlug: 'your-project-slug', // 项目标识
64+
});
65+
66+
// 写入到 zip 包
67+
await CodeGenerator.publishers.zip().publish({
68+
project, // 上一步生成的 project
69+
outputPath: '/path/to/your/output/dir', // 输出目录
70+
projectSlug: 'your-project-slug', // 项目标识 -- 对应生成 your-project-slug.zip 文件
71+
});
72+
```
73+
74+
注:一般来说在服务端出码可以跟 github/gitlab, CI 和 CD 流程等一起串起来使用,通常用于优化性能。
75+
76+
### 4)浏览器中出码接入
77+
78+
随着现在电脑性能和浏览器技术的发展,出码其实已经不必非得在服务端做了,借助于 Web Worker 特性,可以在浏览器中进行出码:
79+
80+
1. 安装依赖: `npm install --save @felce/lowcode-code-generator`
81+
2. 引入代码生成器:
82+
83+
```js
84+
import * as CodeGenerator from '@felce/lowcode-code-generator/standalone-loader';
85+
```
86+
87+
3. 【可选】提前初始化代码生成器:
88+
89+
```js
90+
// 提前初始化下,这样后面用的时候更快(这个 init 内部会提前准备好创建 worker 的一些资源)
91+
await CodeGenerator.init();
92+
```
93+
94+
4. 出码
95+
96+
```js
97+
const project = await CodeGenerator.generateCode({
98+
solution: 'icejs', // 出码方案 (目前内置有 icejs 和 rax )
99+
schema, // 编排搭建出来的 schema
100+
});
101+
102+
console.log(project); // 出码结果(默认是递归结构描述的,可以传 flattenResult: true 以生成扁平结构的结果)
103+
```
104+
105+
注:一般来说在浏览器中出码适合做即时预览功能。
106+
107+
5. 下载 zip 包
108+
109+
```js
110+
// 写入到 zip 包
111+
await CodeGenerator.publishers.zip().publish({
112+
project, // 上一步生成的 project
113+
projectSlug: 'your-project-slug', // 项目标识 -- 对应下载 your-project-slug.zip 文件
114+
});
115+
```
116+
117+
### 5)自定义出码
118+
119+
前端框架灵活多变,默认内置的出码方案很难满足所有人的需求,好在此代码生成器支持非常灵活的插件机制 -- 欢迎参考 ./src/plugins/xxx 来编写您自己的出码插件,然后参考 ./src/solutions/xxx 将各种插件组合成一套适合您的业务场景的出码方案。
120+
121+
## 参与共建
122+
123+
欢迎参与共建,如何共建请参阅:[./CONTRIBUTING.md](https://github.com/fe-lce/lowcode-engine/blob/main/modules/code-generator/CONTRIBUTING.md)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../../babel.config');
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable no-var */
3+
/* eslint-disable prefer-arrow-callback */
4+
/* eslint-disable @typescript-eslint/no-require-imports */
5+
6+
var program = require('commander');
7+
8+
program
9+
.command('generate', { isDefault: true })
10+
.description('Generate code from ali lowcode schema')
11+
.requiredOption('-s, --solution <solution>', 'specify the solution to use (icejs/rax/recore)')
12+
.option('-i, --input <input>', 'specify the input schema file')
13+
.option('-o, --output <output>', 'specify the output directory', 'generated')
14+
.option('-c, --cwd <cwd>', 'specify the working directory', '.')
15+
.option('-q, --quiet', 'be quiet, do not output anything unless get error', false)
16+
.option('-v, --verbose', 'be verbose, output more information', false)
17+
.option('--solution-options <options>', 'specify the solution options', '{}')
18+
.arguments('[input-schema] ali lowcode schema JSON file')
19+
.action(function doGenerate(inputSchema, command) {
20+
var options = command.opts();
21+
if (options.cwd) {
22+
process.chdir(options.cwd);
23+
}
24+
25+
require('../dist/cli')
26+
.run(inputSchema ? [inputSchema] : [], options)
27+
.then((retCode) => {
28+
process.exit(retCode);
29+
});
30+
});
31+
32+
program
33+
.command('init-solution')
34+
.option('-c, --cwd <cwd>', 'specify the working directory', '.')
35+
.option('-q, --quiet', 'be quiet, do not output anything unless get error', false)
36+
.option('-v, --verbose', 'be verbose, output more information', false)
37+
.arguments('<your-solution-name>')
38+
.action(function initSolution(solutionName, command) {
39+
var options = command.opts();
40+
if (options.cwd) {
41+
process.chdir(options.cwd);
42+
}
43+
44+
require('../dist/cli')
45+
.initSolution([solutionName], options)
46+
.then((retCode) => {
47+
process.exit(retCode);
48+
});
49+
});
50+
51+
program.parse(process.argv);
52+

0 commit comments

Comments
 (0)