diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c5faf1..e11d621 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,7 @@ ### Bug Fixes -* Don't convert colors to the calibrated RGB color space if it isn't needed. - [David Jennes](https://github.com/djbe) - [#23](https://github.com/SwiftGen/SwiftGenKit/issues/23) +_None_ ### Breaking Changes @@ -16,10 +14,28 @@ _None_ ### New Features +_None_ + +### Internal Changes + +_None_ + +## 1.1.0 + +### Bug Fixes + +* Don't convert colors to the calibrated RGB color space if it isn't needed. + [David Jennes](https://github.com/djbe) + [#23](https://github.com/SwiftGen/SwiftGenKit/issues/23) + +### New Features + * More variables have been deprecated, while new variables have been added. [David Jennes](https://github.com/djbe) + [#5](https://github.com/SwiftGen/SwiftGenKit/issues/5) [#13](https://github.com/SwiftGen/SwiftGenKit/issues/13) [#27](https://github.com/SwiftGen/SwiftGenKit/issues/27) + [#33](https://github.com/SwiftGen/SwiftGenKit/issues/33) * The `strings`, `structuredStrings` and `tableName` have been replaced by `tables`, which is an array of string tables, each with a `name` and a `strings` property. * For each string, the `params` variable and it's subvariables (such as `names`, `count`, ...) have been replaced by `types`, which is an array of types. * `enumName`, `sceneEnumName` and `segueEnumName` have been replaced by `param.enumName`, `param.sceneEnumName` and `param.segueEnumName` respectively. Templates should provide a default value for these in case the variables are empty. diff --git a/Documentation/Strings.md b/Documentation/Strings.md index 89e3927..3193425 100644 --- a/Documentation/Strings.md +++ b/Documentation/Strings.md @@ -33,14 +33,14 @@ will be parsed into the following structure (not showing the rest of the structu The output context has the following structure: - `tables`: `Array` — List of string tables - - `name` : `String` — name of the `.strings` file (usually `"Localizable"`) - - `strings`: `Array` — Tree structure of strings (based on dot syntax), each level has: - - `name` : `String` — name of the level (that is, part of the key split by `.` that we're describing) - - `strings`: `Array` — list of strings at this level: - - `key`: `String` — the full translation key, as it appears in the strings file + - `name` : `String` — name of the `.strings` file (usually `"Localizable"`) + - `levels`: `Array` — Tree structure of strings (based on dot syntax), each level has: + - `name` : `String` — name of the level (that is, part of the key split by `.` that we're describing) + - `children`: `Array` — list of sub-levels, repeating the same structure as a level + - `strings` : `Array` — list of strings at this level: + - `name` : `String` — contains only the last part of the key (after the last `.`) + (useful to do recursion when splitting keys against `.` for structured templates) + - `key` : `String` — the full translation key, as it appears in the strings file - `translation`: `String` — the translation for that key in the strings file - `types`: `Array` — defined only if localized string has parameter placeholders like `%d` and `%@` etc. Contains a list of types like `"String"`, `"Int"`, etc - - `keytail`: `String` — contains only the last part of the key (after the last `.`) - (useful to do recursion when splitting keys against `.` for structured templates) - - `subenums`: `Array` — list of sub-levels, repeating the structure mentioned above diff --git a/Podfile.lock b/Podfile.lock index d1192a4..0ca01c2 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,6 +1,6 @@ PODS: - PathKit (0.8.0) - - SwiftGenKit (1.0.1): + - SwiftGenKit (1.1.0): - PathKit (~> 0.8.0) DEPENDENCIES: @@ -8,11 +8,11 @@ DEPENDENCIES: EXTERNAL SOURCES: SwiftGenKit: - :path: "." + :path: . SPEC CHECKSUMS: PathKit: dcab05d701474011aae0e40cf892298a831f63d6 - SwiftGenKit: 9b6f20360c33216663514b720016fa2d57cea478 + SwiftGenKit: 6bffbbb5e592d537e48930b28d01cf0bec9d771b PODFILE CHECKSUM: c30ec8de82eda04587ffe005a6ce7372509b1340 diff --git a/Pods/Local Podspecs/SwiftGenKit.podspec.json b/Pods/Local Podspecs/SwiftGenKit.podspec.json index 925a259..9de9eea 100644 --- a/Pods/Local Podspecs/SwiftGenKit.podspec.json +++ b/Pods/Local Podspecs/SwiftGenKit.podspec.json @@ -1,6 +1,6 @@ { "name": "SwiftGenKit", - "version": "1.0.1", + "version": "1.1.0", "summary": "The SwiftGen framework responsible for parsing assets and turn them in a dictionary representation suitable for Stencil templates", "description": "This pod contains asset parsers for\n[SwiftGen](https://github.com/SwiftGen/SwiftGen), as well as\nmethods for converting the data into contexts for\n[Stencil](https://github.com/kylef/Stencil).", "homepage": "https://github.com/SwiftGen/SwiftGenKit", @@ -14,7 +14,7 @@ }, "source": { "git": "https://github.com/SwiftGen/SwiftGenKit.git", - "tag": "1.0.1" + "tag": "1.1.0" }, "source_files": "Sources/**/*.swift", "dependencies": { diff --git a/Pods/Manifest.lock b/Pods/Manifest.lock index d1192a4..0ca01c2 100644 --- a/Pods/Manifest.lock +++ b/Pods/Manifest.lock @@ -1,6 +1,6 @@ PODS: - PathKit (0.8.0) - - SwiftGenKit (1.0.1): + - SwiftGenKit (1.1.0): - PathKit (~> 0.8.0) DEPENDENCIES: @@ -8,11 +8,11 @@ DEPENDENCIES: EXTERNAL SOURCES: SwiftGenKit: - :path: "." + :path: . SPEC CHECKSUMS: PathKit: dcab05d701474011aae0e40cf892298a831f63d6 - SwiftGenKit: 9b6f20360c33216663514b720016fa2d57cea478 + SwiftGenKit: 6bffbbb5e592d537e48930b28d01cf0bec9d771b PODFILE CHECKSUM: c30ec8de82eda04587ffe005a6ce7372509b1340 diff --git a/Pods/Target Support Files/SwiftGenKit/Info.plist b/Pods/Target Support Files/SwiftGenKit/Info.plist index 3c175b6..21a30b4 100644 --- a/Pods/Target Support Files/SwiftGenKit/Info.plist +++ b/Pods/Target Support Files/SwiftGenKit/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0.1 + 1.1.0 CFBundleSignature ???? CFBundleVersion diff --git a/Rakefile b/Rakefile index 07db7f1..4c3604c 100644 --- a/Rakefile +++ b/Rakefile @@ -14,4 +14,54 @@ task :generate_contexts => "xcode:build" do |task| Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "Generate Contexts" -configuration "#{CONFIGURATION}" test-without-building), task, xcrun: true, formatter: :xcpretty) end +## [ Release a new version ] ################################################## + +namespace :release do + desc 'Create a new release on CocoaPods' + task :new => [:check_versions, 'xcode:test', :cocoapods] + + desc 'Check if all versions from the podspecs and CHANGELOG match' + task :check_versions do + results = [] + + # Check if bundler is installed first, as we'll need it for the cocoapods task (and we prefer to fail early) + `which bundler` + results << Utils.table_result( $?.success?, 'Bundler installed', 'Please install bundler using `gem install bundler` and run `bundle install` first.') + + # Extract version from SwiftGen.podspec + podspec_version = Utils.podspec_version('SwiftGenKit') + Utils.table_info('SwiftGenKit.podspec', podspec_version) + + # Check if version in Podfile.lock matches + podfile_lock_version = Utils.podfile_lock_version('SwiftGenKit') + results << Utils.table_result(podfile_lock_version == podspec_version, "Podfile.lock", "Please run pod install") + + # Check if submodule is aligned + submodule_aligned = Dir.chdir('Tests/Resources') do + `git fetch origin` + `git rev-parse origin/master`.chomp == `git rev-parse HEAD`.chomp + end + results << Utils.table_result(submodule_aligned, "Submodule on origin/master", "Please align the submodule to master") + + # Check if entry present in CHANGELOG + changelog_entry = system(%Q{grep -q '^## #{Regexp.quote(podspec_version)}$' CHANGELOG.md}) + results << Utils.table_result(changelog_entry, "CHANGELOG, Entry added", "Please add an entry for #{podspec_version} in CHANGELOG.md") + + changelog_master = system(%q{grep -qi '^## Master' CHANGELOG.md}) + results << Utils.table_result(!changelog_master, "CHANGELOG, No master", 'Please remove entry for master in CHANGELOG') + + exit 1 unless results.all? + + print "Release version #{podspec_version} [Y/n]? " + exit 2 unless (STDIN.gets.chomp == 'Y') + end + + desc 'pod trunk push SwiftGenKit to CocoaPods' + task :cocoapods do + Utils.print_header "Pushing pod to CocoaPods Trunk" + sh 'bundle exec pod trunk push SwiftGenKit.podspec' + end +end + + task :default => 'xcode:test' diff --git a/Sources/Stencil/StringsContext.swift b/Sources/Stencil/StringsContext.swift index 8ab509b..a97bc81 100644 --- a/Sources/Stencil/StringsContext.swift +++ b/Sources/Stencil/StringsContext.swift @@ -16,17 +16,17 @@ private extension String { /* - `tables`: `Array` — List of string tables - - `name` : `String` — name of the `.strings` file (usually `"Localizable"`) - - `strings`: `Array` — Tree structure of strings (based on dot syntax), each level has: - - `name` : `String` — name of the level (that is, part of the key split by `.` that we're describing) - - `strings`: `Array` — list of strings at this level: - - `key`: `String` — the full translation key, as it appears in the strings file + - `name` : `String` — name of the `.strings` file (usually `"Localizable"`) + - `levels`: `Array` — Tree structure of strings (based on dot syntax), each level has: + - `name` : `String` — name of the level (that is, part of the key split by `.` that we're describing) + - `children`: `Array` — list of sub-levels, repeating the same structure as a level + - `strings` : `Array` — list of strings at this level: + - `name` : `String` — contains only the last part of the key (after the last `.`) + (useful to do recursion when splitting keys against `.` for structured templates) + - `key` : `String` — the full translation key, as it appears in the strings file - `translation`: `String` — the translation for that key in the strings file - `types`: `Array` — defined only if localized string has parameter placeholders like `%d` and `%@` etc. Contains a list of types like `"String"`, `"Int"`, etc - - `keytail`: `String` — contains only the last part of the key (after the last `.`) - (useful to do recursion when splitting keys against `.` for structured templates) - - `subenums`: `Array` — list of sub-levels, repeating the structure mentioned above */ extension StringsFileParser { public func stencilContext(enumName: String = "L10n", tableName: String = "Localizable") -> [String: Any] { @@ -34,12 +34,15 @@ extension StringsFileParser { let entryToStringMapper = { (entry: Entry, keyPath: [String]) -> [String: Any] in var keyStructure = entry.keyStructure Array(0.. 0 { @@ -67,7 +70,7 @@ extension StringsFileParser { ) let tables: [[String: Any]] = [[ "name": tableName, - "strings": structuredStrings + "levels": structuredStrings ]] return [ @@ -108,7 +111,7 @@ extension StringsFileParser { structuredStrings["name"] = lastKeyPathComponent } - var subenums: [[String: Any]] = [] + var children: [[String: Any]] = [] let nextLevelKeyPaths: [[String]] = entries .filter({ $0.keyStructure.count > keyPath.count+1 }) .map({ Array($0.keyStructure.prefix(keyPath.count+1)) }) @@ -127,15 +130,18 @@ extension StringsFileParser { let entriesInKeyPath = entries.filter { Array($0.keyStructure.map(normalize).prefix(nextLevelKeyPath.count)) == nextLevelKeyPath.map(normalize) } - subenums.append( + children.append( structure(entries: entriesInKeyPath, atKeyPath: nextLevelKeyPath, usingMapper: mapper) ) } - if !subenums.isEmpty { - structuredStrings["subenums"] = subenums + if !children.isEmpty { + structuredStrings["children"] = children + + // NOTE: These are deprecated variables + structuredStrings["subenums"] = children } return structuredStrings diff --git a/SwiftGenKit.podspec b/SwiftGenKit.podspec index a450bcd..462a72e 100644 --- a/SwiftGenKit.podspec +++ b/SwiftGenKit.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "SwiftGenKit" - s.version = "1.0.1" + s.version = "1.1.0" s.summary = "The SwiftGen framework responsible for parsing assets and turn them in a dictionary representation suitable for Stencil templates" s.description = <<-DESC diff --git a/Tests/Resources b/Tests/Resources index 5abab76..8a8d0d1 160000 --- a/Tests/Resources +++ b/Tests/Resources @@ -1 +1 @@ -Subproject commit 5abab76c2255418229996267b4fc34143de12485 +Subproject commit 8a8d0d108f46f787cc5e5c2ce05fb8e1d18e0ce5 diff --git a/rakelib/utils.rake b/rakelib/utils.rake index a87ce32..36daf27 100644 --- a/rakelib/utils.rake +++ b/rakelib/utils.rake @@ -1,7 +1,11 @@ # Used constants: # none +require 'json' + class Utils + COLUMN_WIDTH = 30 + # formatter types :xcpretty # pass through xcpretty and store in artifacts :raw # store in artifacts @@ -21,6 +25,17 @@ class Utils end end + def self.podspec_version(file = '*') + JSON.parse(`bundle exec pod ipc spec #{file}.podspec`)["version"] + end + + def self.podfile_lock_version(pod) + require 'yaml' + root_pods = YAML.load_file('Podfile.lock')['PODS'].map { |n| n.is_a?(Hash) ? n.keys.first : n } + pod_vers = root_pods.select { |n| n.start_with?(pod) }.first # "SwiftGen (x.y.z)" + /\((.*)\)$/.match(pod_vers)[1] # Just the 'x.y.z' part + end + # print an info header def self.print_header(str) puts "== #{str.chomp} ==".format(:yellow, :bold) @@ -36,6 +51,21 @@ class Utils puts str.chomp.format(:red) end + # format an info message in a 2 column table + def self.table_info(label, msg) + puts "#{label.ljust(COLUMN_WIDTH)} 👉 #{msg}" + end + + # format a result message in a 2 column table + def self.table_result(result, label, error_msg) + if result + puts "#{label.ljust(COLUMN_WIDTH)} ✅" + else + puts "#{label.ljust(COLUMN_WIDTH)} ❌ - #{error_msg}" + end + result + end + ## [ Private helper functions ] ################################################## # run a command, pipe output through 'xcpretty' and store the output in CI artifacts @@ -68,9 +98,10 @@ class Utils # select the xcode version we want/support def self.version_select - xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode' && kMDItemVersion = '8.*'"`.chomp.split("\n") + version = '8.*' + xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode' && kMDItemVersion = '#{version}'"`.chomp.split("\n") if xcodes.empty? - raise "\n[!!!] You need to have Xcode 8.x to compile SwiftGen.\n\n" + raise "\n[!!!] SwiftGen requires Xcode #{version}, but we were not able to find it. If it's already installed update your Spotlight index with 'mdimport /Applications/Xcode*'\n\n" end # Order by version and get the latest one