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: blockCompiler #906

Draft
wants to merge 16 commits into
base: refactor/develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions packages/block-compiler/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { rules } = require('../../.eslintrc')

module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['./tsconfig.json'],
ecmaVersion: 'latest',
},
plugins: ['@typescript-eslint'],
env: {
browser: true,
es2015: true,
node: true
},
rules,
ignorePatterns: ['test/sample/*.vue']
}
2 changes: 2 additions & 0 deletions packages/block-compiler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 区块浏览器编译器

35 changes: 35 additions & 0 deletions packages/block-compiler/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>block-compiler</title>
<link rel="stylesheet" href="https://unpkg.com/@opentiny/[email protected]/index.css" />
<script type="importmap">
{
"imports": {
"vue": "https://unpkg.com/[email protected]/dist/vue.runtime.esm-browser.js",
"vue/server-renderer": "https://unpkg.com/@vue/[email protected]/dist/server-renderer.esm-browser.js",
"vue-i18n": "https://unpkg.com/[email protected]/dist/vue-i18n.esm-browser.js",
"vue-router": "https://unpkg.com/[email protected]/dist/vue-router.esm-browser.js",
"@vue/devtools-api": "https://unpkg.com/@vue/[email protected]/lib/esm/index.js",
"@vueuse/core": "https://unpkg.com/@vueuse/[email protected]/index.mjs",
"@vueuse/shared": "https://unpkg.com/@vueuse/[email protected]/index.mjs",
"axios": "https://unpkg.com/[email protected]/dist/esm/axios.js",
"@opentiny/tiny-engine-i18n-host": "https://unpkg.com/@opentiny/tiny-engine-i18n-host@1/dist/lowcode-design-i18n-host.es.js",
"@opentiny/tiny-engine-builtin-component": "https://unpkg.com/@opentiny/tiny-engine-builtin-component@1/dist/index.js",
"pinia": "https://unpkg.com/[email protected]/dist/pinia.esm-browser.js",
"@opentiny/vue": "https://unpkg.com/@opentiny/[email protected]/runtime/tiny-vue.mjs",
"@opentiny/vue-icon": "https://unpkg.com/@opentiny/[email protected]/runtime/tiny-vue-icon.mjs",
"@opentiny/vue-common": "https://unpkg.com/@opentiny/[email protected]/runtime/tiny-vue-common.mjs",
"@opentiny/vue-locale": "https://unpkg.com/@opentiny/[email protected]/runtime/tiny-vue-locale.mjs",
"@opentiny/vue-renderless/": "https://unpkg.com/@opentiny/[email protected]/"
}
}
</script>
</head>
<body>
<div id="app"></div>
<script type="module" src="./src/dev.ts"></script>
</body>
</html>
47 changes: 47 additions & 0 deletions packages/block-compiler/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@opentiny/tiny-engine-block-compiler",
"version": "2.0.0-rc.2",
"publishConfig": {
"access": "public"
},
"description": "block runtime compiler",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"files": [
"dist"
],
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"repository": {
"type": "git",
"url": "https://github.com/opentiny/tiny-engine",
"directory": "packages/block-compiler"
},
"bugs": {
"url": "https://github.com/opentiny/tiny-engine/issues"
},
"author": "OpenTiny Team",
"license": "MIT",
"homepage": "https://opentiny.design/tiny-engine",
"dependencies": {
"@vue/shared": "^3.3.4"
},
"devDependencies": {
"@opentiny/tiny-engine-common": "workspace:*",
"@opentiny/tiny-engine-meta-register": "workspace:*",
"@typescript-eslint/eslint-plugin": "^8.14.0",
"@typescript-eslint/parser": "^8.14.0",
"@vitejs/plugin-vue": "^5.1.2",
"eslint": "8",
"typescript": "~5.6.2",
"vite": "^5.4.2",
"vite-plugin-dts": "^4.3.0",
"vue-tsc": "^2.1.8"
},
"peerDependencies": {
"vue": "^3.4.15"
}
}
76 changes: 76 additions & 0 deletions packages/block-compiler/src/dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// @ts-ignore
import { createApp, defineAsyncComponent, h } from 'https://unpkg.com/[email protected]/dist/vue.runtime.esm-browser.js'
import { compile } from './index'
import BlockFileName from '../test/sample/BlockFileName.vue?raw'
import BlockHead from '../test/sample/BlockHead.vue?raw'
import BlockMenu from '../test/sample/BlockMenu.vue?raw'
import BlockTest from '../test/sample/BlockTest.vue?raw'

const RenderMain = {
setup() {
const componentMap = compile(
[
{
fileName: 'BlockHead',
sourceCode: BlockHead
},
{
fileName: 'BlockFileName',
sourceCode: BlockFileName
},
{
fileName: 'BlockMenu',
sourceCode: BlockMenu
},
{
fileName: 'BlockTest',
sourceCode: BlockTest
}
],
{}
)

const blockComponents: { [key: string]: any } = {}

for (const [fileName, value] of Object.entries(componentMap)) {
blockComponents[fileName] = defineAsyncComponent(() => import(value.blobURL))
}

const css = Object.values(componentMap)
.map((item) => item.style)
.join('')

const stylesheet = document.querySelector('#block-stylesheet')

if (stylesheet) {
stylesheet.remove()
} else {
const newStyleSheet = document.createElement('style')

newStyleSheet.innerHTML = css

document.head.appendChild(newStyleSheet)
}

return {
componentMap,
blockComponents
}
},
// @ts-ignore
render() {
// @ts-ignore
const { blockComponents } = this

return h('div', {}, [
h(blockComponents.BlockTest),
h(blockComponents.BlockHead),
h(blockComponents.BlockFileName),
h('span', {}, 'testtest')
])
}
}

const App = createApp(RenderMain)

App.mount(document.querySelector('#app')!)
Loading