diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..bb136c1 --- /dev/null +++ b/.eslintrc.json @@ -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 +} diff --git a/index.ts b/index.ts index 118d0b5..e834edd 100644 --- a/index.ts +++ b/index.ts @@ -1,3 +1,3 @@ -import tokens from "./Tokens"; +import tokens from "./src"; export default tokens; diff --git a/package-lock.json b/package-lock.json index 51d0a9d..8c864e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@zerogachis/smartway-design-token", - "version": "0.0.0", + "version": "0.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@zerogachis/smartway-design-token", - "version": "0.0.0", + "version": "0.0.1", "license": "ISC", "devDependencies": { "typescript": "^5.3.3" diff --git a/package.json b/package.json index e1e5b29..061e908 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/Tokens.ts b/src/Tokens.ts similarity index 78% rename from Tokens.ts rename to src/Tokens.ts index e951293..b06967d 100644 --- a/Tokens.ts +++ b/src/Tokens.ts @@ -1,4 +1,4 @@ -import * as tokensJson from "./tokens.json"; +import * as tokensJson from "../tokens.json"; import { BoxShadows, BoxShadow, @@ -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, @@ -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 = @@ -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 + ], }; }; @@ -58,14 +73,14 @@ const getValueToken = ( Object.keys(value).forEach((key) => { const parsedValue = parseMethod(value[key].value); if (parsedValue) { - values[key] = parseMethod(value[key].value); + (values as Record)[key] = parsedValue; } }); return values as T; }; const getTokens = () => { - const shadows = getValueToken( + const shadows = getValueToken( tokensJson.global.shadow, parseShadow ); @@ -90,7 +105,7 @@ const getTokens = () => { ), boxShadow: { ...shadows, - ...getValueToken( + ...getValueToken( tokensJson.global.shadow, parseAliasShadow(shadows) ), diff --git a/TokensType.ts b/src/TokensType.ts similarity index 100% rename from TokensType.ts rename to src/TokensType.ts diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..118d0b5 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,3 @@ +import tokens from "./Tokens"; + +export default tokens; diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..5b4b760 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,5 @@ +{ + "extends": "./tsconfig", + "include": ["src"], + "exclude": ["**/*.test.tsx", "**/*.test.ts"] +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..f0d8d22 --- /dev/null +++ b/tsconfig.json @@ -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"], +}