Skip to content

Commit

Permalink
[Build] Gérer des assets et des strings propres à TchapX
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Buquet committed Nov 18, 2024
1 parent b827738 commit 7f20232
Show file tree
Hide file tree
Showing 17 changed files with 188 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
--swiftversion 5.6

--exclude ElementX/Sources/Generated,vendor,**/Package.swift,ElementX/Sources/Mocks/Generated
# Tchap: add TchapX generated files to exclusion list.
# --exclude ElementX/Sources/Generated,vendor,**/Package.swift,ElementX/Sources/Mocks/Generated
--exclude ElementX/Sources/Generated,vendor,**/Package.swift,ElementX/Sources/Mocks/Generated,TchapX/Sources/main/Generated

--disable wrapMultiLineStatementBraces
--disable hoistPatternLet
Expand Down
2 changes: 2 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ included:
excluded:
- IntegrationTests
- ElementX/Sources/Generated
# Tchap: add TchapX generated files to exclusion list.
- TchapX/Sources/main/Generated

line_length:
warning: 250
Expand Down
6 changes: 3 additions & 3 deletions TchapX/SupportingFiles/target-development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ targets:
BASE_BUNDLE_IDENTIFIER: fr.gouv.tchapx.dev
APP_NAME: TchapX-Development
APP_DISPLAY_NAME: TchapX Development # The name used in the application.

PRODUCT_NAME: $(APP_NAME)
PRODUCT_BUNDLE_IDENTIFIER: $(BASE_BUNDLE_IDENTIFIER)
ASSETCATALOG_COMPILER_APPICON_NAME: TchapX-icon
Expand All @@ -129,7 +129,6 @@ targets:
OTHER_SWIFT_FLAGS:
- "-DIS_MAIN_APP -DIS_TCHAP_DEVELOPMENT"


preBuildScripts:
- name: 🛠 SwiftGen
runOnlyWhenInstalling: false
Expand All @@ -138,7 +137,7 @@ targets:
script: |
export PATH="$PATH:/opt/homebrew/bin"
if which swiftgen >/dev/null; then
swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml
swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml --config Tools/SwiftGen/swiftgen-config-tchap.yml
else
echo "warning: SwiftGen not installed, download from https://github.com/SwiftGen/SwiftGen"
fi
Expand Down Expand Up @@ -216,6 +215,7 @@ targets:
- path: ../main/Sources
excludes:
- Other/Extensions/XCUIElement.swift
- path: ../main/Resources
- path: ../../ElementX/Resources
- path: ../../ElementX/SupportingFiles/Settings.bundle
- path: ../development/Resources
Expand Down
5 changes: 3 additions & 2 deletions TchapX/SupportingFiles/target-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ targets:
PILLS_UT_TYPE_IDENTIFIER: $(BASE_BUNDLE_IDENTIFIER).pills
OTHER_SWIFT_FLAGS:
- "-DIS_MAIN_APP -DIS_TCHAP_PRODUCTION"

preBuildScripts:
- name: 🛠 SwiftGen
runOnlyWhenInstalling: false
Expand All @@ -137,7 +137,7 @@ targets:
script: |
export PATH="$PATH:/opt/homebrew/bin"
if which swiftgen >/dev/null; then
swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml
swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml --config Tools/SwiftGen/swiftgen-config-tchap.yml
else
echo "warning: SwiftGen not installed, download from https://github.com/SwiftGen/SwiftGen"
fi
Expand Down Expand Up @@ -215,6 +215,7 @@ targets:
- path: ../main/Sources
excludes:
- Other/Extensions/XCUIElement.swift
- path: ../main/Resources
- path: ../../ElementX/Resources
- path: ../../ElementX/SupportingFiles/Settings.bundle
- path: ../production/Resources
Expand Down
5 changes: 3 additions & 2 deletions TchapX/SupportingFiles/target-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ targets:
PILLS_UT_TYPE_IDENTIFIER: $(BASE_BUNDLE_IDENTIFIER).pills
OTHER_SWIFT_FLAGS:
- "-DIS_MAIN_APP -DIS_TCHAP_STAGING"

preBuildScripts:
- name: 🛠 SwiftGen
runOnlyWhenInstalling: false
Expand All @@ -137,7 +137,7 @@ targets:
script: |
export PATH="$PATH:/opt/homebrew/bin"
if which swiftgen >/dev/null; then
swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml
swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml --config Tools/SwiftGen/swiftgen-config-tchap.yml
else
echo "warning: SwiftGen not installed, download from https://github.com/SwiftGen/SwiftGen"
fi
Expand Down Expand Up @@ -215,6 +215,7 @@ targets:
- path: ../main/Sources
excludes:
- Other/Extensions/XCUIElement.swift
- path: ../main/Resources
- path: ../../ElementX/Resources
- path: ../../ElementX/SupportingFiles/Settings.bundle
- path: ../staging/Resources
Expand Down
3 changes: 2 additions & 1 deletion TchapX/development/SupportingFiles/NSE/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,5 @@ targets:
- path: ../../../../ElementX/Sources/AppHooks/AppHooks.swift
- path: ../../../../ElementX/Sources/AppHooks/Hooks/ClientBuilderHook.swift
- path: ../PrivacyInfo.xcprivacy
# - path: ../../../main/Sources/Other/Helpers/TchapX-String.swift
- path: ../../../main/Sources/Generated/TchapAssets.swift
- path: ../../../main/Sources/Generated/TchapStrings.swift
6 changes: 6 additions & 0 deletions TchapX/main/Resources/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Localizable.strings
TchapX

Created by Nicolas Buquet on 18/11/2024.
Copyright © 2024 Tchap. All rights reserved.
*/

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Untranslated.strings
TchapX

Created by Nicolas Buquet on 18/11/2024.
Copyright © 2024 Tchap. All rights reserved.
*/

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Localizable.strings
TchapX

Created by Nicolas Buquet on 18/11/2024.
Copyright © 2024 Tchap. All rights reserved.
*/

38 changes: 38 additions & 0 deletions TchapX/main/Sources/Generated/TchapAssets.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// swiftlint:disable all
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen

#if os(macOS)
import AppKit
#elseif os(iOS)
import UIKit
#elseif os(tvOS) || os(watchOS)
import UIKit
#endif
#if canImport(SwiftUI)
import SwiftUI
#endif

// Deprecated typealiases

// swiftlint:disable superfluous_disable_command file_length implicit_return

// MARK: - Asset Catalogs

// swiftlint:disable identifier_name line_length nesting type_body_length type_name
internal enum TchapAssets {
}
// swiftlint:enable identifier_name line_length nesting type_body_length type_name

// MARK: - Implementation Details

// swiftlint:disable convenience_type
private final class BundleToken {
static let bundle: Bundle = {
#if SWIFT_PACKAGE
return Bundle.module
#else
return Bundle(for: BundleToken.self)
#endif
}()
}
// swiftlint:enable convenience_type
28 changes: 28 additions & 0 deletions TchapX/main/Sources/Generated/TchapStrings+Untranslated.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swiftlint:disable all
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen

import Foundation

// swiftlint:disable superfluous_disable_command file_length implicit_return

// MARK: - Strings

// swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length
// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces
internal enum TchapUntranslatedL10n {
}
// swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length
// swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces

// MARK: - Implementation Details

extension TchapUntranslatedL10n {
static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
// No need to check languages, we always default to en for untranslated strings
guard let bundle = Bundle.lprojBundle(for: "en") else { return key }
let format = NSLocalizedString(key, tableName: table, bundle: bundle, comment: "")
return String(format: format, locale: Locale(identifier: "en"), arguments: args)
}
}

// swiftlint:enable all
41 changes: 41 additions & 0 deletions TchapX/main/Sources/Generated/TchapStrings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// swiftlint:disable all
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen

import Foundation

// swiftlint:disable superfluous_disable_command file_length implicit_return

// MARK: - Strings

// swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length
// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces
internal enum TchapL10n {
}
// swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length
// swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces

// MARK: - Implementation Details

extension TchapL10n {
static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
// Use preferredLocalizations to get a language that is in the bundle and the user's preferred list of languages.
let languages = Bundle.overrideLocalizations ?? Bundle.app.preferredLocalizations

for language in languages {
if let translation = trIn(language, table, key, args) {
return translation
}
}
return Bundle.app.developmentLocalization.flatMap { trIn($0, table, key, args) } ?? key
}

private static func trIn(_ language: String, _ table: String, _ key: String, _ args: CVarArg...) -> String? {
guard let bundle = Bundle.lprojBundle(for: language) else { return nil }
let format = NSLocalizedString(key, tableName: table, bundle: bundle, comment: "")
let translation = String(format: format, locale: Locale(identifier: language), arguments: args)
guard translation != key else { return nil }
return translation
}
}

// swiftlint:enable all
3 changes: 2 additions & 1 deletion TchapX/production/SupportingFiles/NSE/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,5 @@ targets:
- path: ../../../../ElementX/Sources/AppHooks/AppHooks.swift
- path: ../../../../ElementX/Sources/AppHooks/Hooks/ClientBuilderHook.swift
- path: ../PrivacyInfo.xcprivacy
# - path: ../../../main/Sources/Other/Helpers/TchapX-String.swift
- path: ../../../main/Sources/Generated/TchapAssets.swift
- path: ../../../main/Sources/Generated/TchapStrings.swift
3 changes: 2 additions & 1 deletion TchapX/staging/SupportingFiles/NSE/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,5 @@ targets:
- path: ../../../../ElementX/Sources/AppHooks/AppHooks.swift
- path: ../../../../ElementX/Sources/AppHooks/Hooks/ClientBuilderHook.swift
- path: ../PrivacyInfo.xcprivacy
# - path: ../../../main/Sources/Other/Helpers/TchapX-String.swift
- path: ../../../main/Sources/Generated/TchapAssets.swift
- path: ../../../main/Sources/Generated/TchapStrings.swift
29 changes: 29 additions & 0 deletions Tools/SwiftGen/swiftgen-config-tchap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
input_dir: ../../TchapX/main/
output_dir: ../../TchapX/main/Sources/Generated/
xcassets:
inputs:
- Resources/Assets.xcassets
outputs:
templateName: swift5
output: TchapAssets.swift
params:
enumName: TchapAssets # To not conflict with ElementX/Assets.swift
strings:
- inputs: Resources/Localizations/en.lproj
filter: TchapLocalizable*
outputs:
templatePath: Templates/Strings/structured-swift5-element.stencil
output: TchapStrings.swift
params:
enumName: TchapL10n
lookupFunction: tr # used for the loc to be computed variables
publicAccess: false
- inputs: Resources/Localizations/en.lproj
filter: TchapUntranslated*
outputs:
templatePath: Templates/Strings/structured-swift5-element-untranslated.stencil
output: TchapStrings+Untranslated.swift
params:
enumName: TchapUntranslatedL10n
lookupFunction: tr # used for the loc to be computed variables
publicAccess: false
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ ignore:
- "**/Mock*.swift"
- "**/*Mock.swift"
- "**/*Proxy.swift"
# Tchap: add TchapX generated files to exclusion list.
- "TchapX/Sources/main/Generated"

flag_management:
default_rules:
Expand Down

0 comments on commit 7f20232

Please sign in to comment.