Skip to content
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.

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

feat(vue-dsl): add app generate code #178

Merged
merged 37 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
06cebfa
feat(vue-dsl): add app generate code
chilingling Dec 2, 2023
d16a079
feat(vue-dsl): add app generate code
chilingling Dec 21, 2023
7153387
feat(vue-dsl): add generate global store code
chilingling Dec 26, 2023
1d96605
feat(vue-dsl): delete parse config and parse schema hook
chilingling Jan 23, 2024
3ee82bd
feat(tempalte): refra generateTemplate logic
chilingling Mar 9, 2024
69b7ccc
feat(vue-generator): add generate script frame code
chilingling Mar 11, 2024
ca4f8dd
feat(vue-generator): add hook flow for sfc file generate
chilingling Mar 12, 2024
a074cc1
feat(vue-generator): support generate sfc script
chilingling Mar 13, 2024
0e5b177
feat(vue-generator): support jsx generate
chilingling Mar 14, 2024
9731d13
fix(vue-generator): fix double quotes issue
chilingling Mar 16, 2024
e105463
feat(vue-generator): handle app generate code
chilingling Mar 18, 2024
1762a22
feat(toolbar-generate-vue): toolbar-generate-vue use new codegen func…
chilingling Mar 20, 2024
ea38b11
feat(vue-generator): add requiredBlock parser
chilingling Mar 21, 2024
0c35f5d
feat(docs): add readme doc
chilingling Mar 21, 2024
dbcfb39
feat(docs): add more docs
chilingling Mar 27, 2024
c8ca983
fix(vue-generator): adapt for more scenario
chilingling Mar 30, 2024
574f583
feat(vue-generator): support tiny-grid editor use tiny component
chilingling Apr 1, 2024
0e8c3c6
fix(vue-generator): complete unit test
chilingling Apr 3, 2024
81dc667
fix(vue-generator): add unit test
chilingling Apr 8, 2024
fa3674e
feat(vue-generator): add sfc generator unit test
chilingling Apr 8, 2024
d72a010
feat(vue-generator[docs]): add contributing docs
chilingling Apr 8, 2024
638c8cb
feat(vue-generator): add test coverage script and app generate test case
chilingling Apr 9, 2024
8ea749f
fix(generate-vue): optimize desc and file list
chilingling Apr 17, 2024
809aa71
fix(vue-generate): [template] fix viteConfig process.env is processed
chilingling Apr 17, 2024
fc32142
fix(vue-generator): escape process.env string
chilingling Apr 17, 2024
728f1f9
feat(vue-generator): support builtin components
chilingling Apr 17, 2024
3940bb0
fix(vue-generator): add builtin componentsMap
chilingling Apr 17, 2024
6a6df09
fix(vue-generator): fix bind utils props
chilingling Apr 18, 2024
65356fe
fix(vue-generator): support utils expression
chilingling Apr 18, 2024
655bae2
fix(vue-generator): support children expression add utils
chilingling Apr 18, 2024
1a074a5
fix(vue-generator): support nested folder page
chilingling Apr 19, 2024
4a726b5
fix(vue-generator): support get datasource with name
chilingling Apr 19, 2024
3a9a034
fix(vue-generator): only write necessary dependencies into package.json
chilingling Apr 23, 2024
9d98f68
feat(vue-generator): simplified genTemplate hooks
chilingling Apr 25, 2024
d3f5f13
fix(vue-generator): update vue-generator docs
chilingling Apr 25, 2024
973cf72
feat(vue-generator): detect jsx on custom method
chilingling May 7, 2024
267c02f
feat(vue-generator): add d.ts types declaration
chilingling May 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mockServer/src/mock/get/app-center/v1/apps/schema/918.json
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@
},
{
"componentName": "TinyPlusFrozenPage",
"package": "@opentiny/vuee",
"package": "@opentiny/vue",
"exportName": "FrozenPage",
"destructuring": true,
"version": "3.4.1"
Expand Down
1 change: 1 addition & 0 deletions packages/design-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@opentiny/tiny-engine-canvas": "workspace:*",
"@opentiny/tiny-engine-common": "workspace:*",
"@opentiny/tiny-engine-controller": "workspace:*",
"@opentiny/tiny-engine-dsl-vue": "workspace:*",
"@opentiny/tiny-engine-http": "workspace:*",
"@opentiny/tiny-engine-i18n-host": "workspace:*",
"@opentiny/tiny-engine-plugin-block": "workspace:*",
Expand Down
83 changes: 60 additions & 23 deletions packages/design-core/src/preview/src/preview/Preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import { defineComponent, computed, defineAsyncComponent } from 'vue'
import { Repl, ReplStore } from '@vue/repl'
import vueJsx from '@vue/babel-plugin-jsx'
import { transformSync } from '@babel/core'
import { Notify } from '@opentiny/vue'
import { genSFCWithDefaultPlugin, parseRequiredBlocks } from '@opentiny/tiny-engine-dsl-vue'
import importMap from './importMap'
import srcFiles from './srcFiles'
import generateMetaFiles, { processAppJsCode } from './generate'
import { getSearchParams, fetchCode, fetchMetaData } from './http'
import { getSearchParams, fetchMetaData, fetchAppSchema, fetchBlockSchema } from './http'
import { PanelType, PreviewTips } from '../constant'
import { injectDebugSwitch } from './debugSwitch'
import '@vue/repl/style.css'
Expand Down Expand Up @@ -71,31 +71,68 @@ export default {
const newImportMap = { imports: { ...importMap.imports, ...utilsImportMaps } }
store.setImportMap(newImportMap)
}
const getBlocksSchema = async (pageSchema, blockSet = new Set()) => {
let res = []

const blockNames = parseRequiredBlocks(pageSchema)
const promiseList = blockNames
.filter((name) => {
if (blockSet.has(name)) {
return false
}

blockSet.add(name)

return true
})
.map((name) => fetchBlockSchema(name))

const schemaList = await Promise.allSettled(promiseList)

schemaList.forEach((item) => {
if (item.status === 'fulfilled' && item.value?.[0]?.content) {
res.push(item.value[0].content)
res.push(...getBlocksSchema(item.value[0].content, blockSet))
}
})

return res
}

const queryParams = getSearchParams()

const promiseList = [fetchCode(queryParams), fetchMetaData(queryParams), setFiles(srcFiles, 'src/Main.vue')]
Promise.all(promiseList).then(([codeList, metaData]) => {
const promiseList = [
fetchAppSchema(queryParams?.app),
fetchMetaData(queryParams),
setFiles(srcFiles, 'src/Main.vue')
]
Promise.all(promiseList).then(async ([appData, metaData]) => {
addUtilsImportMap(metaData.utils || [])
const codeErrorMsgs = codeList
.filter(({ errors }) => errors?.length)
.map(({ errors }) => errors)
.flat()
.map(({ message }) => message)

if (codeErrorMsgs.length) {
const title = PreviewTips.ERROR_WHEN_COMPILE
Notify({
type: 'error',
title,
message: codeErrorMsgs.join('\n'),
// 不自动关闭
duration: 0,
position: 'top-right'
})

return title
}
const blocks = await getBlocksSchema(queryParams.pageInfo?.schema)

// TODO: 需要验证级联生成 block schema
// TODO: 物料内置 block 需要如何处理?
const pageCode = [
{
panelName: 'Main.vue',
panelValue:
genSFCWithDefaultPlugin(queryParams.pageInfo?.schema, appData?.componentsMap || [], {
blockRelativePath: './'
}) || '',
panelType: 'vue',
index: true
},
...(blocks || []).map((blockSchema) => {
return {
panelName: blockSchema.fileName,
panelValue:
genSFCWithDefaultPlugin(blockSchema, appData?.componentsMap || [], { blockRelativePath: './' }) || '',
panelType: 'vue',
index: true
}
})
]

// [@vue/repl] `Only lang="ts" is supported for <script> blocks.`
const langReg = /lang="jsx"/
Expand Down Expand Up @@ -143,7 +180,7 @@ export default {

newFiles['app.js'] = appJsCode

codeList.map(fixScriptLang).forEach(assignFiles)
pageCode.map(fixScriptLang).forEach(assignFiles)

const metaFiles = generateMetaFiles(metaData)
Object.assign(newFiles, metaFiles)
Expand Down
3 changes: 3 additions & 0 deletions packages/design-core/src/preview/src/preview/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ export const fetchMetaData = async ({ platform, app, type, id, history, tenant }
params: { platform, app, type, id, history }
})
: {}

export const fetchAppSchema = async (id) => http.get(`/app-center/v1/api/apps/schema/${id}`)
export const fetchBlockSchema = async (blockName) => http.get(`/material-center/api/block?label=${blockName}`)
65 changes: 65 additions & 0 deletions packages/design-core/src/preview/src/preview/srcFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,69 @@ srcFiles['locales.js'] = localesJS
srcFiles['stores.js'] = storesJS
srcFiles['storesHelper.js'] = storesHelperJS

export const genPreviewTemplate = () => {
return [
{
fileName: 'App.vue',
path: '',
fileContent: appVue
},
{
fileName: 'constant.js',
path: '',
fileContent: constantJS
},
{
fileName: 'app.js',
path: '',
fileContent: appJS.replace(/VITE_CDN_DOMAIN/g, import.meta.env.VITE_CDN_DOMAIN)
},
{
fileName: 'injectGlobal.js',
path: '',
fileContent: injectGlobalJS
},
{
fileName: 'lowcode.js',
path: '',
fileContent: lowcodeJS
},
{
fileName: 'dataSourceMap.js',
path: '',
fileContent: dataSourceMapJS
},
{
fileName: 'dataSource.js',
path: '',
fileContent: dataSourceJS
},
{
fileName: 'utils.js',
path: '',
fileContent: utilsJS
},
{
fileName: 'bridge.js',
path: '',
fileContent: bridgeJS
},
{
fileName: 'locales.js',
path: '',
fileContent: localesJS
},
{
fileName: 'stores.js',
path: '',
fileContent: storesJS
},
{
fileName: 'storesHelper.js',
path: '',
fileContent: storesHelperJS
}
]
}

export default srcFiles
1 change: 1 addition & 0 deletions packages/toolbars/generate-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"@opentiny/tiny-engine-canvas": "workspace:*",
"@opentiny/tiny-engine-controller": "workspace:*",
"@opentiny/tiny-engine-dsl-vue": "workspace:*",
"@opentiny/tiny-engine-http": "workspace:*",
"@opentiny/tiny-engine-utils": "workspace:*",
"prettier": "2.7.1"
Expand Down
25 changes: 20 additions & 5 deletions packages/toolbars/generate-vue/src/FileSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,30 @@ export default {
emits: ['cancel', 'confirm'],
setup(props, { emit }) {
const getTableTreeData = (data) => {
const dataMap = {}
const res = []
data.forEach((item) => {
if (!dataMap[item.fileType]) {
dataMap[item.fileType] = { fileType: item.fileType, children: [] }
const folder = item.filePath.split('/').slice(0, -1)

if (!folder.length) {
res.push(item)
return
}
dataMap[item.fileType].children.push(item)

const parentFolder = folder.reduce((parent, curPath) => {
let curItem = parent.find((parItem) => parItem.path === curPath)

if (!curItem) {
curItem = { path: curPath, filePath: curPath, children: [] }
parent.push(curItem)
}

return curItem.children
}, res)

parentFolder.push(item)
})

return Object.values(dataMap)
return res
}

const tableData = computed(() => getTableTreeData(props.data))
Expand Down
Loading
Loading