Skip to content

Commit

Permalink
Merge pull request #2 from eliperkins/taki-on/fix_script
Browse files Browse the repository at this point in the history
Adopt new asset catalogue folder structure
  • Loading branch information
eliperkins committed Oct 14, 2020
2 parents fa6a314 + 8663240 commit 1867716
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Sources/Catalogue/main.swift
Expand Up @@ -14,7 +14,7 @@ do {
let data = try Data(contentsOf: sourceDataPath)
let decoder = JSONDecoder()
let colors = try decoder.decode([Color].self, from: data)
let creator = AssetCreator(assetFileName: "Primer")
let creator = AssetCreator(assetFileName: "Assets")
try creator.write(colors, at: outputPath)
}
} catch {
Expand Down
18 changes: 12 additions & 6 deletions Sources/CatalogueKit/AssetCreator.swift
Expand Up @@ -18,12 +18,17 @@ public struct AssetCreator {
}()

public func write(_ colors: [Color], at path: String) throws {
// Ensure a full-rewrite of assets if one currently exists.
let folder = try Folder(path: path + "/\(assetFileName).xcassets", using: fileManager)
try folder.delete()

let rootFolder =
try Folder(path: path + "/\(assetFileName).xcassets", using: fileManager)

// Ensure a full-rewrite of Primer assets if one currently exists.
let primerFolderName = "Primer"
let primerFolder =
try Folder(path: rootFolder.path + "/\(primerFolderName)", using: fileManager)
try primerFolder.delete()

// Overwrite with a new blank directory.
let assetFolder = try fileSystem.createFolderIfNeeded(at: folder.path)
let assetFolder = try fileSystem.createFolderIfNeeded(at: rootFolder.path)
let rootContents = try JSONSerialization.data(withJSONObject: [
"info" : [
"version" : 1,
Expand All @@ -32,7 +37,8 @@ public struct AssetCreator {
], options: [.prettyPrinted])
try assetFolder.createFile(named: "Contents.json", contents: rootContents)

let colorsFolder = try assetFolder.createSubfolder(named: "Colors")
let colorsFolder =
try assetFolder.createSubfolder(named: primerFolderName)

try colors.forEach { color in
let currentColorFolder = try colorsFolder.createSubfolder(named: color.name + ".colorset")
Expand Down

0 comments on commit 1867716

Please sign in to comment.