Skip to content

Commit

Permalink
Create Makefile. Update Logger. Add excluded paths
Browse files Browse the repository at this point in the history
  • Loading branch information
timbaev committed Aug 12, 2019
1 parent 43e2d98 commit ba6b311
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 8 deletions.
67 changes: 67 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
PRODUCT_NAME = LocalizedGenStrings
VERSION = $(version)

PREFIX ?= /usr/local

CD = cd
CP = $(shell whereis cp) -Rf
GIT = $(shell which git)
HUB = $(shell which hub)
MKDIR = $(shell which mkdir) -p
RM = $(shell whereis rm) -rf
SED = /usr/bin/sed
SWIFT = $(shell which swift)
TAR = $(shell whereis tar) cJf

TARGET_PLATFORM = x86_64-apple-macosx
TARBALL = "LocalizedGetStrings-$(VERSION).mojave.tar.xz"

BINARY_DIRECTORY = $(PREFIX)/bin
BUILD_DIRECTORY = $(shell pwd)/.build/$(TARGET_PLATFORM)/release
OUTPUT_EXECUTABLE = $(BUILD_DIRECTORY)/$(PRODUCT_NAME)
INSTALL_EXECUTABLE_PATH = $(BINARY_DIRECTORY)/$(PRODUCT_NAME)

SWIFT_BUILD_FLAGS = --configuration release --disable-sandbox

.PHONY: all
all: build

.PHONY: test
test: clean
$(SWIFT) test

.PHONY: build
build:
$(SWIFT) build $(SWIFT_BUILD_FLAGS)

.PHONY: install
install: build
$(MKDIR) $(BINARY_DIRECTORY)
$(CP) "$(OUTPUT_EXECUTABLE)" "$(BINARY_DIRECTORY)"

.PHONY: package
package: build
$(CD) "$(BUILD_DIRECTORY)" && $(TAR) $(TARBALL) "$(PRODUCT_NAME)"
$(CP) "$(BUILD_DIRECTORY)/$(TARBALL)" $(TARBALL)

.PHONY: release
release: clean package
$(GIT) --git-dir=../homebrew-tap/.git pull origin master
$(SED) -i '' '4s/.*/ version "$(VERSION)"/' ../homebrew-tap/swiftbrew.rb
$(SED) -i '' '6s/.*/ sha256 "$(shell shasum -a 256 "$(TARBALL)" | cut -f 1 -d " ")"/' ../homebrew-tap/swiftbrew.rb
$(HUB) release create --message $(VERSION) --attach $(TARBALL) $(VERSION)
$(CD) ../homebrew-tap && \
$(GIT) commit swiftbrew.rb -m "Release version $(VERSION)"
$(GIT) --git-dir=../homebrew-tap/.git push origin master

.PHONY: xcode
xcode:
$(SWIFT) package generate-xcodeproj

.PHONY: uninstall
uninstall:
$(RM) "$(BINARY_DIRECTORY)/$(PRODUCT_NAME)"

.PHONY: clean
clean:
$(SWIFT) package clean
16 changes: 15 additions & 1 deletion Sources/LocalizedGenStringsCore/CommandLineTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public final class CommandLineTool {
}
}

// MARK: -

private enum Constants {

// MARK: - Type Properties

static let excludedPaths = ["Pods"]
}

// MARK: - Instance Properties

private let arguments: [String]
Expand Down Expand Up @@ -61,7 +70,12 @@ public final class CommandLineTool {

private func run(path: String, lang: String? = nil, key: String? = nil) throws {
let enumerator = FileManager.default.enumerator(atPath: path)
let filePaths = enumerator?.allObjects as? [String]

let filePaths = (enumerator?.allObjects as? [String])?.filter { filePath in
let components = filePath.components(separatedBy: "/")

return !components.intersects(with: Constants.excludedPaths)
}

guard let xcodeprojPath = filePaths?.first(where: { $0.contains(".xcodeproj") }) else {
throw Error.xcodeProjectNotFound
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// SequenceExtension.swift
// LocalizedGenStringsCore
//
// Created by Timur Shafigullin on 12/08/2019.
//

import Foundation

extension Sequence where Iterator.Element: Hashable {

// MARK: - Instance Methods

func intersects<S: Sequence>(with sequence: S) -> Bool where S.Iterator.Element == Iterator.Element {
let sequenceSet = Set(sequence)

return self.contains(where: sequenceSet.contains)
}
}
12 changes: 6 additions & 6 deletions Sources/LocalizedGenStringsCore/Tools/Log.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ private enum LogEvent: String {

// MARK: - Enumeration Cases

case e = "[‼️]" // error
case i = "[ℹ️]" // info
case d = "[💬]" // debug
case v = "[🔬]" // verbose
case w = "[⚠️]" // warning
case s = "[🔥]" // severe
case e = "‼️" // error
case i = "ℹ️" // info
case d = "💬" // debug
case v = "🔬" // verbose
case w = "⚠️" // warning
case s = "🔥" // severe
}

// MARK: - OutputType
Expand Down
4 changes: 3 additions & 1 deletion Sources/LocalizedGenStringsCore/Writer/DefaultWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class DefaultWriter: Writer {
static let generatedFilename = "Localizable.strings"

static let pattern = #"(".*?") = (".*");"#

static let excludedPaths = ["Pods"]
}

// MARK: - Instance Methods
Expand All @@ -45,7 +47,7 @@ class DefaultWriter: Writer {
if element.hasSuffix("\(lang).lproj") {
let localizableFilePath = mainProjectPath + Path(element) + Path(Constants.generatedFilename)

if localizableFilePath.exists {
if localizableFilePath.exists, !localizableFilePath.components.intersects(with: Constants.excludedPaths) {
return localizableFilePath
}
}
Expand Down

0 comments on commit ba6b311

Please sign in to comment.