Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions AGENTS.md

This file was deleted.

30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,31 @@ OPTIONS:

TARGET SUBCOMMANDS:
list-targets List project targets.
set-target Set target for an existing file.
set-target Set target for existing file.

GROUP SUBCOMMANDS:
add-group Add a group to the project.
delete-group Delete a group from the project.
move-group Move a group to a different location within the project.
rename-group Rename a group within the project.
add-group Add group.
delete-group Delete group.
move-group Move group.
rename-group Rename group.

FILE SUBCOMMANDS:
add-file Add a file to specified targets in the project.
delete-file Delete a file from the project.
move-file Move a file to a different location within the project.
rename-file Rename a file within the project.
add-file Add file to specified targets.
delete-file Delete file.
move-file Move file.
rename-file Rename file.

BUILD SETTINGS SUBCOMMANDS:
get-build-setting Get a build setting for specified target in the project.
set-build-setting Set a build setting for specified targets in the project.
get-build-setting Get build setting.
set-build-setting Set build setting.

ASSETS SUBCOMMANDS:
add-image-asset Add image asset.
add-data-asset Add data asset.
add-color-asset Add color asset.
list-assets List all assets.
move-asset Move asset.
delete-asset Delete asset.

See 'xcp help <subcommand>' for detailed help.
```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
final class ColorAssetBuilder {
private var hexColor: String?
private var darkHexColor: String?
private var colorSpace = "srgb"

func setHexColor(_ hex: String) -> ColorAssetBuilder {
hexColor = hex
return self
}

func setDarkHexColor(_ hex: String?) -> ColorAssetBuilder {
darkHexColor = hex
return self
}

func setColorSpace(_ space: String) -> ColorAssetBuilder {
colorSpace = space
return self
}

func build() -> String {
var darkColorTemplate = ""

if let darkColor = darkHexColor.flatMap(HexColor.init) {
darkColorTemplate = """
,
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "\(colorSpace)",
"components" : {
"alpha" : "\(darkColor.alpha)",
"blue" : "0x\(darkColor.blue)",
"green" : "0x\(darkColor.green)",
"red" : "0x\(darkColor.red)"
}
},
"idiom" : "universal"
}
"""
}

guard let color = hexColor.flatMap(HexColor.init) else {
return ""
}

return """
{
"colors" : [
{
"color" : {
"color-space" : "\(colorSpace)",
"components" : {
"alpha" : "\(color.alpha)",
"blue" : "0x\(color.blue)",
"green" : "0x\(color.green)",
"red" : "0x\(color.red)"
}
},
"idiom" : "universal"
}\(darkColorTemplate)
],
"info" : {
"author" : "xcode",
"version" : 1
}
}\n
"""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
final class DataAssetBuilder {
private let asset: AssetInfo

init(_ asset: AssetInfo) {
self.asset = asset
}

func build() -> String {
"""
{
"data" : [
{
"filename" : "\(asset.fileName)",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}\n
"""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
final class ImageAssetBuilder {
private var renderingMode: RenderingMode = .default
private var includeDark = false

private let asset: AssetInfo

init(_ asset: AssetInfo) {
self.asset = asset
}

func setRenderingMode(_ mode: RenderingMode) -> ImageAssetBuilder {
renderingMode = mode
return self
}

func includeDarkAppearance(_ includeDark: Bool) -> ImageAssetBuilder {
self.includeDark = includeDark
return self
}

func build() -> String {
let templateRendering = renderingMode != .default
? """
,
"properties" : {
"template-rendering-intent" : "\(renderingMode.rawValue)"
}
"""
: ""

let darkAppearance = includeDark
? """
,
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "\(asset.darkFileName)",
"idiom" : "universal"
}
"""
: ""

return """
{
"images" : [
{
"filename" : "\(asset.fileName)",
"idiom" : "universal"
}\(darkAppearance)
],
"info" : {
"author" : "xcode",
"version" : 1
}\(templateRendering)
}\n
"""
}
}
18 changes: 3 additions & 15 deletions Sources/XcodeProject/Core/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,16 @@ public final class Project {

public init(xcodeProjectPath: String?) throws {
var projectPath = xcodeProjectPath
let pwd = ProcessInfo.processInfo.environment["PWD"]
var currentDir = pwd

#if DEBUG
if pwd == nil || pwd == "/tmp" {
currentDir = #filePath
.components(separatedBy: "/")
.dropLast(4)
.joined(separator: "/")
}
#endif
let currentDir = PathUtils.processWorkingDirectory()

if projectPath == nil, let currentDir {
let contents = try FileManager.default.contentsOfDirectory(atPath: currentDir)
projectPath = contents.first { $0.hasSuffix(".xcodeproj") }
projectPath = InputPath(projectPath ?? "", projectRoot: currentDir).absolutePath
} else if let projectPathUnwrapped = projectPath, let currentDir, !(projectPathUnwrapped as NSString).isAbsolutePath {
projectPath = ("\(currentDir)/\(projectPathUnwrapped)" as NSString).standardizingPath
} else {
projectPath = projectPath.flatMap { PathUtils.toAbsolutePath($0) }
}

projectPath = (projectPath as NSString?)?.expandingTildeInPath

guard let projectPath else {
throw XcodeProjectError.xcodeProjectNotFound
}
Expand Down
Loading