Skip to content

Commit f19bbb8

Browse files
committed
chore: update template scripts
1 parent 9ed078e commit f19bbb8

File tree

4 files changed

+133
-13
lines changed

4 files changed

+133
-13
lines changed
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2-
"name": "designer-demo-template",
2+
"name": "designer-demo",
33
"private": true,
44
"version": "0.0.0",
55
"type": "module",
66
"scripts": {
77
"dev": "concurrently 'pnpm:serve:mock' 'pnpm:serve:frontend'",
8-
"serve:frontend": "cross-env VITE_THEME=light vite",
9-
"serve:mock": "node node_modules/@opentiny/tiny-engine-mock/dist/app.js",
108
"build:alpha": "cross-env NODE_OPTIONS=--max-old-space-size=8192 VITE_THEME=light vite build --mode alpha",
11-
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 VITE_THEME=light vite build --mode prod"
9+
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 VITE_THEME=light vite build --mode prod",
10+
"serve:frontend": "cross-env VITE_THEME=light vite",
11+
"serve:mock": "node node_modules/@opentiny/tiny-engine-mock/dist/app.js"
1212
},
1313
"dependencies": {
14-
"@opentiny/tiny-engine": "^2.1.0",
15-
"@opentiny/tiny-engine-theme-dark": "^2.1.0",
16-
"@opentiny/tiny-engine-theme-light": "^2.1.0",
17-
"@opentiny/tiny-engine-utils": "^2.1.0",
14+
"@opentiny/tiny-engine": "2.2.0-rc.0",
15+
"@opentiny/tiny-engine-theme-dark": "2.2.0-rc.0",
16+
"@opentiny/tiny-engine-theme-light": "2.2.0-rc.0",
17+
"@opentiny/tiny-engine-utils": "2.2.0-rc.0",
1818
"@opentiny/vue": "~3.20.0",
1919
"@opentiny/vue-design-smb": "~3.20.0",
2020
"@opentiny/vue-icon": "~3.20.0",
@@ -25,11 +25,11 @@
2525
"vue": "^3.4.21"
2626
},
2727
"devDependencies": {
28-
"@opentiny/tiny-engine-mock": "^2.1.0",
29-
"@opentiny/tiny-engine-vite-config": "^2.1.0",
28+
"@opentiny/tiny-engine-mock": "2.2.0-rc.0",
29+
"@opentiny/tiny-engine-vite-config": "2.2.0-rc.0",
3030
"@vitejs/plugin-vue": "^5.1.2",
3131
"cross-env": "^7.0.3",
32-
"concurrently": "^8.2.0",
33-
"vite": "^5.4.2"
32+
"vite": "^5.4.2",
33+
"concurrently": "^8.2.0"
3434
}
3535
}

packages/engine-cli/template/designer/registry.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,20 @@ export default {
101101
Lang,
102102
ViewSetting
103103
],
104-
plugins: [Materials, Tree, Page, Block, Datasource, Bridge, I18n, Script, State, Schema, Help, Robot],
104+
plugins: [
105+
Materials,
106+
Tree,
107+
Page,
108+
[Block, { options: { ...Block.options, mergeCategoriesAndGroups: true } }],
109+
Datasource,
110+
Bridge,
111+
I18n,
112+
Script,
113+
State,
114+
Schema,
115+
Help,
116+
Robot
117+
],
105118
dsls: [{ id: 'engine.dsls.dslvue' }],
106119
settings: [Props, Styles, Events],
107120
canvas: Canvas

packages/engine-cli/template/designer/vite.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default defineConfig((configEnv) => {
77
viteConfigEnv: configEnv,
88
root: __dirname,
99
iconDirs: [path.resolve(__dirname, './node_modules/@opentiny/tiny-engine/assets/')],
10+
useSourceAlias: false,
1011
envDir: './env'
1112
})
1213

scripts/updateTemplate.mjs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import fs from 'fs-extra'
2+
import path from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
import Logger from './logger.mjs'
5+
import pkg from '../packages/design-core/package.json' assert { type: 'json' }
6+
7+
const logger = new Logger('updateTemplate')
8+
9+
const __filename = fileURLToPath(import.meta.url)
10+
const __dirname = path.dirname(__filename)
11+
12+
const templateSrcPath = path.resolve(__dirname, '../designer-demo')
13+
const templateDistPath = path.resolve(__dirname, '../packages/engine-cli/template/designer')
14+
15+
const ignoreFolder = ['node_modules', 'dist', 'temp', 'tmp']
16+
17+
const filter = (src, _dest) => {
18+
if (ignoreFolder.some((item) => src.includes(item))) {
19+
return false
20+
}
21+
return true
22+
}
23+
24+
async function copyTemplate() {
25+
const templateBackupPath = path.resolve(templateDistPath, '../designer_backup')
26+
if (await fs.pathExists(templateBackupPath)) {
27+
await fs.remove(templateBackupPath)
28+
}
29+
// 先备份原目录
30+
if (await fs.pathExists(templateDistPath)) {
31+
await fs.move(templateDistPath, templateBackupPath)
32+
}
33+
try {
34+
// 删除cli template内容
35+
if (await fs.pathExists(templateDistPath)) {
36+
await fs.remove(templateDistPath)
37+
}
38+
// 复制designer-demo
39+
await fs.copy(templateSrcPath, templateDistPath, { filter })
40+
await fs.remove(templateBackupPath)
41+
return true
42+
} catch (error) {
43+
logger.error(error)
44+
// 复制错误时恢复
45+
if (await fs.pathExists(templateBackupPath)) {
46+
await fs.move(templateBackupPath, templateDistPath)
47+
}
48+
} finally {
49+
if (await fs.pathExists(templateBackupPath)) {
50+
await fs.remove(templateBackupPath)
51+
}
52+
}
53+
}
54+
55+
async function updatePkgJson() {
56+
const { version } = pkg
57+
const pkgJsonPath = path.resolve(templateDistPath, 'package.json')
58+
if ((await fs.pathExists(pkgJsonPath)) === false) {
59+
return
60+
}
61+
const pkgData = await fs.readJSON(pkgJsonPath)
62+
pkgData.version = '0.0.0'
63+
64+
const defaultScripts = {
65+
dev: "concurrently 'pnpm:serve:mock' 'pnpm:serve:frontend'",
66+
'serve:frontend': 'cross-env VITE_THEME=light vite',
67+
'serve:mock': 'node node_modules/@opentiny/tiny-engine-mock/dist/app.js',
68+
'build:alpha': 'cross-env NODE_OPTIONS=--max-old-space-size=8192 VITE_THEME=light vite build --mode alpha',
69+
build: 'cross-env NODE_OPTIONS=--max-old-space-size=8192 VITE_THEME=light vite build --mode prod'
70+
}
71+
72+
Object.entries(defaultScripts).forEach(([name, value]) => {
73+
pkgData.scripts[name] = value
74+
})
75+
76+
pkgData.devDependencies['concurrently'] = '^8.2.0'
77+
78+
Object.keys(pkgData.dependencies)
79+
.filter((name) => name.includes('@opentiny/tiny-engine'))
80+
.forEach((name) => (pkgData.dependencies[name] = version))
81+
Object.keys(pkgData.devDependencies)
82+
.filter((name) => name.includes('@opentiny/tiny-engine'))
83+
.forEach((name) => (pkgData.devDependencies[name] = version))
84+
85+
await fs.writeJSON(pkgJsonPath, pkgData, { spaces: 2 })
86+
}
87+
88+
async function modifyViteConfig() {
89+
const viteConfigPath = path.resolve(templateDistPath, 'vite.config.js')
90+
if (await fs.exists(viteConfigPath)) {
91+
const fileContent = await fs.readFile(viteConfigPath, { encoding: 'utf-8' })
92+
const aliasRegexp = /useSourceAlias: *true/
93+
if (aliasRegexp.test(fileContent)) {
94+
const newFileContent = fileContent.replace(aliasRegexp, 'useSourceAlias: false')
95+
await fs.writeFile(viteConfigPath, newFileContent)
96+
}
97+
}
98+
}
99+
100+
async function main() {
101+
await copyTemplate()
102+
await updatePkgJson()
103+
await modifyViteConfig()
104+
}
105+
106+
main()

0 commit comments

Comments
 (0)