Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS-10444 Mistica tokens generator #387

Merged
merged 11 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions .github/workflows/generate-mistica-tokens.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,40 @@ name: Generate Mistica Tokens

on:
workflow_dispatch:
inputs:
ref:
description: 'mistica-design repo changeset or branch'
required: false
default: 'production'

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
get-design-tokens:
name: Get Design Tokens
runs-on: self-hosted-novum-mac
build:
name: Build & generate tokens
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4

- name: Install dependencies
run: npm install
working-directory: scripts/mistica-skin-generator

- name: Generate Skin
run: make skin ref=${{github.event.inputs.ref}}
- name: Generate tokens
run: npm run generate
working-directory: scripts/mistica-skin-generator

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.NOVUM_PRIVATE_REPOS }}
add-paths: 'Sources/MisticaCommon/*'
commit-message: 'feat(skin): update design tokens'
title: 'feat(skin): update design tokens from mistica-design branch: ${{github.event.inputs.ref}}'
branch: 'import-design-tokens'
team-reviewers: 'ios'
delete-branch: true
- name: Create Pull Request
id: create_pr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.NOVUM_PRIVATE_REPOS }}
add-paths: 'Sources/MisticaCommon/*'
commit-message: 'feat(skin): update design tokens'
title: 'feat(skin): update design tokens from mistica-design'
branch: 'import-design-tokens'
team-reviewers: 'ios'
delete-branch: true
- name: Show URL in summary annotation
run: echo '::notice::Pull Request generated ${{ steps.create_pr.outputs.pull-request-url }}'
30 changes: 30 additions & 0 deletions .github/workflows/mistica-skin-generator-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Mistica skin generator tests

on:
workflow_dispatch:
push:
paths:
- 'scripts/mistica-skin-generator/**'

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build & execute tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4

- name: Install dependencies
run: npm install
working-directory: scripts/mistica-skin-generator

- name: Run tests
run: npm run test
working-directory: scripts/mistica-skin-generator
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ fastlane/test_output
# ci
.ruby-version
vendor/

# Mistica skin generator
scripts/mistica-skin-generator/.vscode
scripts/mistica-skin-generator/node_modules
scripts/mistica-skin-generator/package-lock.json
30 changes: 0 additions & 30 deletions .hygen.js

This file was deleted.

6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint"
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"eslint.workingDirectories": [
"scripts/mistica-skin-generator"
]
}
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ In order to automatise this, we can execute this [GitHub action](.github/.workfl
You can also execute it manually using the actions defined in the [Makefile](Makefile).
Example:
```bash
make skin ref=production
make skin
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will always get the production branch.
I've added doc to change this but I think it was not useful in the past...

```

## Testing
Expand Down
64 changes: 9 additions & 55 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help setup format test simulator archive export clean skinGeneratorSetup colorPaletteGeneration cornerRadiusGeneration fontWeightsGeneration fontSizesGeneration skin
.PHONY: help setup format test simulator archive export clean skin

# Simulator
OS_VERSION := 17.2
Expand All @@ -22,53 +22,24 @@ BUILD_PATH := $(ROOT_DIR)/build
EXPORTED_OPTIONS_PATH := $(ROOT_DIR)/enterprise.plist
ARCHIVE_PATH := $(TMP_ROOT_PATH)/ios.xcarchive
XCODEBUILD := set -o pipefail && xcodebuild
MISTICA_DESIGN_PATH := $(ROOT_DIR)/tmp/mistica-design
MISTICA_DESIGN_TOKENS_PATH := /tokens
MISTICA_DESIGN_URL := https://raw.githubusercontent.com/Telefonica/mistica-design/$(ref)/tokens

#Skin tokens config
#These variables will be used to get the json file from mistica design repository and later to create the appropiate file and class/struct names. If a new brand/skin needs to be added, it should be added here. All of the brand names should be in lowercase.
Movistar:= movistar
Blau:= blau
O2:= o2
O2New:= o2-new
Vivo:= vivo
VivoNew:= vivo-new
Telefonica:= telefonica
TU:= tu
BRAND_FILES:= $(Movistar) $(Blau) $(O2) $(O2New) $(Vivo) $(VivoNew) $(Telefonica) $(TU) # List of all the brand names that will be procesed.

# Xcode
ifneq ($(origin GITHUB_ACTION),undefined)
export DEVELOPER_DIR=/Applications/Xcode-15.2.app/Contents/Developer
endif

# TokenGenerator func to be used in all token generators.
define tokenGenerator
@echo "Generating Mistica $(2) interfaces"
hygen $(1) Mistica$(2) --json $(MISTICA_DESIGN_PATH)$(MISTICA_DESIGN_TOKENS_PATH)/$(Movistar).json

for key in $(BRAND_FILES) ; do \
echo "Generating $$key $(2) palette"; \
hygen $(1) Brand$(2) --name $$key --json $(MISTICA_DESIGN_PATH)$(MISTICA_DESIGN_TOKENS_PATH)/$$key.json ; \
done
endef

# Targets
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " setup to set up dependencies"
@echo " format to execute swiftformat in Sources directory"
@echo " test to build and test the main target"
@echo " simulator to install the simulator for testing"
@echo " export to export the archived project as an .ipa"
@echo " export to export the archived project as an .ipa"
@echo " clean to remove all temporal files"
@echo " skinGeneratorSetup to setup skin dependencies"
@echo " colorPaletteGeneration ref=<ref> to setup and regenerate MisticaColors with new palettes from mistica design where <ref> is the branch from mistica-design repository from where we want to generate the tokens"
@echo " cornerRadiusGeneration ref=<ref> to setup and regenerate MisticaCornerRadius with new palettes from mistica design where <ref> is the branch from mistica-design repository from where we want to generate the tokens"
@echo " fontWeightsGeneration ref=<ref> to setup and regenerate MisticaFontWeights with new palettes from mistica design where <ref> is the branch from mistica-design repository from where we want to generate the tokens"
@echo " fontSizesGeneration ref=<ref> to setup and regenerate MisticaFontSizes with new palettes from mistica design where <ref> is the branch from mistica-design repository from where we want to generate the tokens"
@echo " skin ref=<ref> to setup, regenerate and format tokens from mistica design where <ref> is the branch from mistica-design repository from where we want to generate the tokens"
@echo " skin to regenerate and format tokens from mistica design"

trace:
@echo "Current xcodebuild configuration"
Expand All @@ -85,9 +56,9 @@ setup: trace
@brew ls xcbeautify --versions || brew install xcbeautify

skinGeneratorSetup:
@echo "Installing tokens generators dependencies"
@echo "Installing tokens generator dependencies"
@brew ls node --versions || brew install node
@brew ls hygen --versions || (brew tap jondot/tap && brew install hygen)
cd scripts/mistica-skin-generator && npm install

format:
Scripts/swiftformat .
Expand Down Expand Up @@ -131,25 +102,8 @@ export: clean setup

@rm -rf "$(TMP_ROOT_PATH)"

getMisticaDesignTokenFiles:
@echo "Obtaining mistica token files"
for key in $(BRAND_FILES) ; do \
curl -o $(MISTICA_DESIGN_PATH)$(MISTICA_DESIGN_TOKENS_PATH)/$$key.json --create-dirs $(MISTICA_DESIGN_URL)/$$key.json ; \
done

colorPaletteGeneration: skinGeneratorSetup getMisticaDesignTokenFiles
$(call tokenGenerator,ColorTokenGenerator,Colors)

cornerRadiusGeneration: skinGeneratorSetup getMisticaDesignTokenFiles
$(call tokenGenerator,CornerRadiusTokenGenerator,CornerRadius)

fontWeightsGeneration: skinGeneratorSetup getMisticaDesignTokenFiles
$(call tokenGenerator,FontWeightsTokenGenerator,FontWeights)

fontSizesGeneration: skinGeneratorSetup getMisticaDesignTokenFiles
$(call tokenGenerator,FontSizesTokenGenerator,FontSizes)

removeMisticaDesignTokenFolder:
rm -rf $(MISTICA_DESIGN_PATH)
tokensGeneration:
@echo "Executing tokens generation tool..."
cd scripts/mistica-skin-generator && npm run generate

skin: colorPaletteGeneration cornerRadiusGeneration fontWeightsGeneration fontSizesGeneration removeMisticaDesignTokenFolder format
skin: tokensGeneration format
9 changes: 0 additions & 9 deletions Sources/MisticaCommon/Colors/ColorToolkit+UIColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -644,12 +644,3 @@ public extension UIColor {
MisticaConfig.currentColors.tagBackgroundError
}
}

public extension BrandStyle {
var preferredStatusBarStyle: UIStatusBarStyle {
switch self {
case .movistar, .vivo, .o2, .o2New, .blau, .custom, .vivoNew, .tu, .telefonica:
return .lightContent
}
}
}
18 changes: 18 additions & 0 deletions Sources/MisticaCommon/Extensions/BrandStyle+UIStatusBarStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// BrandStyle+UIStatusBarStyle.swift
//
// Made with ❤️ by Novum
//
// Copyright © Telefonica. All rights reserved.
//

import UIKit

public extension BrandStyle {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to a different file since it shouldn't be auto-generated

var preferredStatusBarStyle: UIStatusBarStyle {
switch self {
case .movistar, .vivo, .o2, .o2New, .blau, .custom, .vivoNew, .tu, .telefonica:
return .lightContent
}
}
}
48 changes: 0 additions & 48 deletions _templates/ColorTokenGenerator/BrandColors/BrandColorsAction.ejs.t

This file was deleted.

This file was deleted.

Loading
Loading