Skip to content

Commit

Permalink
fix: test on windows admzip
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Oct 17, 2024
1 parent 9543919 commit 3f23c67
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,21 @@
"@std/semver": "npm:@jsr/std__semver",
"@supabase/supabase-js": "^2.45.2",
"@tomasklaen/checksum": "^1.1.0",
"@types/adm-zip": "^0.5.5",
"@types/node": "^22.5.0",
"@types/prettyjson": "^0.0.33",
"@types/tmp": "^0.2.6",
"@typescript-eslint/eslint-plugin": "^8.3.0",
"@typescript-eslint/parser": "^8.3.0",
"@vercel/ncc": "^0.38.1",
"adm-zip": "^0.5.16",
"ci-info": "^4.0.0",
"commander": "12.1.0",
"esbuild": "^0.24.0",
"eslint": "9.12.0",
"git-format-staged": "3.1.1",
"husky": "^9.1.5",
"is-wsl": "^3.1.0",
"jszip": "^3.10.1",
"ky": "^1.7.2",
"latest-version": "^9.0.0",
"open": "^10.1.0",
Expand Down
39 changes: 25 additions & 14 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import type { Buffer } from 'node:buffer'
import type { ExtConfigPairs } from './config'
import type { Database } from './types/supabase.types'
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
import { homedir } from 'node:os'
import { homedir, platform as osPlatform } from 'node:os'
import { dirname, join, relative, resolve, sep } from 'node:path'
import { cwd, exit } from 'node:process'
import { findMonorepoRoot, findNXMonorepoRoot, isMonorepo, isNXMonorepo } from '@capacitor/cli/dist/util/monorepotools'
import { findInstallCommand, findPackageManagerRunner, findPackageManagerType } from '@capgo/find-package-manager'
import { confirm as confirmC, isCancel, log, select, spinner as spinnerC } from '@clack/prompts'
import { createClient, FunctionsHttpError } from '@supabase/supabase-js'
import { checksum as getChecksum } from '@tomasklaen/checksum'
import AdmZip from 'adm-zip'
import { program } from 'commander'
import JSZip from 'jszip'
import ky from 'ky'
import prettyjson from 'prettyjson'
import * as tus from 'tus-js-client'
Expand Down Expand Up @@ -695,33 +695,44 @@ export interface uploadUrlsType {
}

export async function zipFile(filePath: string): Promise<Buffer> {
log.info('Zipping file')
const zip = new JSZip()
if (osPlatform() === 'win32') {
return zipFileWindows(filePath)
}
else {
return zipFileUnix(filePath)
}
}

export function zipFileUnix(filePath: string) {
const zip = new AdmZip()
zip.addLocalFolder(filePath)
return zip.toBuffer()
}

export async function zipFileWindows(filePath: string): Promise<Buffer> {
log.info('Zipping file windows mode')
const zip = new AdmZip()

// Helper function to recursively add files and folders to the ZIP archive
const addToZip = async (folderPath: string, zipPath: string) => {
const addToZip = (folderPath: string, zipPath: string) => {
const items = readdirSync(folderPath)

for (const item of items) {
const itemPath = join(folderPath, item)
const stats = statSync(itemPath)

if (stats.isFile()) {
const fileContent = await readFileSync(itemPath)
zip.file(join(zipPath, item).split(sep).join('/'), fileContent)
const fileContent = readFileSync(itemPath)
zip.addFile(join(zipPath, item).split(sep).join('/'), fileContent)
}
else if (stats.isDirectory()) {
await addToZip(itemPath, join(zipPath, item))
addToZip(itemPath, join(zipPath, item))
}
}
}

// Start adding files and folders to the ZIP archive
await addToZip(filePath, '')
addToZip(filePath, '')

// Generate the ZIP file as a Buffer
const zipBuffer = await zip.generateAsync({ type: 'nodebuffer', platform: 'UNIX', compression: 'DEFLATE', compressionOptions: { level: 6 } })
return zipBuffer
return zip.toBuffer()
}

export async function uploadTUS(apikey: string, data: Buffer, orgId: string, appId: string, name: string, spinner: ReturnType<typeof spinnerC>, localConfig: CapgoConfig): Promise<boolean> {
Expand Down

0 comments on commit 3f23c67

Please sign in to comment.