From 6f186c2a8b6a8a7bbb4cadc551548cdfee31b861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B3=E5=90=9B=E5=81=A5?= <40288193@qq.com> Date: Fri, 26 Jul 2024 17:17:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(theme):=20when=20release=20theme,=20copy=20?= =?UTF-8?q?dist=20to=20=5Fdist=20and=20replace=20cssvar=E2=80=A6=20(#1768)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(theme): when release theme, copy dist to _dist and replace cssvar's prefix name * fix(vue-theme): update package's version --- packages/theme/build/release.js | 41 +++++++++++++++++++++++++-------- packages/theme/package.json | 34 +++++++++++++-------------- 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/packages/theme/build/release.js b/packages/theme/build/release.js index 66f3f17ffc..f9c871b8e2 100644 --- a/packages/theme/build/release.js +++ b/packages/theme/build/release.js @@ -1,17 +1,40 @@ /** - * 将 dist 目录生成 TGZ 的压缩包 + * 将 dist 目录生成 TGZ 的压缩包 fs.cp 需要node 18.0+ */ const fs = require('node:fs') const path = require('node:path') -const { execSync } = require('node:child_process') +const fg = require('fast-glob') -const source = 'dist' -const content = fs.readFileSync(path.join(source, 'index.css')).toString('UTF-8') -// 提供特殊的前缀名称 -const result = content.replace(/--ti-/g, '--ti-vue-') -const packagesPath = path.join(source, 'lowcode.css') +// 替换文件内容。 如果不指定target,则原地覆盖 +function replaceFile(src, cb, target = null) { + let content = fs.readFileSync(src, 'utf8') + content = cb(content) + fs.writeFileSync(target || src, content, 'utf8') +} -fs.writeFileSync(packagesPath, result) +// 1、从 index.css 生成 lowcode.css ------ 提供特殊的前缀名称 +replaceFile('dist/index.css', (content) => content.replace(/--ti-/g, '--ti-vue-'), 'dist/lowcode.css') -fs.copyFileSync('package.json', path.join(source, 'package.json')) +// 2、复制一份冗余的文件,统一替换 --ti- 前缀为 --tvue- ,避免混用 tiny3时,css变量名冲突。 +fs.cpSync('dist', '_dist', { recursive: true, force: true }) +fs.cpSync('_dist', 'dist/_dist', { recursive: true, force: true }) +fs.rmSync('_dist', { recursive: true, force: true }) +// 2.1 处理所有的 index.css +let files = fg.sync(['dist/_dist/**/index.css']) +files.forEach((file) => { + replaceFile(file, (content) => content.replace(/--ti-/g, '--tvue-')) +}) +// 2.2 处理所有的说主题js +files = fg.sync(['dist/_dist/**/{aurora,smb}-theme.js', 'dist/_dist/theme/**/{index,component}.js']) +files.forEach((file) => { + replaceFile(file, (content) => + content + .replace(/--ti-/g, '--tvue-') // + .replace(/'ti-/g, `'tvue-`) + ) +}) + +// 3、复制package.json/README.md到dist目录 +fs.copyFileSync('package.json', path.join('dist', 'package.json')) +fs.copyFileSync('README.md', path.join('dist', 'README.md')) diff --git a/packages/theme/package.json b/packages/theme/package.json index 10da1014cc..785032ab50 100644 --- a/packages/theme/package.json +++ b/packages/theme/package.json @@ -1,9 +1,17 @@ { "name": "@opentiny/vue-theme", - "version": "3.17.3", + "version": "3.17.4", "description": "An enterprise-class UI component library, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.", - "main": "index.css", + "author": "OpenTiny Team", + "license": "MIT", "homepage": "https://opentiny.design/tiny-vue", + "repository": { + "type": "git", + "url": "git@github.com:opentiny/tiny-vue.git" + }, + "bugs": { + "url": "https://github.com/opentiny/tiny-vue/issues" + }, "keywords": [ "vue", "vue3", @@ -15,24 +23,16 @@ "renderless-components", "headless-components" ], - "author": "OpenTiny Team", - "license": "MIT", - "repository": { - "type": "git", - "url": "git@github.com:opentiny/tiny-vue.git" - }, - "bugs": { - "url": "https://github.com/opentiny/tiny-vue/issues" - }, "exports": { "./*": "./src/*" }, + "main": "index.css", "scripts": { "clean": "rimraf dist src/aurora-theme src/smb-theme", "build:theme": "gulp build --gulpfile build/gulp-dist.js", "build": "npm run clean && npm run build:theme && node build/replace-img.js", "build:fast": "npm run build && npm run release", - "release": "node build/release.js && node build/postbuild.js && shx cp README.md dist", + "release": "node build/release.js && node build/postbuild.js", "build:copy-remote": "npm run build:theme && cp-cli dist ../tiny-vue/node_modules/@opentiny/vue-theme", "publishTgz": "node .cloudbuild/publish-tgzs.js", "postversion": "pnpm build", @@ -42,18 +42,18 @@ "@babel/cli": "^7.5.5", "@babel/core": "^7.5.5", "@babel/preset-env": "^7.5.5", + "fast-glob": "^3.2.12", "gulp": "^4.0.2", "gulp-autoprefixer": "^7.0.1", "gulp-clean-css": "^4.2.0", + "gulp-concat": "2.6.1", "gulp-less": "^5.0.0", "gulp-svg-inline": "^1.0.1", "gulp-transform": "3.0.5", - "gulp-concat": "2.6.1", - "svgo": "3.2.0", "rimraf": "^2.6.2", - "fast-glob": "^3.2.12", "stylelint": "^14.14.0", - "stylelint-config-standard": "^29.0.0" + "stylelint-config-standard": "^29.0.0", + "svgo": "3.2.0" }, "stylelint": { "extends": [ @@ -87,4 +87,4 @@ ] } } -} \ No newline at end of file +}