Skip to content

Commit

Permalink
feat: display tokens library version in doc and Design Toolbox with u…
Browse files Browse the repository at this point in the history
…pdate script (#425)

Closes #425

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
  • Loading branch information
pylapp committed Feb 5, 2025
1 parent a9f2231 commit dc6e0bf
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [Tool] Add with a script the token library version in documentation and Design Toolbox ([#425](https://github.com/Orange-OpenSource/ouds-ios/issues/425))
- [DesignToolbox] Add text field in component configuration to customize text ([#436](https://github.com/Orange-OpenSource/ouds-ios/issues/436))
- [Library] Link component ([#400](https://github.com/Orange-OpenSource/ouds-ios/issues/400))

Expand Down
3 changes: 2 additions & 1 deletion DesignToolbox/DesignToolbox/Pages/About/AboutPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ struct AboutPage: View {
}

// TODO: Only for debug purposes, should be displayed in another way
Text("Version: \(Bundle.main.marketingVersion)")
Text("\(Bundle.main.tokensLibraryVersion)")
Text("App version: \(Bundle.main.marketingVersion)")
Text("Build number: \(Bundle.main.buildNumber)")
Text("Build type: \(Bundle.main.fullBuildType)")
if let buildDetails = Bundle.main.buildDetails {
Expand Down
4 changes: 4 additions & 0 deletions DesignToolbox/DesignToolbox/Utils/Bundle+extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ extension Bundle {
return "\(type)\(tag)"
}

var tokensLibraryVersion: String {
"Tokens version: 0.5.0"
}

// MARK: Private Implementation

private func string(forInfoDictionaryKey key: String) -> String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ They can be seen as a kind of bridge between components and in the end primitive

<!-- NOTE: Do not forget to update tokens version -->
```
🧱 Tokens version: v0.5.0
🧱 Tokens version: 0.5.0
```

Thus if a component need to change for example its _background color_, and if a _component token_ is used for it, then only the value of this _token_ should be changed without any modification on the _component_ definition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _Raw tokens_ are smallest _tokens_ possible. They are associated to raw values a

<!-- NOTE: Do not forget to update tokens version -->
```
🧱 Tokens version: v0.5.0
🧱 Tokens version: 0.5.0
```

In fact, we choose to use as most as possible primitive types for raw values, like `Int`, `Double`, `CGFloat` or `String` so as to handle the smallest types with few impacts on the memory for ecodesign principles. Indeed with hundreds of raw tokens, it will be more efficient to store primitive small types than Swift `struct` or `class` objects. Keeping primitive types helps today to expose objects using Objective-C runtime.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ They can be seen as an high level of usage with functional meanings.

<!-- NOTE: Do not forget to update tokens version -->
```
🧱 Tokens version: v0.5.0
🧱 Tokens version: 0.5.0
```

If we need for example to change a warning color for a button (which has its component tokens, see [OUDSTokensComponent](https://ios.unified-design-system.orange.com/documentation/oudstokenscomponent/)), supposing this color is defined as a _semantic token_, we only have to change its assigned value and all components using the _semantic token_ won't be impacted in their definition. In fact, semantic tokens are here to bring meaning, semantic, between raw values and components.
Expand Down
117 changes: 117 additions & 0 deletions docs_release/updateTokensLibraryVersion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/bash
#
# Software Name: OUDS iOS
# SPDX-FileCopyrightText: Copyright (c) Orange SA
# SPDX-License-Identifier: MIT
#
# This software is distributed under the MIT license,
# the text of which is available at https://opensource.org/license/MIT/
# or see the "LICENSE" file for more details.
#
# Authors: See CONTRIBUTORS.txt
# Software description: A SwiftUI components library with code examples for Orange Unified Design System
#

set -euo pipefail

# Configuration
# -------------

TEMPLATE_TO_LOOK_FOR="Tokens version: "

FILES_TO_PROCESS=(
"../DesignToolbox/DesignToolbox/Utils/Bundle+extension.swift"
"../OUDS/Core/Tokens/ComponentTokens/Sources/_OUDSTokensComponent.docc/OUDSTokensComponent.md"
"../OUDS/Core/Tokens/RawTokens/Sources/_OUDSTokensRaw.docc/OUDSTokensRaw.md"
"../OUDS/Core/Tokens/SemanticTokens/Sources/_OUDSTokensSemantic.docc/OUDSTokensSemantic.md"
)

# Errors
# ------

EXIT_OK=0
EXIT_ERROR_BAD_PARAMETER_COUNT=1
EXIT_ERROR_MISSING_ARGUMENT=2
EXIT_ERROR_UNKNOWN_PARAMETER=3
EXIT_ERROR_MISSING_FILE_TO_PROCESS=4
EXIT_ERROR_MISSING_TEMPLATE_IN_FILE_TO_PROCESS=5
EXIT_ERROR_TOO_MANY_OCCURENCES_OF_TEMPLATE=6

# Utils
# -----

function display_help {
echo "Usage: $0 --version <value>"
echo
echo "Options:"
echo " --version <value> The value to use in the files in place of the predefined template (format x.y.z)"
echo
echo "This script composes occurences of '$TEMPLATE_TO_LOOK_FOR' in some predefined files with the given value, looking for old x.y.z version and replace by new one"
}

# Service
# --------

# Check parameters

if [[ "$#" -eq 0 ]]; then
display_help
exit $EXIT_ERROR_BAD_PARAMETER_COUNT
fi

if [[ "$#" -ne 2 ]]; then
echo "❌ Error: Too few or too many parameter(s)."
exit $EXIT_ERROR_BAD_PARAMETER_COUNT
fi

versionToInject=""

# Process arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--version)
if [[ -n "$2" ]]; then
versionToInject="$2"
shift
else
echo "❌ Error: No value given for --version."
exit $EXIT_ERROR_MISSING_ARGUMENT
fi
;;
*)
echo "❌ Error: Unknown parameter '$1'."
exit $EXIT_ERROR_UNKNOWN_PARAMETER
;;
esac
shift
done

# Replace any template occurences in the files predefined above
for file in "${FILES_TO_PROCESS[@]}"; do

# Check if nthe file exists
if [[ ! -f "$file" ]]; then
echo "❌ Error: The file '$file' does not exist"
exit $EXIT_ERROR_MISSING_FILE_TO_PROCESS
fi

# Ensure we have only one occurence to replace, othrwise it could mean side effects
count=$(grep -c "$TEMPLATE_TO_LOOK_FOR" "$file")
if [[ $count -ne 1 ]]; then
echo "❌ Error: The pattern appears not enough or too many times in the file '$file'."
exit $EXIT_ERROR_TOO_MANY_OCCURENCES_OF_TEMPLATE
fi

if ! grep -q "$TEMPLATE_TO_LOOK_FOR" "$file"; then
echo "❌ Error: Missing template '$TEMPLATE_TO_LOOK_FOR' in file '$file'."
exit $EXIT_ERROR_MISSING_TEMPLATE_IN_FILE_TO_PROCESS
fi

# Keep items before and after template, keep tempalte and replace old x.y.z by the value
sed -i '' -E "s/(${TEMPLATE_TO_LOOK_FOR})([0-9]+\.[0-9]+\.[0-9]+)/\1$versionToInject/" "$file"

echo "✔️ Updated file '$file'"
done

echo "👋 Bye!"
exit $EXIT_OK

0 comments on commit dc6e0bf

Please sign in to comment.