Skip to content

Commit

Permalink
Add LocalFileURLProvider Package
Browse files Browse the repository at this point in the history
  • Loading branch information
Tawa committed Jul 1, 2023
1 parent 0203ddc commit 92c423c
Show file tree
Hide file tree
Showing 23 changed files with 296 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// swift-tools-version: 5.8

import PackageDescription

let package = Package(
name: "LocalFileURLProviderContract",
platforms: [
.macOS(.v12)
],
products: [
.library(
name: "LocalFileURLProviderContract",
targets: ["LocalFileURLProviderContract"])
],
targets: [
.target(
name: "LocalFileURLProviderContract"
)
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# LocalFileURLProviderContract

A description of this package.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public protocol LocalFileURLProviderProtocol {
func localFileURL() -> URL?
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Modules/Features/GenerateFeature/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let package = Package(
dependencies: [
.package(path: "../../Contracts/DataStores/GenerateFeatureDataStoreContract"),
.package(path: "../../Contracts/Generators/ProjectGeneratorContract"),
.package(path: "../../Contracts/Providers/LocalFileURLProviderContract"),
.package(path: "../../Contracts/Syncers/PBXProjectSyncerContract"),
.package(path: "../../Entities/PhoenixDocument"),
.package(path: "../../Support/AccessibilityIdentifiers")
Expand All @@ -25,6 +26,7 @@ let package = Package(
dependencies: [
"GenerateFeatureDataStoreContract",
"ProjectGeneratorContract",
"LocalFileURLProviderContract",
"PBXProjectSyncerContract",
"PhoenixDocument",
"AccessibilityIdentifiers"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import AppKit
import Foundation

struct AshFileURLGetter: LocalFileURLGetter {
let fileURL: URL?

func getUrl() -> URL? {
let openPanel = NSOpenPanel()

openPanel.directoryURL = fileURL?.deletingLastPathComponent()
openPanel.allowsMultipleSelection = false
openPanel.canChooseFiles = true
openPanel.canChooseDirectories = true
openPanel.canCreateDirectories = true
openPanel.allowedContentTypes = [
.init(filenameExtension: "ash",
conformingTo: .init("com.apple.package")!)
].compactMap { $0 }

openPanel.runModal()

var url = openPanel.url
if url?.lastPathComponent.hasSuffix(".ash") == true {
url = url?.deletingLastPathComponent()
}
return url
}
}
//import AppKit
//import Foundation
//
//struct AshFileURLGetter: LocalFileURLGetter {
// let fileURL: URL?
//
// func getUrl() -> URL? {
// let openPanel = NSOpenPanel()
//
// openPanel.directoryURL = fileURL?.deletingLastPathComponent()
// openPanel.allowsMultipleSelection = false
// openPanel.canChooseFiles = true
// openPanel.canChooseDirectories = true
// openPanel.canCreateDirectories = true
// openPanel.allowedContentTypes = [
// .init(filenameExtension: "ash",
// conformingTo: .init("com.apple.package")!)
// ].compactMap { $0 }
//
// openPanel.runModal()
//
// var url = openPanel.url
// if url?.lastPathComponent.hasSuffix(".ash") == true {
// url = url?.deletingLastPathComponent()
// }
// return url
// }
//}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation

protocol LocalFileURLGetter {
func getUrl() -> URL?
}
//import Foundation
//
//protocol LocalFileURLGetter {
// func getUrl() -> URL?
//}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import AppKit
import Foundation

struct XcodeProjURLGetter: LocalFileURLGetter {
let fileURL: URL?

func getUrl() -> URL? {
let openPanel = NSOpenPanel()

openPanel.directoryURL = fileURL?.deletingLastPathComponent()
openPanel.allowsMultipleSelection = false
openPanel.canChooseFiles = true
openPanel.canChooseDirectories = false
openPanel.canCreateDirectories = true
openPanel.allowedContentTypes = [
.init(filenameExtension: "xcodeproj",
conformingTo: .init("com.apple.package")!)
].compactMap { $0 }

openPanel.runModal()

return openPanel.url
}
}
//import AppKit
//import Foundation
//
//struct XcodeProjURLGetter: LocalFileURLGetter {
// let fileURL: URL?
//
// func getUrl() -> URL? {
// let openPanel = NSOpenPanel()
//
// openPanel.directoryURL = fileURL?.deletingLastPathComponent()
// openPanel.allowsMultipleSelection = false
// openPanel.canChooseFiles = true
// openPanel.canChooseDirectories = false
// openPanel.canCreateDirectories = true
// openPanel.allowedContentTypes = [
// .init(filenameExtension: "xcodeproj",
// conformingTo: .init("com.apple.package")!)
// ].compactMap { $0 }
//
// openPanel.runModal()
//
// return openPanel.url
// }
//}
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import AccessibilityIdentifiers
import GenerateFeatureDataStoreContract
import LocalFileURLProviderContract
import PBXProjectSyncerContract
import PhoenixDocument
import ProjectGeneratorContract
import SwiftUI

public struct GenerateFeatureDependencies {
let ashFileURLGetter: LocalFileURLProviderProtocol
let dataStore: GenerateFeatureDataStoreProtocol
let projectGenerator: ProjectGeneratorProtocol
let pbxProjectSyncer: PBXProjectSyncerProtocol
let xcodeProjURLGetter: LocalFileURLProviderProtocol

public init(
ashFileURLGetter: LocalFileURLProviderProtocol,
dataStore: GenerateFeatureDataStoreProtocol,
projectGenerator: ProjectGeneratorProtocol,
pbxProjectSyncer: PBXProjectSyncerProtocol
pbxProjectSyncer: PBXProjectSyncerProtocol,
xcodeProjURLGetter: LocalFileURLProviderProtocol
) {
self.ashFileURLGetter = ashFileURLGetter
self.dataStore = dataStore
self.projectGenerator = projectGenerator
self.pbxProjectSyncer = pbxProjectSyncer
self.xcodeProjURLGetter = xcodeProjURLGetter
}
}

Expand Down Expand Up @@ -70,8 +77,8 @@ final class GenerateFeatureViewModel: ObservableObject {
}

// File URLs Managers
var ashFileURLGetter: LocalFileURLGetter
var xcodeProjURLGetter: LocalFileURLGetter
var ashFileURLGetter: LocalFileURLProviderProtocol
var xcodeProjURLGetter: LocalFileURLProviderProtocol
var dataStore: GenerateFeatureDataStoreProtocol
var fileAccessValidator: FileAccessValidatorProtocol

Expand All @@ -83,8 +90,8 @@ final class GenerateFeatureViewModel: ObservableObject {
self.onGenerate = onGenerate
self.onAlert = onAlert

ashFileURLGetter = AshFileURLGetter(fileURL: fileURL)
xcodeProjURLGetter = XcodeProjURLGetter(fileURL: fileURL)
ashFileURLGetter = dependencies.ashFileURLGetter
xcodeProjURLGetter = dependencies.xcodeProjURLGetter
fileAccessValidator = FileAccessValidator()

dataStore = dependencies.dataStore
Expand All @@ -106,11 +113,11 @@ final class GenerateFeatureViewModel: ObservableObject {
}

func onOpenModulesFolder() {
ashFileURLGetter.getUrl().map { modulesURL = $0 }
ashFileURLGetter.localFileURL().map { modulesURL = $0 }
}

func onOpenXcodeProject() {
xcodeProjURLGetter.getUrl().map { xcodeProjectURL = $0 }
xcodeProjURLGetter.localFileURL().map { xcodeProjectURL = $0 }
}

func onSkipXcodeProject(_ value: Bool) {
Expand Down
2 changes: 2 additions & 0 deletions Modules/Features/ValidationFeature/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ let package = Package(
targets: ["ValidationFeature"])
],
dependencies: [
.package(path: "../../Contracts/Providers/LocalFileURLProviderContract"),
.package(path: "../../Contracts/Validators/ProjectValidatorContract")
],
targets: [
.target(
name: "ValidationFeature",
dependencies: [
"LocalFileURLProviderContract",
"ProjectValidatorContract"
]
),
Expand Down
13 changes: 13 additions & 0 deletions Modules/Modules.ash/Feature/GenerateFeature.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@
"Contract"
]
},
{
"name" : {
"family" : "Provider",
"given" : "LocalFileURL"
},
"targetTypes" : [
{
"isTests" : false,
"name" : "Implementation"
},
"Contract"
]
},
{
"name" : {
"family" : "Syncer",
Expand Down
13 changes: 13 additions & 0 deletions Modules/Modules.ash/Feature/ValidationFeature.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
{
"localDependencies" : [
{
"name" : {
"family" : "Provider",
"given" : "LocalFileURL"
},
"targetTypes" : [
{
"isTests" : false,
"name" : "Implementation"
},
"Contract"
]
},
{
"name" : {
"family" : "Validator",
Expand Down
14 changes: 14 additions & 0 deletions Modules/Modules.ash/Provider/LocalFileURLProvider.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"macOSVersion" : "v12",
"modules" : {
"Contract" : "undefined",
"Implementation" : "undefined"
},
"name" : {
"family" : "Provider",
"given" : "LocalFileURL"
},
"resources" : [

]
}
2 changes: 1 addition & 1 deletion Modules/Modules.ash/appversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2.2
4.3

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions Modules/Providers/LocalFileURLProvider/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// swift-tools-version: 5.8

import PackageDescription

let package = Package(
name: "LocalFileURLProvider",
platforms: [
.macOS(.v12)
],
products: [
.library(
name: "LocalFileURLProvider",
targets: ["LocalFileURLProvider"])
],
dependencies: [
.package(path: "../../Contracts/Providers/LocalFileURLProviderContract")
],
targets: [
.target(
name: "LocalFileURLProvider",
dependencies: [
"LocalFileURLProviderContract"
]
),
.testTarget(
name: "LocalFileURLProviderTests",
dependencies: [
"LocalFileURLProvider"
]
)
]
)
3 changes: 3 additions & 0 deletions Modules/Providers/LocalFileURLProvider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# LocalFileURLProvider

A description of this package.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import AppKit
import Foundation
import LocalFileURLProviderContract
import UniformTypeIdentifiers

public struct AshFileURLProvider: LocalFileURLProviderProtocol {
let initialURL: URL?

public init(initialURL: URL?) {
self.initialURL = initialURL
}

public func localFileURL() -> URL? {
let openPanel = NSOpenPanel()

openPanel.directoryURL = initialURL?.deletingLastPathComponent()
openPanel.allowsMultipleSelection = false
openPanel.canChooseFiles = true
openPanel.canChooseDirectories = true
openPanel.canCreateDirectories = true
openPanel.allowedContentTypes = [
.init(filenameExtension: "ash",
conformingTo: .init("com.apple.package")!)
].compactMap { $0 }

openPanel.runModal()

var url = openPanel.url
if url?.lastPathComponent.hasSuffix(".ash") == true {
url = url?.deletingLastPathComponent()
}
return url
}
}
Loading

0 comments on commit 92c423c

Please sign in to comment.