Skip to content

Commit 7716dda

Browse files
chilinglinghexqi
andauthored
feat: blockCompiler (opentiny#906)
* feat: blockCompiler * feat: block compile to blobURL * feat: block-compiler * fix: add dev alias * fix: del unnecessary comments * feat: del old block web component logic * fix: scope id error * feat: del umd block support * feat: del block deploy progress bar * feat: del block progress request * fix: del customElement relative logic * feat: add block loading and error status view * fix: select blockSchema by historyid * fix: block schema should select by version * feat: add block compile cache * fix: add source code cache * fix: add default material import map * feat: update builtin-component version * feat(block-compiler): support compile jsx * feat: support block compileCache * feat: update block version slient refresh * fix: update @vue/babel-plusin-jsx version * fix: type checking * fix: typescript build error * fix: imporve type checking * feat: use new block compile cache realize * fix(block-compiler): remove deps order check * fix: use has method check the specified key exists in the map instead of get method * fix: optimize deps * fix: update cache name params --------- Co-authored-by: hexqi <[email protected]>
1 parent cff74bb commit 7716dda

Some content is hidden

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

45 files changed

+1153
-437
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const path = require('path')
2+
const { rules } = require('../../.eslintrc')
3+
4+
module.exports = {
5+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
6+
root: true,
7+
parser: '@typescript-eslint/parser',
8+
parserOptions: {
9+
projectService: true,
10+
project: [path.join(__dirname, './tsconfig.json') ],
11+
ecmaVersion: 'latest',
12+
},
13+
plugins: ['@typescript-eslint'],
14+
env: {
15+
browser: true,
16+
es2015: true,
17+
node: true
18+
},
19+
rules: {
20+
...rules,
21+
// 允许 @ts-ignore
22+
"@typescript-eslint/ban-ts-comment": "off",
23+
// 允许非空断言
24+
"@typescript-eslint/no-non-null-asserted-optional-chain": "off"
25+
},
26+
ignorePatterns: ['test/sample/*.vue', '.eslintrc.cjs']
27+
}

packages/block-compiler/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# @opentiny/tiny-engine 低代码引擎区编译器
2+

packages/block-compiler/index.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>block-compiler</title>
7+
<link rel="stylesheet" href="https://unpkg.com/@opentiny/[email protected]/index.css" />
8+
<script type="importmap">
9+
{
10+
"imports": {
11+
"vue": "https://unpkg.com/[email protected]/dist/vue.runtime.esm-browser.js",
12+
"vue/server-renderer": "https://unpkg.com/@vue/[email protected]/dist/server-renderer.esm-browser.js",
13+
"vue-i18n": "https://unpkg.com/[email protected]/dist/vue-i18n.esm-browser.js",
14+
"vue-router": "https://unpkg.com/[email protected]/dist/vue-router.esm-browser.js",
15+
"@vue/devtools-api": "https://unpkg.com/@vue/[email protected]/lib/esm/index.js",
16+
"@vueuse/core": "https://unpkg.com/@vueuse/[email protected]/index.mjs",
17+
"@vueuse/shared": "https://unpkg.com/@vueuse/[email protected]/index.mjs",
18+
"axios": "https://unpkg.com/[email protected]/dist/esm/axios.js",
19+
"@opentiny/tiny-engine-i18n-host": "https://unpkg.com/@opentiny/tiny-engine-i18n-host@1/dist/lowcode-design-i18n-host.es.js",
20+
"@opentiny/tiny-engine-builtin-component": "https://unpkg.com/@opentiny/tiny-engine-builtin-component@^2.0.0/dist/index.js",
21+
"pinia": "https://unpkg.com/[email protected]/dist/pinia.esm-browser.js",
22+
"@opentiny/vue": "https://unpkg.com/@opentiny/[email protected]/runtime/tiny-vue.mjs",
23+
"@opentiny/vue-icon": "https://unpkg.com/@opentiny/[email protected]/runtime/tiny-vue-icon.mjs",
24+
"@opentiny/vue-common": "https://unpkg.com/@opentiny/[email protected]/runtime/tiny-vue-common.mjs",
25+
"@opentiny/vue-locale": "https://unpkg.com/@opentiny/[email protected]/runtime/tiny-vue-locale.mjs",
26+
"@opentiny/vue-renderless/": "https://unpkg.com/@opentiny/[email protected]/"
27+
}
28+
}
29+
</script>
30+
</head>
31+
<body>
32+
<div id="app"></div>
33+
<script type="module" src="./src/dev.ts"></script>
34+
</body>
35+
</html>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "@opentiny/tiny-engine-block-compiler",
3+
"version": "2.0.0-rc.2",
4+
"publishConfig": {
5+
"access": "public"
6+
},
7+
"description": "block runtime compiler",
8+
"scripts": {
9+
"dev": "vite",
10+
"build": "vite build"
11+
},
12+
"files": [
13+
"dist"
14+
],
15+
"type": "module",
16+
"main": "dist/index.js",
17+
"module": "dist/index.js",
18+
"types": "dist/index.d.ts",
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/opentiny/tiny-engine",
22+
"directory": "packages/block-compiler"
23+
},
24+
"bugs": {
25+
"url": "https://github.com/opentiny/tiny-engine/issues"
26+
},
27+
"author": "OpenTiny Team",
28+
"license": "MIT",
29+
"homepage": "https://opentiny.design/tiny-engine",
30+
"dependencies": {},
31+
"devDependencies": {
32+
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
33+
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
34+
"@types/babel__core": "^7.20.5",
35+
"@typescript-eslint/eslint-plugin": "^8.14.0",
36+
"@typescript-eslint/parser": "^8.14.0",
37+
"@vitejs/plugin-vue": "^5.1.2",
38+
"eslint": "^8.38.0",
39+
"typescript": "~5.4.2",
40+
"vite": "^5.4.2",
41+
"vite-plugin-dts": "^4.3.0"
42+
},
43+
"peerDependencies": {
44+
"@babel/core": "^7.26.0",
45+
"@vue/babel-plugin-jsx": "^1.2.5",
46+
"vue": "^3.4.15",
47+
"@vue/compiler-sfc": "^3.4.15"
48+
}
49+
}

packages/block-compiler/src/dev.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// @ts-ignore
2+
import { createApp, defineAsyncComponent, h } from 'https://unpkg.com/[email protected]/dist/vue.runtime.esm-browser.js'
3+
import { compile } from './index'
4+
import BlockFileName from '../test/sample/BlockFileName.vue?raw'
5+
import BlockHead from '../test/sample/BlockHead.vue?raw'
6+
import BlockMenu from '../test/sample/BlockMenu.vue?raw'
7+
import BlockTest from '../test/sample/BlockTest.vue?raw'
8+
import BlockJsxTest from '../test/sample/slotModelValueTest.vue?raw'
9+
10+
const RenderMain = {
11+
setup() {
12+
const componentMap = compile(
13+
[
14+
{
15+
fileName: 'BlockHead',
16+
sourceCode: BlockHead
17+
},
18+
{
19+
fileName: 'BlockFileName',
20+
sourceCode: BlockFileName
21+
},
22+
{
23+
fileName: 'BlockMenu',
24+
sourceCode: BlockMenu
25+
},
26+
{
27+
fileName: 'BlockTest',
28+
sourceCode: BlockTest
29+
},
30+
{
31+
fileName: 'BlockJsxTest',
32+
sourceCode: BlockJsxTest
33+
}
34+
],
35+
{}
36+
)
37+
38+
const blockComponents: { [key: string]: unknown } = {}
39+
40+
// @ts-ignore
41+
window.getBlockComponentBlobUrl = (name) => {
42+
return componentMap?.[name]?.blobURL
43+
}
44+
45+
for (const [fileName, value] of Object.entries(componentMap)) {
46+
blockComponents[fileName] = defineAsyncComponent(() => import(/* @vite-ignore */ value.blobURL))
47+
}
48+
49+
const css = Object.values(componentMap)
50+
.map((item) => item.style)
51+
.join('')
52+
53+
const stylesheet = document.querySelector('#block-stylesheet')
54+
55+
if (stylesheet) {
56+
stylesheet.remove()
57+
} else {
58+
const newStyleSheet = document.createElement('style')
59+
60+
newStyleSheet.innerHTML = css
61+
62+
document.head.appendChild(newStyleSheet)
63+
}
64+
65+
return () =>
66+
h('div', {}, [
67+
h(blockComponents.BlockJsxTest),
68+
h(blockComponents.BlockTest),
69+
h(blockComponents.BlockHead),
70+
h(blockComponents.BlockFileName),
71+
h('span', {}, 'testtest')
72+
])
73+
}
74+
}
75+
76+
const App = createApp(RenderMain)
77+
78+
App.mount(document.querySelector('#app')!)

0 commit comments

Comments
 (0)