Skip to content

feat: added prettier and eslint support #25

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

Merged
merged 2 commits into from
Jul 22, 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
11 changes: 9 additions & 2 deletions .commitlintrc.cjs → .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
module.exports = {
// @ts-check

/**
* @type {import('@commitlint/types').UserConfig}
*/
const config = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [
Expand All @@ -7,4 +12,6 @@ module.exports = {
['feat', 'feature', 'fix', 'refactor', 'docs', 'build', 'test', 'ci', 'chore', 'fonts']
]
}
};
};

module.exports = config;
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @ts-check

/**
* @type {import('eslint').Linter.Config}
*/
const config = {
root: true,
env: {
es2022: true
},
ignorePatterns: ['dist', 'node_modules'],
extends: ['plugin:prettier/recommended']
};

module.exports = config;
1 change: 0 additions & 1 deletion .github/workflows/actions/build-packages/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ description: Common setup steps used by our workflows
runs:
using: composite
steps:

- name: Build packages
shell: bash
run: .github/workflows/actions/build-packages/entrypoint.sh
2 changes: 1 addition & 1 deletion .github/workflows/actions/setup-yarn/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runs:
steps:
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
node-version-file: .nvmrc

- uses: actions/setup-node@v4
with:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ jobs:

- name: Build packages
uses: ./.github/workflows/actions/build-packages

- name: Linters
run: |
yarn run prettier:lint
yarn run eslint
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
*.launch
.settings/
*.sublime-workspace
/.vscode
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/.awcache
/.angular

Expand Down
2 changes: 1 addition & 1 deletion .husky/commit-msg
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname -- "$0")/_/husky.sh"

yarn commitlint --config .commitlintrc.cjs --edit ${1}
yarn commitlint --edit ${1}
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
4 changes: 4 additions & 0 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'*.{md,yml,json,js}': 'prettier --write',
'*.js': 'eslint'
};
File renamed without changes.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
/dist
CHANGELOG.md
22 changes: 22 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @ts-check

/**
* @type {import('prettier').Options}
*/
const config = {
printWidth: 120,
tabWidth: 4,
useTabs: false,
singleQuote: true,
trailingComma: 'none',
overrides: [
{
files: ['*.yml'],
options: {
tabWidth: 2
}
}
]
};

module.exports = config;
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
43 changes: 22 additions & 21 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ helpful.

Before you submit your pull request (PR) consider the following guidelines:

- Fork Design-tokens into your namespace by using the fork button on github.
- Make your changes in a new git branch: `git checkout -b my-fix-branch master`
- Create your bugfix/feature including appropriate tests.
- Test your changes with our supported browsers.
- Run unit tests and ensure that all tests pass.
- Push your branch to GitHub.
- Create a new pull request from your branch against the angular-components:master
branch.
- Fork Design-tokens into your namespace by using the fork button on github.
- Make your changes in a new git branch: `git checkout -b my-fix-branch master`
- Create your bugfix/feature including appropriate tests.
- Test your changes with our supported browsers.
- Run unit tests and ensure that all tests pass.
- Push your branch to GitHub.
- Create a new pull request from your branch against the angular-components:master
branch.

## Commit message guidelines

Expand All @@ -34,10 +34,11 @@ Before you submit your pull request (PR) consider the following guidelines:
│ elements|forms|http|language-service|localize|platform-browser|
│ platform-browser-dynamic|platform-server|router|service-worker|
│ upgrade|zone.js|packaging|changelog|dev-infra|docs-infra|migrations|
└─⫸ Commit Type: build|ci|docs|feat|fix|perf|refactor|test
```

Each commit message consists of a `type`, `scope` and `subject` (message).
The `type` and `subject` are mandatory, the `scope` is optional in some specific
cases. Format: `<type>(<scope>): <subject>`
Expand All @@ -46,17 +47,17 @@ cases. Format: `<type>(<scope>): <subject>`

Must be one of the following:

- **feat**: A new feature
- **fix**: A bug fix
- **docs**: Documentation only changes
- **style**: Changes that do not affect the meaning of the code (white-space,
formatting, missing semi-colons, etc)
- **refactor**: A code change that neither fixes a bug nor adds a feature
- **test**: Adding missing tests or correcting existing tests
- **ci**: Changes that affect the CI
- **build**: Changes that affect the build system like npm scripts or
angular-cli related changes
- **chore**: Other changes that don't modify src or test files
- **feat**: A new feature
- **fix**: A bug fix
- **docs**: Documentation only changes
- **style**: Changes that do not affect the meaning of the code (white-space,
formatting, missing semi-colons, etc)
- **refactor**: A code change that neither fixes a bug nor adds a feature
- **test**: Adding missing tests or correcting existing tests
- **ci**: Changes that affect the CI
- **build**: Changes that affect the build system like npm scripts or
angular-cli related changes
- **chore**: Other changes that don't modify src or test files

### Scope

Expand Down Expand Up @@ -100,7 +101,7 @@ BREAKING CHANGE: The method has been removed.
Describe reasons.
```

## Code reviews and PRs
## Code reviews and PRs

### Open PR

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## How to build a distribution with tokens

- **Clone** this repository;
- **Install** the packages using: `yarn install`
- You can **build it** with this command: `yarn run build`
- Then **find your distribution** in the following folder: `/dist`
- **Clone** this repository;
- **Install** the packages using: `yarn install`
- You can **build it** with this command: `yarn run build`
- Then **find your distribution** in the following folder: `/dist`
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
"author": "",
"license": "MIT",
"packageManager": "[email protected]",
"engines": {
"yarn": "^4.0.0",
"node": ">=18.0.0"
},
"keywords": [
"design-system",
"design-tokens",
Expand All @@ -17,13 +13,17 @@
"koobiq"
],
"scripts": {
"prepare": "husky",
"prebuild": "rimraf dist/",
"build:index-common": "yarn run rollup dist/design-tokens/web/js/index.mjs --file dist/design-tokens/web/js/index.cjs --format cjs",
"build": "node tools/build.js && yarn run build:index-common",
"stage:commit": "koobiq-cli stage-commit -c \"Design Tokens\"",
"release:publish:ci-github": "koobiq-cli publish-ci-github",
"release:publish:ci-gitlab": "koobiq-cli publish-ci-gitlab"
"release:publish:ci-gitlab": "koobiq-cli publish-ci-gitlab",
"prettier": "prettier '**/*.{md,yml,json,js}'",
"prettier:lint": "yarn run prettier --check",
"prettier:fix": "yarn run prettier --list-different --write",
"eslint": "eslint .",
"eslint:fix": "yarn run eslint --fix"
},
"publishConfig": {
"access": "public"
Expand All @@ -40,8 +40,13 @@
"@koobiq/cli": "17.0.0-rc.5",
"@types/fs-extra": "^11.0.4",
"@types/node": "^18.19.31",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"fs-extra": "^11.2.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.7",
"prettier": "^3.3.3",
"rimraf": "^5.0.5",
"rollup": "^4.17.2",
"style-dictionary": "^3.9.2"
Expand Down
9 changes: 4 additions & 5 deletions packages/design-tokens/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ visual system for UI development and brand consistency.
Koobiq design tokens store the visual design attributes that define the
visual language, including color, typography, and spacing we use.


Design tokens are key-value pairs. For example:

```
Key: value;
$card-dark-success-background: #276211;
```
- The key name defines the usage or how to apply the value to a specific context, such as using text on a light background
- The key stores visual design attributes
- The key replaces hard-coded values, such as hex values for color or pixel values for spacing


- The key name defines the usage or how to apply the value to a specific context, such as using text on a light background
- The key stores visual design attributes
- The key replaces hard-coded values, such as hex values for color or pixel values for spacing
4 changes: 2 additions & 2 deletions packages/tokens-builder/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Tokens Builder

## Overview

Tokens builder is a configuration script that utilizes Style Dictionary,
a design-token platform for creating and maintaining consistent design tokens across various platforms.
a design-token platform for creating and maintaining consistent design tokens across various platforms.

Overall, this script orchestrates the generation of design tokens by applying custom transformations,
filters, and formats to the specified theme configuration for multiple platforms,
facilitating a streamlined design token workflow compatible with
various output formats like SCSS, CSS, and TypeScript.

19 changes: 9 additions & 10 deletions packages/tokens-builder/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ require('./formats/variables')(StyleDictionary);
console.log('Build started...');
console.log('==============================================');


module.exports = (themeConfig) => {
StyleDictionary.registerFileHeader({
name: 'customHeader',
Expand All @@ -40,14 +39,14 @@ module.exports = (themeConfig) => {

if (!themeConfig || themeConfig.length === 0) {
console.error('Build Failed. Please set ThemeConfig, for example: ', {
name: 'default-theme',
buildPath: [
`design-tokens/tokens/properties/**/*.json5`,
`design-tokens/tokens/components/**/*.json5`
],
outputPath: 'design-tokens/'
}
)
name: 'default-theme',
// prettier-ignore
buildPath: [
`design-tokens/tokens/properties/**/*.json5`,
`design-tokens/tokens/components/**/*.json5`
],
outputPath: 'design-tokens/'
});
process.exit(0);
}

Expand All @@ -63,4 +62,4 @@ module.exports = (themeConfig) => {

console.log('\n==============================================');
console.log('\nBuild completed!');
}
};
9 changes: 4 additions & 5 deletions packages/tokens-builder/configs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const filterObj = {
function filterOptions(platforms) {
const platformObj = {};

platforms.map(p => Object.assign(platformObj, p));
platforms.map((p) => Object.assign(platformObj, p));

Object.keys(platformObj).forEach((p) => {
platformObj[p].files = platformObj[p].files.map(f => ({
platformObj[p].files = platformObj[p].files.map((f) => ({
...f,
...filterObj,
options: {
...f.options ?? {},
...(f.options ?? {}),
...filterObj.options
}
}));
Expand All @@ -30,7 +30,7 @@ function filterOptions(platforms) {
}

function getSources(theme) {
return theme.buildPath.map(pathName => {
return theme.buildPath.map((pathName) => {
if (pathName.startsWith('@')) {
return join('node_modules', pathName);
}
Expand All @@ -48,7 +48,6 @@ function getConfigs(theme) {
}

module.exports = (theme) => {

return {
source: [...getSources(theme)],
platforms: getConfigs(theme)
Expand Down
1 change: 0 additions & 1 deletion packages/tokens-builder/configs/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ module.exports = {
]
}
};

9 changes: 3 additions & 6 deletions packages/tokens-builder/filters/color.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module.exports = (StyleDictionary) => {

StyleDictionary.registerFilter({
name: 'color',
matcher: (prop) => !prop.attributes.palette &&
!prop.attributes.typography &&
!prop.attributes['md-typography']
})
}
matcher: (prop) => !prop.attributes.palette && !prop.attributes.typography && !prop.attributes['md-typography']
});
};
Loading