Skip to content

Commit f2859a1

Browse files
committed
Merge branch 'develop' of https://github.com/betterdancing/tiny-engine into feat/chart-options-configurator
2 parents 7337def + a926b80 commit f2859a1

File tree

14 files changed

+258
-30
lines changed

14 files changed

+258
-30
lines changed

.github/workflows/deploy-cdn.yml

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
name: Deploy to CDN
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
is_latest_release:
7+
description: '当前分支是否是最新release版本'
8+
required: true
9+
default: true
10+
type: boolean
11+
12+
env:
13+
HUAWEI_CLOUD_AK: ${{ secrets.HUAWEI_CLOUD_AK }}
14+
HUAWEI_CLOUD_SK: ${{ secrets.HUAWEI_CLOUD_SK }}
15+
HUAWEI_CLOUD_ENDPOINT: ${{ secrets.HUAWEI_CLOUD_ENDPOINT }}
16+
HUAWEI_CLOUD_BUCKET: ${{ secrets.HUAWEI_CLOUD_BUCKET }}
17+
18+
jobs:
19+
check-secrets:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
secrets-ready: ${{ steps.check.outputs.secrets-ready }}
23+
steps:
24+
- name: Check required secrets
25+
id: check
26+
run: |
27+
if [[ -z "${{ secrets.HUAWEI_CLOUD_AK }}" ]] || \
28+
[[ -z "${{ secrets.HUAWEI_CLOUD_SK }}" ]] || \
29+
[[ -z "${{ secrets.HUAWEI_CLOUD_ENDPOINT }}" ]] || \
30+
[[ -z "${{ secrets.HUAWEI_CLOUD_BUCKET }}" ]]; then
31+
echo "secrets-ready=false" >> $GITHUB_OUTPUT
32+
echo "::error::Required Huawei Cloud secrets are not configured."
33+
echo "::error::Please set: HUAWEI_CLOUD_AK, HUAWEI_CLOUD_SK, HUAWEI_CLOUD_ENDPOINT, HUAWEI_CLOUD_BUCKET"
34+
exit 1
35+
fi
36+
echo "secrets-ready=true" >> $GITHUB_OUTPUT
37+
echo "✅ All required secrets are configured"
38+
39+
build:
40+
runs-on: ubuntu-latest
41+
needs: check-secrets
42+
outputs:
43+
version-timestamp: ${{ steps.prepare-version.outputs.version_timestamp }}
44+
cdn-base: ${{ steps.prepare-version.outputs.cdn_base }}
45+
cdn-base-latest: ${{ steps.prepare-version.outputs.cdn_base_latest }}
46+
obs-path: ${{ steps.prepare-version.outputs.obs_path }}
47+
obs-path-latest: ${{ steps.prepare-version.outputs.obs_path_latest }}
48+
concurrency:
49+
group: deploy-cdn
50+
cancel-in-progress: true
51+
steps:
52+
- name: Checkout
53+
uses: actions/checkout@v4
54+
55+
- name: Install pnpm
56+
uses: pnpm/action-setup@v4
57+
with:
58+
version: 10
59+
run_install: false
60+
61+
- name: Setup Node.js
62+
uses: actions/setup-node@v4
63+
with:
64+
node-version: '20'
65+
registry-url: 'https://registry.npmjs.org'
66+
67+
- name: Install dependencies
68+
run: pnpm install
69+
70+
- name: add environment variable
71+
run: |
72+
VITE_ORIGIN_URL="https://agent.opentiny.design/"
73+
cat <<EOF >> designer-demo/env/.env.alpha
74+
# ---- appended by CI (deploy-cdn) ----
75+
VITE_ORIGIN=$VITE_ORIGIN_URL
76+
EOF
77+
echo "VITE_ORIGIN_URL=$VITE_ORIGIN_URL"
78+
79+
- id: prepare-version
80+
name: Prepare version-timestamp
81+
run: |
82+
# Extract version from package.json
83+
VERSION=$(node -p "require('./designer-demo/package.json').version")
84+
85+
# Generate timestamp in YYYYMMDD-HHMMSS format
86+
TIMESTAMP=$(TZ="Asia/Shanghai" date +%Y%m%d-%H%M%S)
87+
88+
# Combine for version-timestamp
89+
VERSION_TIMESTAMP="${VERSION}-${TIMESTAMP}"
90+
91+
# Set CDN base path
92+
CDN_BASE="https://res-static.opentiny.design/tiny-engine-designer/${VERSION_TIMESTAMP}/"
93+
CDN_BASE_LATEST="https://res-static.opentiny.design/tiny-engine-designer/latest/"
94+
OBS_PATH="tiny-engine-designer/${VERSION_TIMESTAMP}/"
95+
OBS_PATH_LATEST="tiny-engine-designer/latest"
96+
97+
# Export as environment variables for subsequent steps
98+
echo "VERSION_TIMESTAMP=$VERSION_TIMESTAMP" >> $GITHUB_ENV
99+
echo "CDN_BASE=$CDN_BASE" >> $GITHUB_ENV
100+
echo "OBS_PATH=$OBS_PATH" >> $GITHUB_ENV
101+
102+
# Set outputs for job-level export
103+
echo "version_timestamp=$VERSION_TIMESTAMP" >> $GITHUB_OUTPUT
104+
echo "cdn_base=$CDN_BASE" >> $GITHUB_OUTPUT
105+
echo "cdn_base_latest=$CDN_BASE_LATEST" >> $GITHUB_OUTPUT
106+
echo "obs_path=$OBS_PATH" >> $GITHUB_OUTPUT
107+
echo "obs_path_latest=$OBS_PATH_LATEST" >> $GITHUB_OUTPUT
108+
109+
echo "Version-Timestamp: $VERSION_TIMESTAMP"
110+
echo "CDN Base: $CDN_BASE"
111+
echo "OBS Path: $OBS_PATH"
112+
113+
- name: Run Build
114+
run: |
115+
set -eo pipefail
116+
pnpm run build:plugin 2>&1 | tee /tmp/build-plugin.log
117+
# Run build:alpha equivalent with --base parameter
118+
pnpm run build:alpha --base=${{ env.CDN_BASE }} 2>&1 | tee /tmp/build-alpha.log
119+
120+
- name: Upload build artifacts
121+
uses: actions/upload-artifact@v4
122+
with:
123+
name: designer-demo-dist
124+
path: ./designer-demo/dist/
125+
retention-days: 1
126+
127+
deploy-cdn:
128+
runs-on: ubuntu-latest
129+
needs: [check-secrets, build]
130+
steps:
131+
- name: Checkout
132+
uses: actions/checkout@v4
133+
134+
- name: Download build artifacts
135+
uses: actions/download-artifact@v4
136+
with:
137+
name: designer-demo-dist
138+
path: ./designer-demo/dist/
139+
140+
- name: Install obsutil
141+
run: |
142+
curl -o obsutil.tar.gz https://obs-community.obs.cn-north-1.myhuaweicloud.com/obsutil/current/obsutil_linux_amd64.tar.gz
143+
tar -xzf obsutil.tar.gz
144+
chmod +x obsutil_linux_amd64_*/obsutil
145+
sudo mv obsutil_linux_amd64_*/obsutil /usr/local/bin/obsutil
146+
147+
- name: Configure and Upload to OBS
148+
run: |
149+
obsutil config -i=${{ env.HUAWEI_CLOUD_AK }} \
150+
-k=${{ env.HUAWEI_CLOUD_SK }} \
151+
-e=${{ env.HUAWEI_CLOUD_ENDPOINT }}
152+
# Upload to versioned path
153+
obsutil cp ./designer-demo/dist \
154+
obs://${{ env.HUAWEI_CLOUD_BUCKET }}/${{ needs.build.outputs.obs-path }} \
155+
-r -f -flat
156+
157+
# If is_latest_release is true, also upload to latest path
158+
if [ "${{ github.event.inputs.is_latest_release }}" = "true" ]; then
159+
# use cdn-base-latest replace cdn-base in all ./designer-demo/dist files
160+
find ./designer-demo/dist -type f \( -name "*.html" -o -name "*.js" -o -name "*.mjs" -o -name "*.css" \) \
161+
-exec sed -i "s|${{ needs.build.outputs.cdn-base }}|${{ needs.build.outputs.cdn-base-latest }}|g" {} +
162+
obsutil cp ./designer-demo/dist \
163+
obs://${{ env.HUAWEI_CLOUD_BUCKET }}/${{ needs.build.outputs.obs-path-latest }} \
164+
-r -f -flat
165+
fi
166+
167+
echo "Uploaded to: obs://${{ env.HUAWEI_CLOUD_BUCKET }}/${{ needs.build.outputs.obs-path }}"
168+
echo "CDN URL: https://res-static.opentiny.design/${{ needs.build.outputs.obs-path }}"

packages/canvas/render/src/RenderMain.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ export default defineComponent({
172172
() => activeSchema.css,
173173
(value) => {
174174
setPageCss(value)
175-
}
175+
},
176+
{ deep: true }
176177
)
177178

178179
const utilsWatchCanceler = window.host.watch(

packages/canvas/render/src/material-function/page-getter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { defineComponent, h, ref, onMounted } from 'vue'
22
import { getController } from '../canvas-function'
33
import RenderMain from '../RenderMain'
44
import { handleScopedCss } from './handle-scoped-css'
5+
import { utils } from '@opentiny/tiny-engine-utils'
56

7+
const { objectCssToString } = utils
68
const pageSchema: Record<string, any> = {}
79

810
async function fetchPageSchema(pageId: string) {
@@ -16,7 +18,7 @@ async function fetchPageSchema(pageId: string) {
1618
// tailwindcss function and directive 特性需要使用 <style type="text/tailwindcss"> 标签
1719
// https://tailwindcss.com/docs/functions-and-directives
1820
// 所以原来 new CSSStyleSheet 的方式改成了 document.createElement('style') 的方式
19-
export function initStyle(key: string, content: string) {
21+
export function initStyle(key: string, content: string | object) {
2022
if (!content) {
2123
return
2224
}
@@ -32,7 +34,7 @@ export function initStyle(key: string, content: string) {
3234
document.head.appendChild(styleSheet)
3335
}
3436

35-
handleScopedCss(key, content).then((scopedCss) => {
37+
handleScopedCss(key, objectCssToString(content)).then((scopedCss) => {
3638
styleSheet.textContent = scopedCss.css
3739
})
3840
}

packages/design-core/src/preview/src/previewDefaultRegistry.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212

1313
import { GenerateCodeService, Breadcrumb, Media, Lang, HttpService } from '../../../re-export'
14+
const isDevelopEnv = import.meta.env.MODE?.includes('dev')
15+
const useAuth = import.meta.env.VITE_AUTH === 'true'
1416

1517
export default {
1618
root: {
@@ -87,7 +89,8 @@ export default {
8789
oppositeTheme: 'light'
8890
}
8991
],
90-
enableTailwindCSS: true
92+
enableTailwindCSS: true,
93+
enableLogin: useAuth || !isDevelopEnv
9194
},
9295
toolbars: [Breadcrumb, Media, Lang]
9396
}

packages/plugins/block/src/BlockSetting.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ export default {
252252
page_content: item.content,
253253
id: item.blockId || item.block_id,
254254
history: item.id,
255-
name: item.label
255+
name: item.label,
256+
previewType: 'page'
256257
},
257258
true
258259
)

packages/plugins/page/src/PageHistory.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export default {
5757
const params = {
5858
...item,
5959
id: Number(item.page),
60-
history: item.id
60+
history: item.id,
61+
previewType: 'page'
6162
}
6263
params.ancestors = await getFamily(params)
6364
previewPage(params, true)

packages/plugins/page/src/composable/usePage.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,31 @@ export interface MaterialsOptions {
115115
}
116116

117117
const generateCssString = (pageOptions: PageOptions, materialsOptions: MaterialsOptions) => {
118-
if (!pageOptions?.pageBaseStyle?.className || !pageOptions?.pageBaseStyle?.style) {
119-
return ''
118+
let cssObject: Record<string, any> = {}
119+
const parseStyle = (styleString: string) => {
120+
const styleObj: Record<string, string> = {}
121+
const styleItems = styleString.split(';')
122+
styleItems.forEach((item: string) => {
123+
if (item) {
124+
const stylekeyValue = item.split(':')
125+
styleObj[stylekeyValue[0].trim()] = stylekeyValue[1].trim()
126+
}
127+
})
128+
return styleObj
129+
}
130+
if (pageOptions?.pageBaseStyle?.className && pageOptions?.pageBaseStyle?.style) {
131+
cssObject[`.${pageOptions.pageBaseStyle.className}`] = parseStyle(pageOptions.pageBaseStyle.style)
120132
}
121133

122-
const formatCssRule = (className: string, style: string) => `.${className} {\n ${style.trim()}\n}\n`
123-
const baseStyle = `.${pageOptions.pageBaseStyle.className}{\r\n ${pageOptions.pageBaseStyle.style}\r\n}\r\n`
124-
125-
if (!materialsOptions.useBaseStyle) {
126-
return baseStyle
134+
if (materialsOptions.useBaseStyle) {
135+
cssObject = {
136+
...cssObject,
137+
[`.${materialsOptions.blockBaseStyle.className}`]: parseStyle(materialsOptions.blockBaseStyle.style),
138+
[`.${materialsOptions.componentBaseStyle.className}`]: parseStyle(materialsOptions.componentBaseStyle.style)
139+
}
127140
}
128141

129-
return [
130-
formatCssRule(pageOptions.pageBaseStyle.className, pageOptions.pageBaseStyle.style),
131-
formatCssRule(materialsOptions.blockBaseStyle.className, materialsOptions.blockBaseStyle.style),
132-
formatCssRule(materialsOptions.componentBaseStyle.className, materialsOptions.componentBaseStyle.style)
133-
].join('\n')
142+
return cssObject
134143
}
135144

136145
const getDefaultPage = () => {

packages/plugins/robot/src/composables/features/useToolCalls.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const callTools = async (tool_calls: any, hooks: CallToolHooks, signal: A
3535
const result = []
3636
for (const tool of tool_calls) {
3737
const { name, arguments: args } = tool.function
38-
const parsedArgs = parseArgs(args)
38+
const parsedArgs = parseArgs(args) ?? {}
3939
tool.parsedArgs = parsedArgs
4040
tool.name = name
4141

packages/settings/styles/src/components/classNamesContainer/index.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ import { Select as TinySelect } from '@opentiny/vue'
108108
import { useProperties, useCanvas, useHistory, useHelp } from '@opentiny/tiny-engine-meta-register'
109109
import { LinkButton } from '@opentiny/tiny-engine-common'
110110
import { CodeConfigurator } from '@opentiny/tiny-engine-configurator'
111-
import { formatString } from '@opentiny/tiny-engine-common/js/ast'
112111
import useStyle, { updateGlobalStyleStr } from '../../js/useStyle'
113-
import { stringify, getSelectorArr } from '../../js/parser'
112+
import { stringify, getSelectorArr, parser } from '../../js/parser'
114113
115114
const { getSchema, propsUpdateKey, setProp } = useProperties()
116115
@@ -449,14 +448,17 @@ watchEffect(() => {
449448
})
450449
451450
const save = ({ content }) => {
452-
const cssString = formatString(content.replace(/"/g, "'"), 'css')
451+
const { styleObject } = parser(content)
452+
const cssObject = {}
453+
for (const styleKey in styleObject) {
454+
cssObject[styleKey] = styleObject[styleKey].rules
455+
}
453456
const { addHistory } = useHistory()
454457
const { updateRect } = useCanvas().canvasApi.value
455458
const { updateSchema } = useCanvas()
456459
457-
updateSchema({ css: cssString })
460+
updateSchema({ css: cssObject })
458461
state.schemaUpdateKey++
459-
460462
addHistory()
461463
updateRect()
462464
}

packages/settings/styles/src/js/useStyle.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { constants, utils } from '@opentiny/tiny-engine-utils'
1818
import { parser, stringify, getSelectorArr } from './parser'
1919

2020
const { EXPRESSION_TYPE } = constants
21-
const { generateRandomLetters, parseExpression } = utils
21+
const { generateRandomLetters, parseExpression, objectCssToString } = utils
2222

2323
const state = reactive({
2424
// 当前选中节点的 style,解析成对象返回
@@ -177,10 +177,10 @@ export const initStylePanelWatch = () => {
177177
watch(
178178
() => useCanvas().getPageSchema?.()?.css,
179179
(value) => {
180-
state.cssContent = value || ''
180+
state.cssContent = objectCssToString(value) || ''
181181

182182
// 解析css
183-
const { parseList, selectors, styleObject } = parser(value)
183+
const { parseList, selectors, styleObject } = parser(state.cssContent)
184184

185185
state.cssParseList = parseList
186186
state.selectors = selectors

0 commit comments

Comments
 (0)