Skip to content

Commit

Permalink
Merge pull request #6 from ZeroGachis/task/clean-repo
Browse files Browse the repository at this point in the history
🚚
  • Loading branch information
ulricden authored Feb 16, 2024
2 parents b689e4f + e64ac79 commit 93292ad
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 14 deletions.
43 changes: 43 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"settings": {
"react": {
"version": "detect"
}
},
"overrides": [],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"plugins": ["react", "@typescript-eslint", "react-hooks", "prettier"],
"rules": {
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/space-before-function-paren": 0,
"prefer-arrow-callback": "error",
"react/function-component-definition": [
"error",
{
"namedComponents": "arrow-function",
"unnamedComponents": "arrow-function"
}
],
"react/prop-types": "off"
},
"ignorePatterns": ["*/*.config.js", "*.config.js"],
"root": true
}
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import tokens from "./Tokens";
import tokens from "./src";

export default tokens;
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Smartway design tokens",
"main": "tokens.json",
"scripts": {
"test": "echo \"Test\" && exit 1"
"type:check": "tsc",
"tsc": "tsc --project tsconfig.build.json"
},
"repository": {
"type": "git",
Expand Down
35 changes: 25 additions & 10 deletions Tokens.ts → src/Tokens.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as tokensJson from "./tokens.json";
import * as tokensJson from "../tokens.json";
import {
BoxShadows,
BoxShadow,
Expand All @@ -14,7 +14,7 @@ import {
Color,
} from "./TokensType";

const parseShadow = (value: any): BoxShadow | undefined => {
const parseShadow = (value: any): BoxShadow | void => {
if (typeof value !== "string")
return {
color: value.color,
Expand All @@ -28,8 +28,11 @@ const parseShadow = (value: any): BoxShadow | undefined => {

const parseAliasShadow =
(shadow: BoxShadows) =>
(value: any): BoxShadow | undefined => {
if (typeof value === "string") return shadow[value.replace(/\D/g, "")];
(value: any): BoxShadow | void => {
if (typeof value === "string") {
const key = value.replace(/\D/g, "");
return shadow[key as keyof BoxShadows];
}
};

const parseTypography =
Expand All @@ -38,12 +41,24 @@ const parseTypography =
return {
fontWeight:
font.fontWeight[
value["fontWeight"].replace("}", "").split(".").slice(-1)
value["fontWeight"]
.replace("}", "")
.split(".")
.slice(-1)[0] as keyof FontWeight
],
fontSize:
font.fontSize[value["fontSize"].replace("}", "").split(".").slice(-1)],
font.fontSize[
value["fontSize"]
.replace("}", "")
.split(".")
.slice(-1)[0] as keyof FontSize
],
fontFamily:
font.fontFamily[value["fontFamily"].replace("{", "").replace("}", "")],
font.fontFamily[
value["fontFamily"]
.replace("{", "")
.replace("}", "") as keyof FontFamily
],
};
};

Expand All @@ -58,14 +73,14 @@ const getValueToken = <T, R>(
Object.keys(value).forEach((key) => {
const parsedValue = parseMethod(value[key].value);
if (parsedValue) {
values[key] = parseMethod(value[key].value);
(values as Record<string, R>)[key] = parsedValue;
}
});
return values as T;
};

const getTokens = () => {
const shadows = getValueToken<BoxShadows, BoxShadow | undefined>(
const shadows = getValueToken<BoxShadows, BoxShadow | void>(
tokensJson.global.shadow,
parseShadow
);
Expand All @@ -90,7 +105,7 @@ const getTokens = () => {
),
boxShadow: {
...shadows,
...getValueToken<BoxShadows, BoxShadow | undefined>(
...getValueToken<BoxShadows, BoxShadow | void>(
tokensJson.global.shadow,
parseAliasShadow(shadows)
),
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import tokens from "./Tokens";

export default tokens;
5 changes: 5 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "./tsconfig",
"include": ["src"],
"exclude": ["**/*.test.tsx", "**/*.test.ts"]
}
27 changes: 27 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"baseUrl": "./",
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": ["esnext"],
"module": "esnext",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noStrictGenericChecks": false,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "lib",
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext"
},
"include": ["src", "./.eslintrc.json"],
}

0 comments on commit 93292ad

Please sign in to comment.