don't diff binary files
This commit is contained in:
parent
0e3699da5a
commit
14281a1bf5
|
|
@ -397,14 +397,23 @@ export async function diffApp() {
|
||||||
console.log(color.gray('─'.repeat(60)))
|
console.log(color.gray('─'.repeat(60)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch all changed files in parallel
|
// Fetch all changed files in parallel (skip binary files)
|
||||||
const remoteContents = await Promise.all(
|
const remoteContents = await Promise.all(
|
||||||
changed.map(file => download(`/api/sync/apps/${appName}/files/${file}`))
|
changed.map(file => isBinary(file) ? null : download(`/api/sync/apps/${appName}/files/${file}`))
|
||||||
)
|
)
|
||||||
|
|
||||||
// Show diffs for changed files
|
// Show diffs for changed files
|
||||||
for (let i = 0; i < changed.length; i++) {
|
for (let i = 0; i < changed.length; i++) {
|
||||||
const file = changed[i]!
|
const file = changed[i]!
|
||||||
|
|
||||||
|
console.log(color.bold(`\n${file}`))
|
||||||
|
console.log(color.gray('─'.repeat(60)))
|
||||||
|
|
||||||
|
if (isBinary(file)) {
|
||||||
|
console.log(color.gray('Binary file changed'))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
const remoteContent = remoteContents[i]
|
const remoteContent = remoteContents[i]
|
||||||
const localContent = readFileSync(join(process.cwd(), file), 'utf-8')
|
const localContent = readFileSync(join(process.cwd(), file), 'utf-8')
|
||||||
|
|
||||||
|
|
@ -414,9 +423,6 @@ export async function diffApp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const remoteText = new TextDecoder().decode(remoteContent)
|
const remoteText = new TextDecoder().decode(remoteContent)
|
||||||
|
|
||||||
console.log(color.bold(`\n${file}`))
|
|
||||||
console.log(color.gray('─'.repeat(60)))
|
|
||||||
showDiff(remoteText, localContent)
|
showDiff(remoteText, localContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -425,6 +431,12 @@ export async function diffApp() {
|
||||||
console.log(color.green('\nNew file (local only)'))
|
console.log(color.green('\nNew file (local only)'))
|
||||||
console.log(color.bold(`${file}`))
|
console.log(color.bold(`${file}`))
|
||||||
console.log(color.gray('─'.repeat(60)))
|
console.log(color.gray('─'.repeat(60)))
|
||||||
|
|
||||||
|
if (isBinary(file)) {
|
||||||
|
console.log(color.gray('Binary file'))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
const content = readFileSync(join(process.cwd(), file), 'utf-8')
|
const content = readFileSync(join(process.cwd(), file), 'utf-8')
|
||||||
const lines = content.split('\n')
|
const lines = content.split('\n')
|
||||||
for (let i = 0; i < Math.min(lines.length, 10); i++) {
|
for (let i = 0; i < Math.min(lines.length, 10); i++) {
|
||||||
|
|
@ -435,9 +447,9 @@ export async function diffApp() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch all remote-only files in parallel
|
// Fetch all remote-only files in parallel (skip binary files)
|
||||||
const remoteOnlyContents = await Promise.all(
|
const remoteOnlyContents = await Promise.all(
|
||||||
remoteOnly.map(file => download(`/api/sync/apps/${appName}/files/${file}`))
|
remoteOnly.map(file => isBinary(file) ? null : download(`/api/sync/apps/${appName}/files/${file}`))
|
||||||
)
|
)
|
||||||
|
|
||||||
// Show remote-only files
|
// Show remote-only files
|
||||||
|
|
@ -448,6 +460,12 @@ export async function diffApp() {
|
||||||
console.log(color.bold(`\n${file}`))
|
console.log(color.bold(`\n${file}`))
|
||||||
console.log(color.gray('─'.repeat(60)))
|
console.log(color.gray('─'.repeat(60)))
|
||||||
console.log(color.red('Remote only'))
|
console.log(color.red('Remote only'))
|
||||||
|
|
||||||
|
if (isBinary(file)) {
|
||||||
|
console.log(color.gray('Binary file'))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if (content) {
|
if (content) {
|
||||||
const text = new TextDecoder().decode(content)
|
const text = new TextDecoder().decode(content)
|
||||||
const lines = text.split('\n')
|
const lines = text.split('\n')
|
||||||
|
|
@ -1087,6 +1105,19 @@ async function getManifestDiff(appName: string): Promise<ManifestDiff | null> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const BINARY_EXTENSIONS = new Set([
|
||||||
|
'.png', '.jpg', '.jpeg', '.gif', '.bmp', '.ico', '.webp', '.avif', '.heic', '.tiff',
|
||||||
|
'.woff', '.woff2', '.ttf', '.eot', '.otf',
|
||||||
|
'.mp3', '.mp4', '.wav', '.ogg', '.webm', '.avi', '.mov',
|
||||||
|
'.pdf', '.zip', '.tar', '.gz', '.br', '.zst',
|
||||||
|
'.wasm', '.exe', '.dll', '.so', '.dylib',
|
||||||
|
])
|
||||||
|
|
||||||
|
const isBinary = (filename: string) => {
|
||||||
|
const ext = filename.slice(filename.lastIndexOf('.')).toLowerCase()
|
||||||
|
return BINARY_EXTENSIONS.has(ext)
|
||||||
|
}
|
||||||
|
|
||||||
function showDiff(remote: string, local: string) {
|
function showDiff(remote: string, local: string) {
|
||||||
const changes = diffLines(remote, local)
|
const changes = diffLines(remote, local)
|
||||||
let lineCount = 0
|
let lineCount = 0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user