Merge branch 'main' into 1600822305-patch-2
# Conflicts: # package.json # yarn.lock
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const yaml = require('js-yaml')
|
||||
|
||||
async function renameFilesWithSpaces() {
|
||||
const distPath = path.join('dist')
|
||||
const files = fs.readdirSync(distPath, { withFileTypes: true })
|
||||
|
||||
// Only process files in the root of dist directory, not subdirectories
|
||||
files.forEach((file) => {
|
||||
if (file.isFile() && file.name.includes(' ')) {
|
||||
const oldPath = path.join(distPath, file.name)
|
||||
const newName = file.name.replace(/ /g, '-')
|
||||
const newPath = path.join(distPath, newName)
|
||||
|
||||
fs.renameSync(oldPath, newPath)
|
||||
console.log(`Renamed: ${file.name} -> ${newName}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function afterBuild() {
|
||||
console.log('[After build] hook started...')
|
||||
|
||||
try {
|
||||
// Read the latest.yml file
|
||||
const latestYmlPath = path.join('dist', 'latest.yml')
|
||||
const yamlContent = fs.readFileSync(latestYmlPath, 'utf8')
|
||||
const data = yaml.load(yamlContent)
|
||||
|
||||
// Remove the first element from files array
|
||||
if (data.files && data.files.length > 1) {
|
||||
const file = data.files.shift()
|
||||
|
||||
// Remove Cherry Studio-1.2.3-setup.exe
|
||||
fs.rmSync(path.join('dist', file.url))
|
||||
fs.rmSync(path.join('dist', file.url + '.blockmap'))
|
||||
|
||||
// Remove Cherry Studio-1.2.3-portable.exe
|
||||
fs.rmSync(path.join('dist', file.url.replace('-setup', '-portable')))
|
||||
|
||||
// Update path and sha512 with the new first element's data
|
||||
if (data.files[0]) {
|
||||
data.path = data.files[0].url
|
||||
data.sha512 = data.files[0].sha512
|
||||
}
|
||||
}
|
||||
|
||||
// Write back the modified YAML with specific dump options
|
||||
const newYamlContent = yaml.dump(data, {
|
||||
lineWidth: -1, // Prevent line wrapping
|
||||
quotingType: '"', // Use double quotes when needed
|
||||
forceQuotes: false, // Only quote when necessary
|
||||
noCompatMode: true, // Use new style options
|
||||
styles: {
|
||||
'!!str': 'plain' // Force plain style for strings
|
||||
}
|
||||
})
|
||||
|
||||
fs.writeFileSync(latestYmlPath, newYamlContent, 'utf8')
|
||||
|
||||
// Rename files with spaces
|
||||
await renameFilesWithSpaces()
|
||||
|
||||
console.log('Successfully cleaned up latest.yml data')
|
||||
} catch (error) {
|
||||
console.error('Error processing latest.yml:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
afterBuild()
|
||||
@@ -1,8 +1,10 @@
|
||||
const { Arch } = require('electron-builder')
|
||||
const { default: removeLocales } = require('./remove-locales')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
exports.default = async function (context) {
|
||||
await removeLocales(context)
|
||||
const platform = context.packager.platform.name
|
||||
const arch = context.arch
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
const fs = require('fs')
|
||||
|
||||
exports.default = function (buildResult) {
|
||||
try {
|
||||
console.log('[artifact build completed] rename artifact file...')
|
||||
if (!buildResult.file.includes(' ')) {
|
||||
return
|
||||
}
|
||||
|
||||
let oldFilePath = buildResult.file
|
||||
if (oldFilePath.includes('-portable') && !oldFilePath.includes('-x64') && !oldFilePath.includes('-arm64')) {
|
||||
console.log('[artifact build completed] delete portable file:', oldFilePath)
|
||||
fs.unlinkSync(oldFilePath)
|
||||
return
|
||||
}
|
||||
const newfilePath = oldFilePath.replace(/ /g, '-')
|
||||
fs.renameSync(oldFilePath, newfilePath)
|
||||
buildResult.file = newfilePath
|
||||
console.log(`[artifact build completed] rename file ${oldFilePath} to ${newfilePath} `)
|
||||
} catch (error) {
|
||||
console.error('Error renaming file:', error)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
exports.default = async function (context) {
|
||||
const platform = context.packager.platform.name
|
||||
|
||||
// 根据平台确定 locales 目录位置
|
||||
let resourceDirs = []
|
||||
if (platform === 'mac') {
|
||||
// macOS 的语言文件位置
|
||||
resourceDirs = [
|
||||
path.join(context.appOutDir, 'Cherry Studio.app', 'Contents', 'Resources'),
|
||||
path.join(
|
||||
context.appOutDir,
|
||||
'Cherry Studio.app',
|
||||
'Contents',
|
||||
'Frameworks',
|
||||
'Electron Framework.framework',
|
||||
'Resources'
|
||||
)
|
||||
]
|
||||
} else {
|
||||
// Windows 和 Linux 的语言文件位置
|
||||
resourceDirs = [path.join(context.appOutDir, 'locales')]
|
||||
}
|
||||
|
||||
// 处理每个资源目录
|
||||
for (const resourceDir of resourceDirs) {
|
||||
if (!fs.existsSync(resourceDir)) {
|
||||
console.log(`Resource directory not found: ${resourceDir}, skipping...`)
|
||||
continue
|
||||
}
|
||||
|
||||
// 读取所有文件和目录
|
||||
const items = fs.readdirSync(resourceDir)
|
||||
|
||||
// 遍历并删除不需要的语言文件
|
||||
for (const item of items) {
|
||||
if (platform === 'mac') {
|
||||
// 在 macOS 上检查 .lproj 目录
|
||||
if (item.endsWith('.lproj') && !item.match(/^(en|zh|ru)/)) {
|
||||
const dirPath = path.join(resourceDir, item)
|
||||
fs.rmSync(dirPath, { recursive: true, force: true })
|
||||
console.log(`Removed locale directory: ${item} from ${resourceDir}`)
|
||||
}
|
||||
} else {
|
||||
// 其他平台处理 .pak 文件
|
||||
if (!item.match(/^(en|zh|ru)/)) {
|
||||
const filePath = path.join(resourceDir, item)
|
||||
fs.unlinkSync(filePath)
|
||||
console.log(`Removed locale file: ${item} from ${resourceDir}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Locale cleanup completed!')
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
// replaceSpaces.js
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const directory = 'dist'
|
||||
|
||||
// 处理文件名中的空格
|
||||
function replaceFileNames() {
|
||||
fs.readdir(directory, (err, files) => {
|
||||
if (err) throw err
|
||||
|
||||
files.forEach((file) => {
|
||||
const oldPath = path.join(directory, file)
|
||||
const newPath = path.join(directory, file.replace(/ /g, '-'))
|
||||
|
||||
fs.stat(oldPath, (err, stats) => {
|
||||
if (err) throw err
|
||||
|
||||
if (stats.isFile() && oldPath !== newPath) {
|
||||
fs.rename(oldPath, newPath, (err) => {
|
||||
if (err) throw err
|
||||
console.log(`Renamed: ${oldPath} -> ${newPath}`)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function replaceYmlContent() {
|
||||
fs.readdir(directory, (err, files) => {
|
||||
if (err) throw err
|
||||
|
||||
files.forEach((file) => {
|
||||
if (path.extname(file).toLowerCase() === '.yml') {
|
||||
const filePath = path.join(directory, file)
|
||||
|
||||
fs.readFile(filePath, 'utf8', (err, data) => {
|
||||
if (err) throw err
|
||||
|
||||
// 替换内容
|
||||
const newContent = data.replace(/Cherry Studio-/g, 'Cherry-Studio-')
|
||||
|
||||
// 写回文件
|
||||
fs.writeFile(filePath, newContent, 'utf8', (err) => {
|
||||
if (err) throw err
|
||||
console.log(`Updated content in: ${filePath}`)
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 执行两个操作
|
||||
replaceFileNames()
|
||||
replaceYmlContent()
|
||||
Reference in New Issue
Block a user