GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: 解决出码的数据源依赖包问题 by Clarence-pan · Pull Request #106 · alibaba/lowcode-engine

fix: 解决出码的数据源依赖包问题 #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Clarence-pan merged 8 commits into develop from fix/code-gen-datasource-dependencies
Mar 10, 2022

Uh oh!

There was an error while loading. Please reload this page.

Merged

fix: 解决出码的数据源依赖包问题 #106

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit Hold shift + click to select a range
76341c8
fix: 解决 package.json 中误添加了没有用到的数据源类型的 handler 的包的问题 (#56)
Clarence-pan Mar 8, 2022
3f0c250
test: 更新别的相关测试用例的期望值
Clarence-pan Mar 8, 2022
e7ce779
fix: 🐛 去掉 npm 上没有的依赖 (#68)
Clarence-pan Mar 8, 2022
4b8897e
chore: 🤖 fix release:beta script
Clarence-pan Mar 8, 2022
6fde53b
chore(release): 1.0.2-beta.0
Clarence-pan Mar 8, 2022
a94553e
fix: 🐛 补充 icejs 模板中缺失的依赖包
Clarence-pan Mar 8, 2022
873baa0
chore(release): 1.0.2-beta.1
Clarence-pan Mar 8, 2022
d8087d4
chore(release): 1.0.2
Clarence-pan Mar 8, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Next Next commit
fix: 解决 package.json 中误添加了没有用到的数据源类型的 handler 的包的问题 (#56)
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@Clarence-pan
Clarence-pan committed Mar 8, 2022
commit 76341c8456b227192bb65537dc3d16033db0b3a1

There are no files selected for viewing

22 changes: 22 additions & 0 deletions 22 modules/code-generator/src/parser/SchemaParser.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ export class SchemaParser implements ISchemaParser {
containersDeps,
utilsDeps,
packages: npms || [],
dataSourcesTypes: this.collectDataSourcesTypes(schema),
},
};
}
Expand Down Expand Up @@ -350,6 +351,27 @@ export class SchemaParser implements ISchemaParser {
}
return schema;
}

private collectDataSourcesTypes(schema: ProjectSchema): string[] {
const dataSourcesTypes = new Set<string>();

// 数据源的默认类型为 fetch
const defaultDataSourceType = 'fetch';

// 收集应用级别的数据源
schema.dataSource?.list?.forEach((ds) => {
dataSourcesTypes.add(ds.type || defaultDataSourceType);
});

// 收集容器级别的数据源(页面/组件/区块)
schema.componentsTree.forEach((rootNode) => {
rootNode.dataSource?.list?.forEach((ds) => {
dataSourcesTypes.add(ds.type || defaultDataSourceType);
});
});

return Array.from(dataSourcesTypes.values());
}
}

export default SchemaParser;
40 changes: 31 additions & 9 deletions 40 modules/code-generator/src/plugins/project/framework/icejs/plugins/packageJSON.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ICodeStruct,
IProjectInfo,
} from '../../../../../types';
import { buildDataSourceDependencies } from '../../../../../utils/dataSource';

interface IIceJsPackageJSON extends PackageJSON {
ideMode: {
Expand All @@ -22,7 +23,31 @@ interface IIceJsPackageJSON extends PackageJSON {
originTemplate: string;
}

const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
export type IceJsPackageJsonPluginConfig = {
/**
* 数据源配置
*/
datasourceConfig?: {
/** 数据源引擎的版本 */
engineVersion?: string;
/** 数据源引擎的包名 */
enginePackage?: string;
/** 数据源 handlers 的版本 */
handlersVersion?: {
[key: string]: string;
};
/** 数据源 handlers 的包名 */
handlersPackages?: {
[key: string]: string;
};
};
/** 包名 */
packageName?: string;
/** 版本 */
packageVersion?: string;
};

const pluginFactory: BuilderComponentPluginFactory<IceJsPackageJsonPluginConfig> = (cfg) => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = {
...pre,
Expand All @@ -31,21 +56,18 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const ir = next.ir as IProjectInfo;

const packageJson: IIceJsPackageJSON = {
name: '@alifd/scaffold-lite-js',
version: '0.1.5',
name: cfg?.packageName || 'icejs-demo-app',
version: cfg?.packageVersion || '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',
'@alilc/lowcode-datasource-engine': '*',
// TODO: 如何动态获取下面这些依赖?
'@alilc/lowcode-datasource-url-params-handler': '*',
'@alilc/lowcode-datasource-fetch-handler': '*',
'@alilc/lowcode-datasource-mtop-handler': '*',
'@alilc/lowcode-datasource-mopen-handler': '*',
'intl-messageformat': '^9.3.6',

// 数据源相关的依赖:
...buildDataSourceDependencies(ir, cfg?.datasourceConfig),
},
devDependencies: {
'@ice/spec': '^1.0.0',
Expand Down
17 changes: 3 additions & 14 deletions 17 modules/code-generator/src/plugins/project/framework/rax/plugins/packageJSON.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import changeCase from 'change-case';
import { NpmInfo, PackageJSON } from '@alilc/lowcode-types';
import { COMMON_CHUNK_NAME } from '../../../../../const/generator';

Expand All @@ -14,6 +13,7 @@ import { isNpmInfo } from '../../../../../utils/schema';
import { getErrorMessage } from '../../../../../utils/errors';
import { calcCompatibleVersion } from '../../../../../utils/version';
import { RaxFrameworkOptions } from '../types/RaxFrameworkOptions';
import { buildDataSourceDependencies } from '../../../../../utils/dataSource';

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

const packageJson: PackageJSON = {
name: cfg?.packageName || '@alilc/rax-app-demo',
name: cfg?.packageName || 'rax-demo-app',
private: true,
version: cfg?.packageVersion || '1.0.0',
scripts: {
Expand All @@ -39,18 +39,7 @@ const pluginFactory: BuilderComponentPluginFactory<RaxFrameworkOptions> = (cfg)
},
dependencies: {
// 数据源相关的依赖:
[cfg?.datasourceConfig?.enginePackage || '@alilc/lowcode-datasource-engine']:
cfg?.datasourceConfig?.engineVersion || 'latest',
// TODO: [p1] 如何动态获取下究竟用了哪些类型的数据源?
...['url-params', 'fetch', 'mtop', 'mopen'].reduce(
(acc, dsType) => ({
...acc,
[cfg?.datasourceConfig?.handlersPackages?.[dsType] ||
`@alilc/lowcode-datasource-${changeCase.kebab(dsType)}-handler`]:
cfg?.datasourceConfig?.handlersVersion?.[dsType] || 'latest',
}),
{},
),
...buildDataSourceDependencies(ir, cfg?.datasourceConfig),

// 环境判断
'universal-env': '^3.2.0',
Expand Down
1 change: 1 addition & 0 deletions 1 modules/code-generator/src/types/intermediate.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface IProjectInfo {
packages: INpmPackage[];
meta?: { name?: string; title?: string } | Record<string, any>;
config?: Record<string, any>;
dataSourcesTypes?: string[];
}

export interface IPageMeta {
Expand Down
43 changes: 43 additions & 0 deletions 43 modules/code-generator/src/utils/dataSource.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import changeCase from 'change-case';
import type { IProjectInfo } from '../types/intermediate';

export type DataSourceDependenciesConfig = {
/** 数据源引擎的版本 */
engineVersion?: string;
/** 数据源引擎的包名 */
enginePackage?: string;
/** 数据源 handlers 的版本 */
handlersVersion?: {
[key: string]: string;
};
/** 数据源 handlers 的包名 */
handlersPackages?: {
[key: string]: string;
};
};

export function buildDataSourceDependencies(
ir: IProjectInfo,
cfg: DataSourceDependenciesConfig = {},
): Record<string, string> {
return {
// 数据源引擎的依赖包
[cfg.enginePackage || '@alilc/lowcode-datasource-engine']: cfg.engineVersion || 'latest',

// 各种数据源的 handlers 的依赖包
...(ir.dataSourcesTypes || []).reduce(
(acc, dsType) => ({
...acc,
[getDataSourceHandlerPackageName(dsType)]: cfg.handlersVersion?.[dsType] || 'latest',
}),
{},
),
};

function getDataSourceHandlerPackageName(dsType: string) {
return (
cfg.handlersPackages?.[dsType] ||
`@alilc/lowcode-datasource-${changeCase.kebab(dsType)}-handler`
);
}
}
57 changes: 57 additions & 0 deletions 57 modules/code-generator/tests/bugfix/icejs-package-json-dependencies.schema.json
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"version": "1.0.0",
"componentsMap": [
{
"package": "@alilc/lowcode-materials",
"version": "^1.0.0",
"exportName": "Page",
"destructuring": true,
"componentName": "Page"
},
{
"package": "@alilc/lowcode-materials",
"version": "^1.0.0",
"exportName": "Typography",
"destructuring": true,
"subName": "Text",
"componentName": "Text"
}
],
"componentsTree": [
{
"componentName": "Page",
"id": "node_dockcviv8fo1",
"props": {},
"fileName": "test",
"dataSource": {
"list": [
{
"id": "test",
"type": "fetch",
"options": {
"uri": "https://xxx.com/api/xxx"
}
}
]
},
"css": "body {\n font-size: 12px;\n}\n\n.botton {\n width: 100px;\n color: #ff00ff;\n}",
"lifeCycles": {},

"hidden": false,
"title": "",
"isLocked": false,
"condition": true,
"conditionGroup": "",
"state": {},
"children": [
{
"componentName": "Text",
"props": {
"text": "hello world"
}
}
]
}
],
"i18n": {}
}
49 changes: 49 additions & 0 deletions 49 modules/code-generator/tests/bugfix/icejs-package-json-dependencies.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import CodeGenerator from '../../src';
import * as fs from 'fs';
import * as path from 'path';

const testCaseBaseName = path.basename(__filename, '.test.ts');

test(testCaseBaseName, async () => {
const inputSchemaJsonFile = path.join(__dirname, `${testCaseBaseName}.schema.json`);
const outputDir = path.join(__dirname, `${testCaseBaseName}.generated`);
await exportProject(inputSchemaJsonFile, outputDir);

const generatedPackageJsonText = fs.readFileSync(
path.join(outputDir, 'demo-project/package.json'),
'utf-8',
);
const generatedPackageJson = JSON.parse(generatedPackageJsonText);
expect(generatedPackageJson.dependencies).toBeTruthy();

// 里面有的数据源则应该生成对应的 dependencies
expect(generatedPackageJson.dependencies).toMatchObject({
'@alilc/lowcode-datasource-engine': 'latest',
'@alilc/lowcode-datasource-fetch-handler': 'latest',
});

// 里面没有的,则不应该生成对应的 dependencies
expect(generatedPackageJson.dependencies).not.toMatchObject({
'@alilc/lowcode-datasource-url-params-handler': 'latest',
'@alilc/lowcode-datasource-mtop-handler': 'latest',
'@alilc/lowcode-datasource-mopen-handler': 'latest',
});
});

function exportProject(inputPath: string, outputPath: string) {
const schemaJson = fs.readFileSync(inputPath, { encoding: 'utf8' });
const newSchema = schemaJson;
const builder = CodeGenerator.solutions.icejs();

return builder.generateProject(newSchema).then(async (result) => {
// displayResultInConsole(result);
const publisher = CodeGenerator.publishers.disk();
await publisher.publish({
project: result,
outputPath,
projectSlug: 'demo-project',
createProjectFolder: true,
});
return result;
});
}
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.