Skip to content

Commit 6a642e8

Browse files
authored
fix: 解决出码的数据源依赖包问题 (alibaba#106)
* fix: 解决 package.json 中误添加了没有用到的数据源类型的 handler 的包的问题 (alibaba#56) * test: 更新别的相关测试用例的期望值 * fix: 🐛 去掉 npm 上没有的依赖 (alibaba#68) * chore: 🤖 fix release:beta script * chore(release): 1.0.2-beta.0 * fix: 🐛 补充 icejs 模板中缺失的依赖包 * chore(release): 1.0.2-beta.1 * chore(release): 1.0.2
1 parent 4a01c97 commit 6a642e8

File tree

47 files changed

+355
-210
lines changed

Some content is hidden

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

47 files changed

+355
-210
lines changed

modules/code-generator/CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,43 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
### [1.0.2](https://github.com/alibaba/lowcode-engine/compare/@alilc/lowcode-code-generator@1.0.2-beta.1...@alilc/lowcode-code-generator@1.0.2) (2022-03-08)
6+
7+
### [1.0.2-beta.1](https://github.com/alibaba/lowcode-engine/compare/@alilc/lowcode-code-generator@1.0.2-beta.0...@alilc/lowcode-code-generator@1.0.2-beta.1) (2022-03-08)
8+
9+
10+
### Bug Fixes
11+
12+
* 🐛 补充 icejs 模板中缺失的依赖包 ([a94553e](https://github.com/alibaba/lowcode-engine/commit/a94553e503d439b67478df6a34950d9e3d15a063))
13+
14+
### [1.0.2-beta.0](https://github.com/alibaba/lowcode-engine/compare/@alilc/lowcode-code-generator@1.0.0...@alilc/lowcode-code-generator@1.0.2-beta.0) (2022-03-08)
15+
16+
17+
### Features
18+
19+
* 在 skeleton 增加几个方法和事件 ([a7d436a](https://github.com/alibaba/lowcode-engine/commit/a7d436a0525a0ce0c7229710077111f283b452f4))
20+
* modify npm private control & version ([ee55d02](https://github.com/alibaba/lowcode-engine/commit/ee55d024a7f964ccf35a0efabec817364cea8041))
21+
* modify yuque link in README ([d522034](https://github.com/alibaba/lowcode-engine/commit/d522034879d20a7b5ed12f8fe02a30662a2ea7c6))
22+
* remove CHANGELOG.md ([b996414](https://github.com/alibaba/lowcode-engine/commit/b996414c436b5d2439c8368eb4e001cdbcd02892))
23+
* remove module field in material-parser package.json ([6141c27](https://github.com/alibaba/lowcode-engine/commit/6141c273c9c32eea22b5374679fe625e6ea15394))
24+
* rename build:umd ([23c7959](https://github.com/alibaba/lowcode-engine/commit/23c795931e1d5cf43e9c21cd902441c69c1ecc63))
25+
* replace tnpm with npm ([36caf0f](https://github.com/alibaba/lowcode-engine/commit/36caf0f18980c16f7ebb82ac845ad6b33e033567))
26+
* support UMD packageing for react-renderer ([982d0d6](https://github.com/alibaba/lowcode-engine/commit/982d0d676b3dfbfc10a2190c0040126d6925ed37))
27+
28+
29+
### Bug Fixes
30+
31+
* 🐛 去掉 npm 上没有的依赖 ([#68](https://github.com/alibaba/lowcode-engine/issues/68)) ([e7ce779](https://github.com/alibaba/lowcode-engine/commit/e7ce77987eb05871dd1675d2a88367c5569bfbff))
32+
* 兼容 setters 为空的情况 ([56b459a](https://github.com/alibaba/lowcode-engine/commit/56b459a017a8350a911ef20f0166d1e62b6390e4))
33+
* 解决 package.json 中误添加了没有用到的数据源类型的 handler 的包的问题 ([#56](https://github.com/alibaba/lowcode-engine/issues/56)) ([76341c8](https://github.com/alibaba/lowcode-engine/commit/76341c8456b227192bb65537dc3d16033db0b3a1))
34+
* 解决出码的一些问题 ([#87](https://github.com/alibaba/lowcode-engine/issues/87)) ([4a01c97](https://github.com/alibaba/lowcode-engine/commit/4a01c97ea6bf23eb677888ba1aba54e5c9f4f630))
35+
* 修复 setup 的逻辑 ([1cfb15a](https://github.com/alibaba/lowcode-engine/commit/1cfb15aebea9796af23b2135f2aa4409d81283d7))
36+
* 修正一些对内的地址 ([07cc1f2](https://github.com/alibaba/lowcode-engine/commit/07cc1f2954530c64a1a3d260e8d532c9e19892e8))
37+
* 增加必要的方法 ([1b38a81](https://github.com/alibaba/lowcode-engine/commit/1b38a812653656aa02100a3b1b2a581188d1b3ef))
38+
* fix tsconfig of material-parser ([46725cb](https://github.com/alibaba/lowcode-engine/commit/46725cb9f3166912c8f5b42f1e0b1177158c1ee3))
39+
* lint&fix auto generated types.ts ([7dde970](https://github.com/alibaba/lowcode-engine/commit/7dde9701c7960b29523abddf32421cdbac47016d))
40+
* The outline tree does not display the loop flag when the loop is an empty array ([191e284](https://github.com/alibaba/lowcode-engine/commit/191e284f2fa190c2b3aecb4df31849b2bdc99d38))
41+
542
### [1.0.1](https://github.com/alibaba/lowcode-engine/compare/@alilc/lowcode-code-generator@1.0.0...@alilc/lowcode-code-generator@1.0.1) (2022-03-08)
643

744

modules/code-generator/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alilc/lowcode-code-generator",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "出码引擎 for LowCode Engine",
55
"license": "MIT",
66
"main": "lib/index.js",
@@ -41,7 +41,7 @@
4141
"test:cov": "jest --coverage",
4242
"test:update-snapshots": "cross-env UPDATE_EXPECTED=true jest -u",
4343
"analyze:standalone": "ANALYZE=true node scripts/build-standalone",
44-
"release:beta": "standard-version -t @alilc/lowcode-code-generator\\@ --prerelease beta && git push --follow-tags && npm publish --tag beta",
44+
"release:beta": "standard-version -t @alilc/lowcode-code-generator\\@ -r patch --prerelease beta && git push --follow-tags && npm publish --tag beta",
4545
"release:patch": "standard-version -t @alilc/lowcode-code-generator\\@ -r patch && git push --follow-tags && npm publish",
4646
"release:minor": "standard-version -t @alilc/lowcode-code-generator\\@ -r minor && git push --follow-tags && npm publish",
4747
"prepublishOnly": "npm run build",

modules/code-generator/src/parser/SchemaParser.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ export class SchemaParser implements ISchemaParser {
319319
containersDeps,
320320
utilsDeps,
321321
packages: npms || [],
322+
dataSourcesTypes: this.collectDataSourcesTypes(schema),
322323
},
323324
};
324325
}
@@ -350,6 +351,27 @@ export class SchemaParser implements ISchemaParser {
350351
}
351352
return schema;
352353
}
354+
355+
private collectDataSourcesTypes(schema: ProjectSchema): string[] {
356+
const dataSourcesTypes = new Set<string>();
357+
358+
// 数据源的默认类型为 fetch
359+
const defaultDataSourceType = 'fetch';
360+
361+
// 收集应用级别的数据源
362+
schema.dataSource?.list?.forEach((ds) => {
363+
dataSourcesTypes.add(ds.type || defaultDataSourceType);
364+
});
365+
366+
// 收集容器级别的数据源(页面/组件/区块)
367+
schema.componentsTree.forEach((rootNode) => {
368+
rootNode.dataSource?.list?.forEach((ds) => {
369+
dataSourcesTypes.add(ds.type || defaultDataSourceType);
370+
});
371+
});
372+
373+
return Array.from(dataSourcesTypes.values());
374+
}
353375
}
354376

355377
export default SchemaParser;

modules/code-generator/src/plugins/project/framework/icejs/plugins/packageJSON.ts

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ICodeStruct,
1111
IProjectInfo,
1212
} from '../../../../../types';
13+
import { buildDataSourceDependencies } from '../../../../../utils/dataSource';
1314

1415
interface IIceJsPackageJSON extends PackageJSON {
1516
ideMode: {
@@ -22,7 +23,31 @@ interface IIceJsPackageJSON extends PackageJSON {
2223
originTemplate: string;
2324
}
2425

25-
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
26+
export type IceJsPackageJsonPluginConfig = {
27+
/**
28+
* 数据源配置
29+
*/
30+
datasourceConfig?: {
31+
/** 数据源引擎的版本 */
32+
engineVersion?: string;
33+
/** 数据源引擎的包名 */
34+
enginePackage?: string;
35+
/** 数据源 handlers 的版本 */
36+
handlersVersion?: {
37+
[key: string]: string;
38+
};
39+
/** 数据源 handlers 的包名 */
40+
handlersPackages?: {
41+
[key: string]: string;
42+
};
43+
};
44+
/** 包名 */
45+
packageName?: string;
46+
/** 版本 */
47+
packageVersion?: string;
48+
};
49+
50+
const pluginFactory: BuilderComponentPluginFactory<IceJsPackageJsonPluginConfig> = (cfg) => {
2651
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
2752
const next: ICodeStruct = {
2853
...pre,
@@ -31,21 +56,21 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
3156
const ir = next.ir as IProjectInfo;
3257

3358
const packageJson: IIceJsPackageJSON = {
34-
name: '@alifd/scaffold-lite-js',
35-
version: '0.1.5',
59+
name: cfg?.packageName || 'icejs-demo-app',
60+
version: cfg?.packageVersion || '0.1.5',
3661
description: '轻量级模板,使用 JavaScript,仅包含基础的 Layout。',
3762
dependencies: {
3863
moment: '^2.24.0',
3964
react: '^16.4.1',
4065
'react-dom': '^16.4.1',
66+
'react-router': '^5.2.1',
4167
'@alifd/theme-design-pro': '^0.x',
42-
'@alilc/lowcode-datasource-engine': '*',
43-
// TODO: 如何动态获取下面这些依赖?
44-
'@alilc/lowcode-datasource-url-params-handler': '*',
45-
'@alilc/lowcode-datasource-fetch-handler': '*',
46-
'@alilc/lowcode-datasource-mtop-handler': '*',
47-
'@alilc/lowcode-datasource-mopen-handler': '*',
4868
'intl-messageformat': '^9.3.6',
69+
'@ice/store': '^1.4.3',
70+
'@loadable/component': '^5.15.2',
71+
72+
// 数据源相关的依赖:
73+
...buildDataSourceDependencies(ir, cfg?.datasourceConfig),
4974
},
5075
devDependencies: {
5176
'@ice/spec': '^1.0.0',
@@ -54,7 +79,6 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
5479
eslint: '^6.0.1',
5580
'ice.js': '^1.0.0',
5681
stylelint: '^13.2.0',
57-
'@ali/build-plugin-ice-def': '^0.1.0',
5882
},
5983
scripts: {
6084
start: 'icejs start',

modules/code-generator/src/plugins/project/framework/icejs/template/files/build.json.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ export default function getFile(): [string[], ResultFile] {
2323
"zh-cn"
2424
]
2525
}
26-
],
27-
"@ali/build-plugin-ice-def"
26+
]
2827
]
2928
}
3029
`,

modules/code-generator/src/plugins/project/framework/rax/plugins/packageJSON.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import changeCase from 'change-case';
21
import { NpmInfo, PackageJSON } from '@alilc/lowcode-types';
32
import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
43

@@ -14,6 +13,7 @@ import { isNpmInfo } from '../../../../../utils/schema';
1413
import { getErrorMessage } from '../../../../../utils/errors';
1514
import { calcCompatibleVersion } from '../../../../../utils/version';
1615
import { RaxFrameworkOptions } from '../types/RaxFrameworkOptions';
16+
import { buildDataSourceDependencies } from '../../../../../utils/dataSource';
1717

1818
const pluginFactory: BuilderComponentPluginFactory<RaxFrameworkOptions> = (cfg) => {
1919
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
@@ -26,7 +26,7 @@ const pluginFactory: BuilderComponentPluginFactory<RaxFrameworkOptions> = (cfg)
2626
const npmDeps = getNpmDependencies(ir);
2727

2828
const packageJson: PackageJSON = {
29-
name: cfg?.packageName || '@alilc/rax-app-demo',
29+
name: cfg?.packageName || 'rax-demo-app',
3030
private: true,
3131
version: cfg?.packageVersion || '1.0.0',
3232
scripts: {
@@ -39,18 +39,7 @@ const pluginFactory: BuilderComponentPluginFactory<RaxFrameworkOptions> = (cfg)
3939
},
4040
dependencies: {
4141
// 数据源相关的依赖:
42-
[cfg?.datasourceConfig?.enginePackage || '@alilc/lowcode-datasource-engine']:
43-
cfg?.datasourceConfig?.engineVersion || 'latest',
44-
// TODO: [p1] 如何动态获取下究竟用了哪些类型的数据源?
45-
...['url-params', 'fetch', 'mtop', 'mopen'].reduce(
46-
(acc, dsType) => ({
47-
...acc,
48-
[cfg?.datasourceConfig?.handlersPackages?.[dsType] ||
49-
`@alilc/lowcode-datasource-${changeCase.kebab(dsType)}-handler`]:
50-
cfg?.datasourceConfig?.handlersVersion?.[dsType] || 'latest',
51-
}),
52-
{},
53-
),
42+
...buildDataSourceDependencies(ir, cfg?.datasourceConfig),
5443

5544
// 环境判断
5645
'universal-env': '^3.2.0',

modules/code-generator/src/types/intermediate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface IProjectInfo {
4242
packages: INpmPackage[];
4343
meta?: { name?: string; title?: string } | Record<string, any>;
4444
config?: Record<string, any>;
45+
dataSourcesTypes?: string[];
4546
}
4647

4748
export interface IPageMeta {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import changeCase from 'change-case';
2+
import type { IProjectInfo } from '../types/intermediate';
3+
4+
export type DataSourceDependenciesConfig = {
5+
/** 数据源引擎的版本 */
6+
engineVersion?: string;
7+
/** 数据源引擎的包名 */
8+
enginePackage?: string;
9+
/** 数据源 handlers 的版本 */
10+
handlersVersion?: {
11+
[key: string]: string;
12+
};
13+
/** 数据源 handlers 的包名 */
14+
handlersPackages?: {
15+
[key: string]: string;
16+
};
17+
};
18+
19+
export function buildDataSourceDependencies(
20+
ir: IProjectInfo,
21+
cfg: DataSourceDependenciesConfig = {},
22+
): Record<string, string> {
23+
return {
24+
// 数据源引擎的依赖包
25+
[cfg.enginePackage || '@alilc/lowcode-datasource-engine']: cfg.engineVersion || 'latest',
26+
27+
// 各种数据源的 handlers 的依赖包
28+
...(ir.dataSourcesTypes || []).reduce(
29+
(acc, dsType) => ({
30+
...acc,
31+
[getDataSourceHandlerPackageName(dsType)]: cfg.handlersVersion?.[dsType] || 'latest',
32+
}),
33+
{},
34+
),
35+
};
36+
37+
function getDataSourceHandlerPackageName(dsType: string) {
38+
return (
39+
cfg.handlersPackages?.[dsType] ||
40+
`@alilc/lowcode-datasource-${changeCase.kebab(dsType)}-handler`
41+
);
42+
}
43+
}

modules/code-generator/test-cases/rax-app/demo01/expected/demo-project/package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@alilc/rax-app-demo",
2+
"name": "rax-demo-app",
33
"private": true,
44
"version": "1.0.0",
55
"scripts": {
@@ -12,10 +12,6 @@
1212
},
1313
"dependencies": {
1414
"@alilc/lowcode-datasource-engine": "latest",
15-
"@alilc/lowcode-datasource-url-params-handler": "latest",
16-
"@alilc/lowcode-datasource-fetch-handler": "latest",
17-
"@alilc/lowcode-datasource-mtop-handler": "latest",
18-
"@alilc/lowcode-datasource-mopen-handler": "latest",
1915
"universal-env": "^3.2.0",
2016
"intl-messageformat": "^9.3.6",
2117
"rax": "^1.1.0",

modules/code-generator/test-cases/rax-app/demo02/expected/demo-project/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@alilc/rax-app-demo",
2+
"name": "rax-demo-app",
33
"private": true,
44
"version": "1.0.0",
55
"scripts": {
@@ -14,8 +14,6 @@
1414
"@alilc/lowcode-datasource-engine": "latest",
1515
"@alilc/lowcode-datasource-url-params-handler": "latest",
1616
"@alilc/lowcode-datasource-fetch-handler": "latest",
17-
"@alilc/lowcode-datasource-mtop-handler": "latest",
18-
"@alilc/lowcode-datasource-mopen-handler": "latest",
1917
"universal-env": "^3.2.0",
2018
"intl-messageformat": "^9.3.6",
2119
"rax": "^1.1.0",

0 commit comments

Comments
 (0)