import { pathFromPackages } from '../build/build-ui'
import path from 'node:path'
import fs from 'fs-extra'
const onlyMobileFirstTemplateLists = ['popconfirm', 'card', 'card-group']
const findAllpage = (packagesPath, vue3version) => {
if (
packagesPath.includes('.png') ||
packagesPath.includes('.gif') ||
packagesPath.includes('.jpeg') ||
packagesPath.includes('.jpg') ||
packagesPath.includes('.ttf') ||
packagesPath.includes('node_modules') ||
!fs.existsSync(packagesPath)
) {
return
}
if (fs.statSync(packagesPath).isDirectory()) {
fs.readdirSync(packagesPath).forEach((childPatch) => {
findAllpage(path.join(packagesPath, childPatch), vue3version)
})
} else {
const content = fs.readFileSync(packagesPath).toString('UTF-8' as BufferEncoding)
let result = content
.replace(/@opentiny\/vue-renderless/g, '@aurora/renderless')
.replace(/@opentiny\/vue-theme/g, '@aurora/theme')
.replace(/@opentiny/g, '@aurora')
.replace(/TINY/g, 'AUI')
.replace(/Tiny/g, 'Aui')
.replace(/tiny/g, 'aui')
.replace(/zhCN/g, 'zh_CN')
.replace(/enUS/g, 'en_US')
.replace(/-openaui/g, '-opentiny')
.replace(/"(.*?\/popup-manager)"/g, '"@aurora/renderless/common/deps/popup-manager"')
.replace(/@aurora\/fluent-editor/g, '@opentiny/fluent-editor')
.replace(/@aurora\/huicharts/g, '@opentiny/huicharts')
if (vue3version) {
result = result.replace(/@aurora\/vue/g, '@aurora/vue3')
}
if (
packagesPath.endsWith('index.js') &&
onlyMobileFirstTemplateLists.some((item) => packagesPath.includes(`${path.sep}${item}${path.sep}`))
) {
result = result.replace(/pc.js/g, 'mobile-first.js')
}
fs.writeFileSync(packagesPath, result)
}
}
export const releaseAurora = ({ vue3version }) => {
const distLists = [
'dist2/@aurora',
'renderless/dist',
'theme/dist',
'theme-saas/dist',
'utils/dist',
'utils/package.json',
'vue-hooks/dist',
'vue-hooks/package.json'
]
if (vue3version) {
distLists.push('dist3/@aurora')
}
distLists.forEach((item) => {
findAllpage(pathFromPackages(item), vue3version)
})
}