diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..430bd5809802262368db381f2734ca6227885485 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,22 @@ +# 版本变更日志 + +这个项目的所有关键变化都将记录在此文件中. + +此日志格式基于 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.0.0/), +并且此项目遵循 [Semantic Versioning](https://semver.org/lang/zh-CN/). + +## [Unreleased] + +### Added + +- 应用实体: 可以遍历当前应用实体的所属的视图、部件模型 + +### Changed + +- 应用路径拼接方式修正 + +## [0.1.13] - 2022-02-22 + +### Added + +- 补充开发模式进行模板开发 diff --git a/lerna.json b/lerna.json index 0b80df700e738c259c4ba3d03f17c44e1b3b8762..3002e2e20bd3556a8f0a4c026559fc3ac5237a36 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "0.1.12", + "version": "0.1.15", "npmClient": "pnpm", "packages": [ "packages/*" diff --git a/packages/cli/package.json b/packages/cli/package.json index 2565d4f5dfb92580e09e9da9bea1b918033afaae..514fb57603a5b15b57c2cd7acf167840928befa7 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@ibizlab/cli", - "version": "0.1.12", + "version": "0.1.15", "description": "核心代码", "bin": { "ibizlab": "out/bin.js" @@ -19,7 +19,7 @@ }, "license": "MIT", "dependencies": { - "@ibizlab/template": "^0.1.12", + "@ibizlab/template": "^0.1.15", "chalk": "4.1.2", "commander": "^9.4.0", "fs-extra": "^10.1.0", diff --git a/packages/core/package.json b/packages/core/package.json index d5ce8b9e1968744caffa9949e5b840c7034ab254..273334e7f11d43332b0e41bfb75ebfc37f449d69 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@ibizlab/template-core", - "version": "0.1.9", + "version": "0.1.13", "description": "核心代码", "main": "out/index.js", "types": "out/types/index.d.ts", diff --git a/packages/generator/package.json b/packages/generator/package.json index ac69b862d82eede0b29b2d5689227179fc79b83a..f6121be347237d8ab1d8a03659c0e608d0035422 100644 --- a/packages/generator/package.json +++ b/packages/generator/package.json @@ -1,6 +1,6 @@ { "name": "@ibizlab/template-generator", - "version": "0.1.11", + "version": "0.1.13", "description": "核心代码", "main": "out/index.js", "types": "out/types/index.d.ts", @@ -17,7 +17,7 @@ "author": "chitanda", "license": "MIT", "dependencies": { - "@ibizlab/template-core": "^0.1.9", + "@ibizlab/template-core": "^0.1.13", "fs-extra": "^10.1.0", "glob": "^8.0.3", "pluralize": "^8.0.0", diff --git a/packages/handlebars/package.json b/packages/handlebars/package.json index 55c00d768e5da0b34a01dd1b27708b9708dccf89..a69b12ccca66ffd3c771a723f10a387c72617df5 100644 --- a/packages/handlebars/package.json +++ b/packages/handlebars/package.json @@ -1,6 +1,6 @@ { "name": "@ibizlab/template-handlebars", - "version": "0.1.11", + "version": "0.1.14", "description": "核心代码", "main": "out/index.js", "types": "out/types/index.d.ts", @@ -18,7 +18,7 @@ "author": "chitanda", "license": "MIT", "dependencies": { - "@ibizlab/template-core": "^0.1.9", + "@ibizlab/template-core": "^0.1.13", "handlebars": "^4.7.7", "lodash": "^4.17.21", "pluralize": "^8.0.0", diff --git a/packages/handlebars/test/helpers/helper.test.ts b/packages/handlebars/test/helpers/helper.test.ts index a64edb7e0e50e08123885952d18dea89928b1ff7..097cc26b946833de27bbcb13b0a9b8e6b532c8a1 100644 --- a/packages/handlebars/test/helpers/helper.test.ts +++ b/packages/handlebars/test/helpers/helper.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-lone-blocks */ import { HandlebarsEngine } from '../../src'; describe('模板助手测试', () => { diff --git a/packages/model/package.json b/packages/model/package.json index 9551f60b96c2c0a6020ff279569913a50f9f1496..fe536589463d0028299314847335dec3446b7052 100644 --- a/packages/model/package.json +++ b/packages/model/package.json @@ -1,6 +1,6 @@ { "name": "@ibizlab/template-model", - "version": "0.1.12", + "version": "0.1.15", "description": "核心代码", "main": "out/index.js", "types": "out/types/index.d.ts", @@ -18,8 +18,8 @@ "author": "chitanda", "license": "MIT", "dependencies": { - "@ibizlab/model": "^0.0.26", - "@ibizlab/template-generator": "^0.1.11", + "@ibizlab/model": "^0.1.3", + "@ibizlab/template-generator": "^0.1.13", "fs-extra": "^10.1.0", "lodash": "^4.17.21", "pluralize": "^8.0.0", diff --git a/packages/model/src/model/app/app-entity-model.ts b/packages/model/src/model/app/app-entity-model.ts index 43c869277268287cbe1f0fff5cb830e4f30191a4..ac99151b96899ca3a9390fea48def52655358474 100644 --- a/packages/model/src/model/app/app-entity-model.ts +++ b/packages/model/src/model/app/app-entity-model.ts @@ -1,5 +1,10 @@ -import { PSAppDataEntityImpl } from '@ibizlab/model'; -import * as pluralize from 'pluralize'; +import { + IPSAppDERS, + IPSApplication, + IPSControl, + PSAppDataEntityImpl, +} from '@ibizlab/model'; +import { AppModel } from './app-model'; import { CtrlModel } from './ctrl-model'; import { PageModel } from './page-model'; @@ -13,64 +18,6 @@ import { PageModel } from './page-model'; * @extends {PSAppDataEntityImpl} */ export class AppEntityModel extends PSAppDataEntityImpl { - /** - * 实体资源路径 - * - * @author chitanda - * @date 2022-01-03 10:01:22 - * @protected - * @type {IModel[]} - */ - protected _appEntityResources: IModel[] = []; - - get appEntityResources(): IModel[] { - if (this._appEntityResources.length === 0) { - const deRss = this.getMinorPSAppDERSs(); - if (deRss) { - deRss.forEach(rs => { - const major = rs.getMajorPSAppDataEntityMust(); - const minor = rs.getMinorPSAppDataEntityMust(); - const majorCodeName = major.codeName; - const minorCoeName = minor.codeName; - const pluralizeMajorCodeName = pluralize(majorCodeName).toLowerCase(); - const pluralizeMinorCoeName = pluralize(minorCoeName).toLowerCase(); - // 资源 - const resource: Record = {}; - resource.majorCodeName = majorCodeName.toLowerCase(); - resource.curCodeName = minorCoeName.toLowerCase(); - resource.path = - `${pluralizeMajorCodeName}/:${majorCodeName}/${pluralizeMinorCoeName}/:${minorCoeName}`.toLowerCase(); - // 路径 - const deRsPaths: Record[] = []; - deRsPaths.push({ - pathName: pluralizeMajorCodeName, - parameterName: majorCodeName.toLowerCase(), - }); - deRsPaths.push({ - pathName: pluralizeMinorCoeName, - parameterName: minorCoeName.toLowerCase(), - }); - resource.deResPaths = JSON.stringify(deRsPaths); - this._appEntityResources.push(resource); - }); - } else { - const pluralizeCodeName = pluralize(this.codeName).toLowerCase(); - const deResPaths = [ - { - pathName: pluralizeCodeName, - parameterName: this.codeName.toLowerCase(), - }, - ]; - this._appEntityResources.push({ - curCodeName: this.codeName.toLowerCase(), - path: `${pluralizeCodeName}/:${this.codeName}`.toLowerCase(), - deResPaths: JSON.stringify(deResPaths), - }); - } - } - return this._appEntityResources; - } - /** * 实体下所有视图 * @@ -83,10 +30,19 @@ export class AppEntityModel extends PSAppDataEntityImpl { get pages(): PageModel[] { if (this._pages.length === 0) { - const views = this.getAllPSAppViews(); + const app = this.getParentPSModelObject( + 'app.IPSApplication', + ) as IPSApplication; + const views = app.getAllPSAppViews(); if (views) { views - .filter(view => view.refFlag === true) + .filter(view => { + if (view.refFlag === true) { + const entity = view.getPSAppDataEntity(); + return entity?.id === this.id; + } + return false; + }) .forEach(view => { this._pages.push(new PageModel(view)); }); @@ -98,6 +54,7 @@ export class AppEntityModel extends PSAppDataEntityImpl { /** * 应用实体所有部件 * + * @description 应用实体所有部件走独立 json 加载,不使用视图中的部件模型 * @author chitanda * @date 2021-12-28 19:12:09 * @protected @@ -108,11 +65,27 @@ export class AppEntityModel extends PSAppDataEntityImpl { get ctrls(): CtrlModel[] { if (this._ctrls.length === 0) { const map: Map = new Map(); + const s = this.getPSModelService(); this.pages.forEach(page => { const { ctrls } = page; if (ctrls) { ctrls.forEach(ctrl => { - map.set(ctrl.mosFilePath, ctrl); + const entity = ctrl.getPSAppDataEntityMust(); + const key = `${entity.id}_${ctrl.id}`; + if (map.has(key)) { + return; + } + if (ctrl.modelPath) { + const model = s.getModel(this, ctrl.modelPath); + const modelObj = s.getPSModel4( + this, + 'control.IPSControl', + model, + '', + ); + ctrl = new CtrlModel(modelObj as IPSControl); + } + map.set(key, ctrl); }); } }); @@ -120,4 +93,165 @@ export class AppEntityModel extends PSAppDataEntityImpl { } return this._ctrls; } + + /** + * 当前应用实体路径Map + * + * @type {Map} + * @memberof AppEntityModel + */ + private psAppDERSPathMap: Map = new Map< + number, + IPSAppDERS[] + >(); + + /** + * 当前应用实体所有关系路径 + * + * @protected + * @type {string[][]} + * @memberof AppEntityModel + */ + protected _appDERSPaths: string[][] = []; + + /** + * 当前应用实体所有关系路径 + * + * @readonly + * @type {string[][]} + * @memberof AppEntityModel + */ + get appDERSPaths(): string[][] { + if (this._appDERSPaths.length === 0) { + const appDERSs = this.getPSAppDERSs(); + if (appDERSs.length === 0) { + return []; + } + appDERSs.forEach((appDERS: IPSAppDERS) => { + if (appDERS.minorDECodeName === appDERS.majorDECodeName) { + return; + } + const list: IPSAppDERS[] = []; + const nIndex = this.psAppDERSPathMap.size; + this.psAppDERSPathMap.set(nIndex, list); + this.fillPSAppDERSPath(appDERS, list); + }); + this._appDERSPaths = this.handlePSAppDERSPaths(); + } + return this._appDERSPaths; + } + + /** + * 处理应用实体路径 + * + * @private + * @return {*} + * @memberof AppEntityModel + */ + private handlePSAppDERSPaths() { + const pathResult: Array> = []; + if (this.psAppDERSPathMap.size > 0) { + const iterator = this.psAppDERSPathMap.values(); + let i = 0; + while (i < this.psAppDERSPathMap.size) { + const list = iterator.next().value; + if (list && list.length > 0) { + const path: Array = []; + list.forEach((appDERS: IPSAppDERS) => { + path.push(appDERS.majorDECodeName); + }); + pathResult.push(path); + } + i++; + } + } + if (pathResult.length > 0) { + pathResult.sort((a: Array, b: Array) => { + return b.length - a.length; + }); + } + return pathResult; + } + + /** + * 获取指定应用实体所有关系 + * + * @private + * @param {string} [entityCodeName] 应用实体标识 + * @return {*} {IPSAppDERS[]} + * @memberof AppEntityModel + */ + private getPSAppDERSs(entityCodeName?: string): IPSAppDERS[] { + const app = this.getParentPSModelObject('app.IPSApplication') as AppModel; + const appDERSs: IPSAppDERS[] = []; + if (app && app.allPSAppDERSs && app.allPSAppDERSs.length > 0) { + app.allPSAppDERSs.forEach((appDERS: IPSAppDERS) => { + if (entityCodeName) { + if (appDERS.minorDECodeName === entityCodeName) { + appDERSs.push(appDERS); + } + } else if (appDERS.minorDECodeName === this.codeName) { + appDERSs.push(appDERS); + } + }); + } + return appDERSs; + } + + /** + * 填充指定应用实体所有关联路径 + * + * @private + * @param {IPSAppDERS} appDERS 关系 + * @param {IPSAppDERS[]} list 关系集合 + * @return {*} + * @memberof AppEntityModel + */ + private fillPSAppDERSPath(appDERS: IPSAppDERS, list: IPSAppDERS[]) { + if (list.length > 0) { + list.forEach((tempPSAppDERS: IPSAppDERS) => { + if (appDERS.id === tempPSAppDERS.id) { + console.warn( + `应用实体${this.codeName}存在递归引用关系${appDERS.name}`, + ); + } + }); + } + list.unshift(appDERS); + const majorList: IPSAppDERS[] = this.getPSAppDERSs(appDERS.majorDECodeName); + if (majorList.length === 0) return; + const srcList: IPSAppDERS[] = []; + list.forEach((_appDERS: IPSAppDERS) => { + srcList.push(_appDERS); + }); + let nIndex: number = 0; + majorList.forEach((tempPSAppDERS: IPSAppDERS) => { + if (tempPSAppDERS.majorDECodeName === tempPSAppDERS.minorDECodeName) { + return; + } + if (nIndex === 0) { + if (appDERS.majorDEMajor !== false) { + // 主实体,备份当前路径 + const list2: IPSAppDERS[] = []; + srcList.forEach((_appDERS: IPSAppDERS) => { + list2.push(_appDERS); + }); + const nIndex2 = this.psAppDERSPathMap.size; + this.psAppDERSPathMap.set(nIndex2, list2); + } + // 继续主路径 + this.fillPSAppDERSPath(tempPSAppDERS, list); + } else { + // 克隆新路径 + const list2: IPSAppDERS[] = []; + srcList.forEach((_appDERS: IPSAppDERS) => { + list2.push(_appDERS); + }); + const nIndex2 = this.psAppDERSPathMap.size; + this.psAppDERSPathMap.set(nIndex2, list2); + this.fillPSAppDERSPath(tempPSAppDERS, list2); + } + nIndex++; + }); + } } diff --git a/packages/model/src/model/app/app-model.ts b/packages/model/src/model/app/app-model.ts index 1180b7603456e1951cdc303265698d704cc825cf..ad1d135dbabcab4ebc983fed9b41d3ba82c086d6 100644 --- a/packages/model/src/model/app/app-model.ts +++ b/packages/model/src/model/app/app-model.ts @@ -1,5 +1,4 @@ -import { IPSAppDERS, PSApplicationImpl } from '@ibizlab/model'; -import * as pluralize from 'pluralize'; +import { PSApplicationImpl } from '@ibizlab/model'; import { AppEntityModel } from './app-entity-model'; import { AppModuleModel } from './app-module-model'; import { PageModel } from './page-model'; @@ -24,6 +23,14 @@ export class AppModel extends PSApplicationImpl { */ protected _appModules: AppModuleModel[] = []; + /** + * 无法直接使用,无此模型。需要配合视图才能上级有 appModule + * + * @author chitanda + * @date 2022-09-20 19:09:59 + * @readonly + * @type {AppModuleModel[]} + */ get appModules(): AppModuleModel[] { if (this._appModules.length === 0) { const modules = this.getAllPSAppModules(); @@ -95,55 +102,4 @@ export class AppModel extends PSApplicationImpl { } return this._pages || []; } - - /** - * 应用实体资源数据 - * - * @protected - * @type {Map} - * @memberof AppModel - */ - protected _appEntityResources: Map = new Map(); - - get appEntityResources(): IModel[] { - const values: IModel[] = []; - if (this.appEntities.length > 0) { - this.appEntities.forEach((entity: AppEntityModel) => { - if (entity.minorPSAppDERSs && entity.minorPSAppDERSs.length > 0) { - entity.minorPSAppDERSs.forEach((appDERS: IPSAppDERS) => { - const majorCodeName: string = appDERS.majorPSAppDataEntity - ?.codeName as string; - const minorCodeName: string = appDERS.minorPSAppDataEntity - ?.codeName as string; - const temp: IModel = { - path: `${pluralize( - majorCodeName, - ).toLowerCase()}/:${majorCodeName.toLowerCase()}?/${pluralize( - minorCodeName, - ).toLowerCase()}/:${minorCodeName.toLowerCase()}?`, - majorCodeName: majorCodeName.toLowerCase(), - curCodeName: minorCodeName.toLowerCase(), - appDataEntity: entity, - }; - values.push(temp); - this._appEntityResources.set( - `${majorCodeName}:${minorCodeName}`, - temp, - ); - }); - } else { - const temp = { - curCodeName: entity.codeName.toLowerCase(), - path: `${pluralize( - entity.codeName, - ).toLowerCase()}/:${entity.codeName.toLowerCase()}`, - appDataEntity: entity, - }; - values.push(temp); - this._appEntityResources.set(entity.codeName, temp); - } - }); - } - return values; - } } diff --git a/packages/model/src/model/app/page-model.ts b/packages/model/src/model/app/page-model.ts index 4d6bff5dd7f635d46b6cd7f4e010d5e0a6de77c8..b9d9eccc3f0ea82e4492762e6961f5f554921bdc 100644 --- a/packages/model/src/model/app/page-model.ts +++ b/packages/model/src/model/app/page-model.ts @@ -40,12 +40,13 @@ export class PageModel extends PSAppViewImpl { if (!this._appModule) { const module = this.psAppModule; if (module != null) { + const app = this.getParentPSModelObject('app.IPSApplication'); const moduleImpl = new AppModuleModel(); moduleImpl.init( module.getPSModelService(), module.modelPath!, module.M, - module.parent, + app, ); this._appModule = moduleImpl; } @@ -67,12 +68,13 @@ export class PageModel extends PSAppViewImpl { if (!this._appEntity) { const module = this.psAppDataEntity; if (module != null) { + const app = this.getParentPSModelObject('app.IPSApplication'); const appEntityImpl = new AppEntityModel(); appEntityImpl.init( module.getPSModelService(), module.modelPath!, module.M, - module.parent, + app, ); this._appEntity = appEntityImpl; } diff --git a/packages/template/package.json b/packages/template/package.json index 5eaf6ffa50fb7ab0f375caf938b89e1a21b907e2..13eb2f816667b5bb99448f0a46cb3f4c8d9bc752 100644 --- a/packages/template/package.json +++ b/packages/template/package.json @@ -1,6 +1,6 @@ { "name": "@ibizlab/template", - "version": "0.1.12", + "version": "0.1.15", "description": "核心代码", "main": "out/index.js", "types": "out/types/index.d.ts", @@ -17,10 +17,10 @@ "author": "chitanda", "license": "MIT", "dependencies": { - "@ibizlab/template-core": "^0.1.9", - "@ibizlab/template-generator": "^0.1.11", - "@ibizlab/template-handlebars": "^0.1.11", - "@ibizlab/template-model": "^0.1.12", + "@ibizlab/template-core": "^0.1.13", + "@ibizlab/template-generator": "^0.1.13", + "@ibizlab/template-handlebars": "^0.1.14", + "@ibizlab/template-model": "^0.1.15", "chokidar": "^3.5.3", "fs-extra": "^10.1.0", "qx-util": "^0.1.2" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 646cb531685d9b038369af6a42eeb59a4b1a9a7c..05f7088558e4d623b3a768169c5cc1407009f2fd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -77,7 +77,7 @@ importers: packages/cli: specifiers: - '@ibizlab/template': ^0.1.12 + '@ibizlab/template': ^0.1.13 chalk: 4.1.2 commander: ^9.4.0 fs-extra: ^10.1.0 @@ -99,7 +99,7 @@ importers: packages/generator: specifiers: - '@ibizlab/template-core': ^0.1.9 + '@ibizlab/template-core': ^0.1.13 fs-extra: ^10.1.0 glob: ^8.0.3 pluralize: ^8.0.0 @@ -115,7 +115,7 @@ importers: packages/handlebars: specifiers: - '@ibizlab/template-core': ^0.1.9 + '@ibizlab/template-core': ^0.1.13 handlebars: ^4.7.7 lodash: ^4.17.21 pluralize: ^8.0.0 @@ -129,14 +129,14 @@ importers: packages/model: specifiers: - '@ibizlab/model': ^0.0.26 - '@ibizlab/template-generator': ^0.1.11 + '@ibizlab/model': ^0.1.3 + '@ibizlab/template-generator': ^0.1.13 fs-extra: ^10.1.0 lodash: ^4.17.21 pluralize: ^8.0.0 qx-util: ^0.1.2 dependencies: - '@ibizlab/model': 0.0.26 + '@ibizlab/model': 0.1.3 '@ibizlab/template-generator': link:../generator fs-extra: 10.1.0 lodash: 4.17.21 @@ -145,10 +145,10 @@ importers: packages/template: specifiers: - '@ibizlab/template-core': ^0.1.9 - '@ibizlab/template-generator': ^0.1.11 - '@ibizlab/template-handlebars': ^0.1.11 - '@ibizlab/template-model': ^0.1.12 + '@ibizlab/template-core': ^0.1.13 + '@ibizlab/template-generator': ^0.1.13 + '@ibizlab/template-handlebars': ^0.1.13 + '@ibizlab/template-model': ^0.1.13 chokidar: ^3.5.3 fs-extra: ^10.1.0 qx-util: ^0.1.2 @@ -538,8 +538,8 @@ packages: engines: {node: '>=6.9.0'} dev: true - /@ibizlab/model/0.0.26: - resolution: {integrity: sha512-T3OZKSRpFsj9BQ6V03QPjkHNRXd7Pcc2WtpwZZZvhgwtX5fO7+gYotXJb2bX7e0aFgoVJVqGV4cGQA1RBr5pEA==} + /@ibizlab/model/0.1.3: + resolution: {integrity: sha512-sRpayDi86royeXXmodOLaz/NAalhgDy0OrfdovzSEWh4YRo709Qcvxjdmwf7pfxQFZH9Jpm4s6SGZBCsjTh8wQ==} dependencies: fs-extra: 10.1.0 qx-util: 0.1.2