diff --git a/packages/engine-cli/template/designer/package.json b/packages/engine-cli/template/designer/package.json index 42ac898df..ac5e9b188 100644 --- a/packages/engine-cli/template/designer/package.json +++ b/packages/engine-cli/template/designer/package.json @@ -1,20 +1,20 @@ { - "name": "designer-demo-template", + "name": "designer-demo", "private": true, "version": "0.0.0", "type": "module", "scripts": { "dev": "concurrently 'pnpm:serve:mock' 'pnpm:serve:frontend'", - "serve:frontend": "cross-env VITE_THEME=light vite", - "serve:mock": "node node_modules/@opentiny/tiny-engine-mock/dist/app.js", "build:alpha": "cross-env NODE_OPTIONS=--max-old-space-size=8192 VITE_THEME=light vite build --mode alpha", - "build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 VITE_THEME=light vite build --mode prod" + "build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 VITE_THEME=light vite build --mode prod", + "serve:frontend": "cross-env VITE_THEME=light vite", + "serve:mock": "node node_modules/@opentiny/tiny-engine-mock/dist/app.js" }, "dependencies": { - "@opentiny/tiny-engine": "^2.1.0", - "@opentiny/tiny-engine-theme-dark": "^2.1.0", - "@opentiny/tiny-engine-theme-light": "^2.1.0", - "@opentiny/tiny-engine-utils": "^2.1.0", + "@opentiny/tiny-engine": "2.2.0-rc.0", + "@opentiny/tiny-engine-theme-dark": "2.2.0-rc.0", + "@opentiny/tiny-engine-theme-light": "2.2.0-rc.0", + "@opentiny/tiny-engine-utils": "2.2.0-rc.0", "@opentiny/vue": "~3.14.0", "@opentiny/vue-design-smb": "~3.14.0", "@opentiny/vue-icon": "~3.14.0", @@ -25,11 +25,11 @@ "vue": "^3.4.21" }, "devDependencies": { - "@opentiny/tiny-engine-mock": "^2.1.0", - "@opentiny/tiny-engine-vite-config": "^2.1.0", + "@opentiny/tiny-engine-mock": "2.2.0-rc.0", + "@opentiny/tiny-engine-vite-config": "2.2.0-rc.0", "@vitejs/plugin-vue": "^5.1.2", "cross-env": "^7.0.3", - "concurrently": "^8.2.0", - "vite": "^5.4.2" + "vite": "^5.4.2", + "concurrently": "^8.2.0" } } diff --git a/packages/engine-cli/template/designer/registry.js b/packages/engine-cli/template/designer/registry.js index 41a914705..2e2fcacb1 100644 --- a/packages/engine-cli/template/designer/registry.js +++ b/packages/engine-cli/template/designer/registry.js @@ -101,7 +101,20 @@ export default { Lang, ViewSetting ], - plugins: [Materials, Tree, Page, Block, Datasource, Bridge, I18n, Script, State, Schema, Help, Robot], + plugins: [ + Materials, + Tree, + Page, + [Block, { options: { ...Block.options, mergeCategoriesAndGroups: true } }], + Datasource, + Bridge, + I18n, + Script, + State, + Schema, + Help, + Robot + ], dsls: [{ id: 'engine.dsls.dslvue' }], settings: [Props, Styles, Events], canvas: Canvas diff --git a/packages/engine-cli/template/designer/vite.config.js b/packages/engine-cli/template/designer/vite.config.js index 9dd2864eb..f90c69aff 100644 --- a/packages/engine-cli/template/designer/vite.config.js +++ b/packages/engine-cli/template/designer/vite.config.js @@ -7,6 +7,7 @@ export default defineConfig((configEnv) => { viteConfigEnv: configEnv, root: __dirname, iconDirs: [path.resolve(__dirname, './node_modules/@opentiny/tiny-engine/assets/')], + useSourceAlias: false, envDir: './env' }) diff --git a/scripts/updateTemplate.mjs b/scripts/updateTemplate.mjs new file mode 100644 index 000000000..96830e9cd --- /dev/null +++ b/scripts/updateTemplate.mjs @@ -0,0 +1,106 @@ +import fs from 'fs-extra' +import path from 'node:path' +import { fileURLToPath } from 'node:url' +import Logger from './logger.mjs' +import pkg from '../packages/design-core/package.json' assert { type: 'json' } + +const logger = new Logger('updateTemplate') + +const __filename = fileURLToPath(import.meta.url) +const __dirname = path.dirname(__filename) + +const templateSrcPath = path.resolve(__dirname, '../designer-demo') +const templateDistPath = path.resolve(__dirname, '../packages/engine-cli/template/designer') + +const ignoreFolder = ['node_modules', 'dist', 'temp', 'tmp'] + +const filter = (src, _dest) => { + if (ignoreFolder.some((item) => src.includes(item))) { + return false + } + return true +} + +async function copyTemplate() { + const templateBackupPath = path.resolve(templateDistPath, '../designer_backup') + if (await fs.pathExists(templateBackupPath)) { + await fs.remove(templateBackupPath) + } + // 先备份原目录 + if (await fs.pathExists(templateDistPath)) { + await fs.move(templateDistPath, templateBackupPath) + } + try { + // 删除cli template内容 + if (await fs.pathExists(templateDistPath)) { + await fs.remove(templateDistPath) + } + // 复制designer-demo + await fs.copy(templateSrcPath, templateDistPath, { filter }) + await fs.remove(templateBackupPath) + return true + } catch (error) { + logger.error(error) + // 复制错误时恢复 + if (await fs.pathExists(templateBackupPath)) { + await fs.move(templateBackupPath, templateDistPath) + } + } finally { + if (await fs.pathExists(templateBackupPath)) { + await fs.remove(templateBackupPath) + } + } +} + +async function updatePkgJson() { + const { version } = pkg + const pkgJsonPath = path.resolve(templateDistPath, 'package.json') + if ((await fs.pathExists(pkgJsonPath)) === false) { + return + } + const pkgData = await fs.readJSON(pkgJsonPath) + pkgData.version = '0.0.0' + + const defaultScripts = { + dev: "concurrently 'pnpm:serve:mock' 'pnpm:serve:frontend'", + 'serve:frontend': 'cross-env VITE_THEME=light vite', + 'serve:mock': 'node node_modules/@opentiny/tiny-engine-mock/dist/app.js', + 'build:alpha': 'cross-env NODE_OPTIONS=--max-old-space-size=8192 VITE_THEME=light vite build --mode alpha', + build: 'cross-env NODE_OPTIONS=--max-old-space-size=8192 VITE_THEME=light vite build --mode prod' + } + + Object.entries(defaultScripts).forEach(([name, value]) => { + pkgData.scripts[name] = value + }) + + pkgData.devDependencies['concurrently'] = '^8.2.0' + + Object.keys(pkgData.dependencies) + .filter((name) => name.includes('@opentiny/tiny-engine')) + .forEach((name) => (pkgData.dependencies[name] = version)) + Object.keys(pkgData.devDependencies) + .filter((name) => name.includes('@opentiny/tiny-engine')) + .forEach((name) => (pkgData.devDependencies[name] = version)) + + await fs.writeJSON(pkgJsonPath, pkgData, { spaces: 2 }) +} + +async function modifyViteConfig() { + const viteConfigPath = path.resolve(templateDistPath, 'vite.config.js') + if (await fs.exists(viteConfigPath)) { + const fileContent = await fs.readFile(viteConfigPath, { encoding: 'utf-8' }) + const aliasRegexp = /useSourceAlias: *true/ + if (aliasRegexp.test(fileContent)) { + const newFileContent = fileContent.replace(aliasRegexp, 'useSourceAlias: false') + await fs.writeFile(viteConfigPath, newFileContent) + } + } +} + +async function main() { + await copyTemplate() + await updatePkgJson() + await modifyViteConfig() +} + +main()