@capgo/cli 4.10.65-beta.1 → 4.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/cli",
3
- "version": "4.10.65-beta.1",
3
+ "version": "4.11.1",
4
4
  "description": "A CLI to upload to capgo servers",
5
5
  "author": "github.com/riderx",
6
6
  "license": "Apache 2.0",
package/src/init.ts CHANGED
@@ -2,7 +2,6 @@ import { readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
2
2
  import type { ExecSyncOptions } from 'node:child_process'
3
3
  import { execSync, spawnSync } from 'node:child_process'
4
4
  import process from 'node:process'
5
- import { tmpdir } from 'node:os'
6
5
  import * as p from '@clack/prompts'
7
6
  import type LogSnag from 'logsnag'
8
7
  import semver from 'semver'
package/src/utils.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
2
- import { homedir } from 'node:os'
2
+ import { homedir, release as osRelease } from 'node:os'
3
3
  import { join, resolve, sep } from 'node:path'
4
4
  import process from 'node:process'
5
5
  import type { Buffer } from 'node:buffer'
@@ -15,8 +15,7 @@ import { promiseFiles } from 'node-dir'
15
15
  import { findRootSync } from '@manypkg/find-root'
16
16
  import type { InstallCommand, PackageManagerRunner, PackageManagerType } from '@capgo/find-package-manager'
17
17
  import { findInstallCommand, findPackageManagerRunner, findPackageManagerType } from '@capgo/find-package-manager'
18
- // import AdmZip from 'adm-zip'
19
- // import isWsl from 'is-wsl'
18
+ import AdmZip from 'adm-zip'
20
19
  import JSZip from 'jszip'
21
20
  import type { Database } from './types/supabase.types'
22
21
 
@@ -520,6 +519,21 @@ async function prepareMultipart(supabase: SupabaseClient<Database>, appId: strin
520
519
  }
521
520
 
522
521
  export async function zipFile(filePath: string): Promise<Buffer> {
522
+ if (osRelease().toLowerCase().includes('microsoft')) {
523
+ return zipFileWindows(filePath)
524
+ }
525
+ else {
526
+ return zipFileUnix(filePath)
527
+ }
528
+ }
529
+
530
+ export function zipFileUnix(filePath: string) {
531
+ const zip = new AdmZip()
532
+ zip.addLocalFolder(filePath)
533
+ return zip.toBuffer()
534
+ }
535
+
536
+ export async function zipFileWindows(filePath: string): Promise<Buffer> {
523
537
  const zip = new JSZip()
524
538
 
525
539
  // Helper function to recursively add files and folders to the ZIP archive
@@ -544,21 +558,10 @@ export async function zipFile(filePath: string): Promise<Buffer> {
544
558
  await addToZip(filePath, '')
545
559
 
546
560
  // Generate the ZIP file as a Buffer
547
- const zipBuffer = await zip.generateAsync({ type: 'nodebuffer', platform: 'UNIX' })
561
+ const zipBuffer = await zip.generateAsync({ type: 'nodebuffer', platform: 'UNIX', compression: 'DEFLATE' })
548
562
  return zipBuffer
549
563
  }
550
564
 
551
- // export function zipFile(filePath: string) {
552
- // // if windows and not wsl then do error
553
- // if (os.release().toLowerCase().includes('microsoft') && !isWsl) {
554
- // p.log.error(`Windows powershell is not supported, please use WSL or a Linux distribution`)
555
- // program.error('')
556
- // }
557
- // const zip = new AdmZip()
558
- // zip.addLocalFolder(filePath)
559
- // return zip.toBuffer()
560
- // }
561
-
562
565
  async function finishMultipartDownload(key: string, uploadId: string, url: string, parts: any[]) {
563
566
  const metadata = {
564
567
  action: 'mpu-complete',
@@ -0,0 +1,24 @@
1
+ {
2
+ "originHash" : "be28ad70f15d01b567aeb05f85c074fc7d437a0ade8a8ceab7a6149b8f5b3593",
3
+ "pins" : [
4
+ {
5
+ "identity" : "swift-argument-parser",
6
+ "kind" : "remoteSourceControl",
7
+ "location" : "https://github.com/apple/swift-argument-parser",
8
+ "state" : {
9
+ "revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b",
10
+ "version" : "1.4.0"
11
+ }
12
+ },
13
+ {
14
+ "identity" : "ziparchive",
15
+ "kind" : "remoteSourceControl",
16
+ "location" : "https://github.com/ZipArchive/ZipArchive.git",
17
+ "state" : {
18
+ "revision" : "79d4dc9729096c6ad83dd3cee2b9f354d1b4ab7b",
19
+ "version" : "2.5.5"
20
+ }
21
+ }
22
+ ],
23
+ "version" : 3
24
+ }
@@ -0,0 +1,29 @@
1
+ // swift-tools-version: 5.10
2
+ // The swift-tools-version declares the minimum version of Swift required to build this package.
3
+
4
+ import PackageDescription
5
+
6
+ let package = Package(
7
+ name: "MyCLI",
8
+ platforms: [
9
+ .macOS(.v11)
10
+ ], dependencies: [
11
+ .package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMajor(from: "1.4.0")),
12
+ .package(url: "https://github.com/ZipArchive/ZipArchive.git", .upToNextMajor(from: "2.5.5"))
13
+ ],
14
+ targets: [
15
+ // Targets are the basic building blocks of a package, defining a module or a test suite.
16
+ // Targets can depend on other targets in this package and products from dependencies.
17
+ .executableTarget(
18
+ name: "MyCLI",
19
+ dependencies: [
20
+ .product(name: "ZipArchive", package: "ZipArchive"),
21
+ .product(name: "ArgumentParser", package: "swift-argument-parser"),
22
+ ],
23
+ path: "Sources",
24
+ swiftSettings: [
25
+ .unsafeFlags(["-parse-as-library"])
26
+ ]
27
+ ),
28
+ ]
29
+ )
@@ -0,0 +1,80 @@
1
+ // The Swift Programming Language
2
+ // https://docs.swift.org/swift-book
3
+
4
+ import ArgumentParser
5
+ import Foundation
6
+ import ZipArchive
7
+ import Darwin
8
+
9
+ extension URL {
10
+ var isDirectory: Bool {
11
+ (try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true
12
+ }
13
+ var exist: Bool {
14
+ return FileManager().fileExists(atPath: self.path)
15
+ }
16
+ }
17
+
18
+
19
+ func verifyZipFile(zipFilePath: String) {
20
+ let destUnZip = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("extracted")
21
+
22
+ var unzipError: NSError?
23
+ let success = SSZipArchive.unzipFile(atPath: zipFilePath,
24
+ toDestination: destUnZip.path,
25
+ preserveAttributes: true,
26
+ overwrite: true,
27
+ nestedZipLevel: 1,
28
+ password: nil,
29
+ error: &unzipError,
30
+ delegate: nil,
31
+ progressHandler: { (entry, _, _, _) in
32
+ if entry.contains("\\") {
33
+ print("Windows path is not supported: \(entry)")
34
+ exit(1)
35
+ }
36
+
37
+ let fileURL = destUnZip.appendingPathComponent(entry)
38
+ let canonicalPath = fileURL.path
39
+ let canonicalDir = destUnZip.path
40
+
41
+ if !canonicalPath.hasPrefix(canonicalDir) {
42
+ print("SecurityException, Failed to ensure directory is the start path: \(canonicalDir) of \(canonicalPath)")
43
+ exit(1)
44
+ }
45
+ },
46
+ completionHandler: nil)
47
+
48
+ if !success || unzipError != nil {
49
+ print("Failed to unzip file: \(zipFilePath)")
50
+ print("Error: \(unzipError?.localizedDescription ?? "")")
51
+ exit(1)
52
+ }
53
+
54
+ print("ZIP file is valid: \(zipFilePath)")
55
+ }
56
+
57
+ @main
58
+ struct CapgoCliTest: ParsableCommand {
59
+ @Option(parsing: .upToNextOption, help: "Specify the files to test")
60
+ public var zipFiles: [String]
61
+
62
+ public func run() throws {
63
+ print("Hello capgo test", zipFiles)
64
+
65
+ for file in zipFiles {
66
+ guard let fileUrl = URL(string: file) else {
67
+ print("Cannot convert \"\(file)\" into a file")
68
+ Darwin.exit(1)
69
+ }
70
+
71
+ if (!fileUrl.exist) {
72
+ print("File \"\(fileUrl)\" does not exist")
73
+ Darwin.exit(1)
74
+ }
75
+
76
+ print("Testing file \(file)")
77
+ verifyZipFile(zipFilePath: file)
78
+ }
79
+ }
80
+ }
@@ -1,54 +0,0 @@
1
- import Foundation
2
- import SSZipArchive
3
-
4
- func verifyZipFile(zipFilePath: String) -> Bool {
5
- let destUnZip = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("extracted")
6
-
7
- var unzipError: NSError?
8
- let success = SSZipArchive.unzipFile(atPath: zipFilePath,
9
- toDestination: destUnZip.path,
10
- preserveAttributes: true,
11
- overwrite: true,
12
- nestedZipLevel: 1,
13
- password: nil,
14
- error: &unzipError,
15
- delegate: nil,
16
- progressHandler: { (entry, _, _, _) in
17
- if entry.contains("\\") {
18
- print("Windows path is not supported: \(entry)")
19
- exit(1)
20
- }
21
-
22
- let fileURL = destUnZip.appendingPathComponent(entry)
23
- let canonicalPath = fileURL.path
24
- let canonicalDir = destUnZip.path
25
-
26
- if !canonicalPath.hasPrefix(canonicalDir) {
27
- print("SecurityException, Failed to ensure directory is the start path: \(canonicalDir) of \(canonicalPath)")
28
- exit(1)
29
- }
30
- },
31
- completionHandler: nil)
32
-
33
- if !success || unzipError != nil {
34
- print("Failed to unzip file: \(zipFilePath)")
35
- print("Error: \(unzipError?.localizedDescription ?? "")")
36
- return false
37
- }
38
-
39
- print("ZIP file is valid: \(zipFilePath)")
40
- return true
41
- }
42
-
43
- let zipFilePaths = CommandLine.arguments.dropFirst()
44
-
45
- if zipFilePaths.isEmpty {
46
- print("Usage: swift run VerifyZip <zip-file1> <zip-file2> ...")
47
- exit(1)
48
- }
49
-
50
- for zipFilePath in zipFilePaths {
51
- if !verifyZipFile(zipFilePath: zipFilePath) {
52
- exit(1)
53
- }
54
- }