Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
feat: add swift deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
braddialpad committed Sep 29, 2022
1 parent 06b8c10 commit df2750f
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 7 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy production - Swift
if: ${{ github.ref == 'refs/heads/production' }}
uses: cpina/github-action-push-to-another-repository@v1.5.1
env:
API_TOKEN_GITHUB: ${{ secrets.DIALTONE_NPM_TOKEN }}
with:
user-email: 'dialtone@dialpad.com'
source-directory: 'dist_ios'
destination-repository-name: 'dialtone-tokens-swift'
destination-github-username: 'dialpad'
commit-message: "dialtone-tokens-swift release"

- name: Github Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist*
dist*/*
!dist_ios/Package.swift
tokens
8 changes: 6 additions & 2 deletions build-ios.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/usr/bin/env node
const fs = require('fs');

fs.copyFile('dist/ios/dialtone.swift', 'dist_ios/Sources', (err) => {
if (!fs.existsSync('dist_ios/Sources')) {
fs.mkdirSync('dist_ios/Sources')
}

fs.copyFile('dist/ios/tokens.swift', 'dist_ios/Sources/tokens.swift', (err) => {
if (err) throw err;
console.log('dialtone.swift was copied to dist_ios/Sources');
console.log('dialtone.swift was copied to dist_ios/Sources/tokens.swift');
});
50 changes: 50 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ StyleDictionary.registerTransform({
}
});

StyleDictionary.registerTransform({
name: 'dt/swiftColor',
type: 'value',
matcher: function(token) {
return ['color'].includes(token.type)
},
transformer: (token, options) => {
const { r, g, b, a } = Color(token.value).toRgb();
const rFixed = (r / 255.0).toFixed(3);
const gFixed = (g / 255.0).toFixed(3);
const bFixed = (b / 255.0).toFixed(3);
return `UIColor(red: ${rFixed}, green: ${gFixed}, blue: ${bFixed}, alpha: ${a})`;
}
});


StyleDictionary.registerTransform({
name: 'dt/size/pxToRem',
Expand Down Expand Up @@ -140,6 +155,24 @@ StyleDictionary.registerTransform({
}
});

StyleDictionary.registerTransform({
name: 'dt/size/pxToCGFloat',
type: 'value',
matcher: function(token) {
return [...SPACING_IDENTIFIERS, ...SIZE_IDENTIFIERS].includes(token.type)
},
transformer: (token, options) => {
const baseFont = 16;
const floatVal = parseFloat(token.value);

if (isNaN(floatVal)) {
throwSizeError(token.name, token.value, 'dp');
}

return `CGFloat(${(floatVal / baseFont).toFixed(2)})`;
}
});

StyleDictionary.registerTransform({
name: 'dt/lineHeight/percentToDecimal',
type: 'value',
Expand All @@ -161,6 +194,23 @@ StyleDictionary.registerTransform({
}
});

StyleDictionary.registerTransform({
name: 'dt/lineHeight/swift/percentToDecimal',
type: 'value',
matcher: function(token) {
return ['opacity', ...LINE_HEIGHT_IDENTIFIERS].includes(token.type)
},
transformer: (token, options) => {
const floatVal = parseFloat(token.value);

if (isNaN(floatVal)) {
throwSizeError(token.name, token.value, '%');
}

return `CGFloat(${(floatVal).toFixed(2)})`;
}
});

StyleDictionary.registerTransform({
name: 'dt/stringify',
type: 'value',
Expand Down
10 changes: 7 additions & 3 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,22 @@ module.exports = {
className: 'DialtoneTokens',
filter: function(token) {
return token.path[0] !== 'tokenSetOrder';
},
},
}
]
},
ios: {
transformGroup: 'ios',
transforms: ['dt/fonts/transformToStack', 'attribute/cti', 'name/cti/camel', 'dt/swiftColor', 'dt/size/pxToCGFloat', 'dt/lineHeight/swift/percentToDecimal', 'dt/stringify'],
prefix: 'dt',
buildPath: 'dist/ios/',
files: [
{
destination: 'dialtone.swift',
destination: 'tokens.swift',
format: 'ios-swift/enum.swift',
className: 'DialtoneTokens',
filter: function(token) {
return token.path[0] !== 'tokenSetOrder';
},
},
],
},
Expand Down
25 changes: 25 additions & 0 deletions dist_ios/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "dialtone-tokens",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "dialtone-tokens",
targets: ["dialtone-tokens"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "dialtone-tokens",
dependencies: []),
]
)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "npm run transform && ./build.js",
"build": "npm run transform && ./build.js && ./build-android.js && ./build-ios.js",
"transform": "token-transformer base.json tokens/tokens.json --expandTypography=true --expandShadow=true",
"prepublishOnly": "npm run build",
"release": "semantic-release --no-ci --extends ./release-local.config.js"
Expand Down

0 comments on commit df2750f

Please sign in to comment.