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

Improve monorepo setup and tooling #93

Merged
merged 6 commits into from
Aug 12, 2021
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
8 changes: 8 additions & 0 deletions .changeset/brown-boats-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@commercetools/history-sdk': minor
'@commercetools/importapi-sdk': minor
'@commercetools/ml-sdk': minor
'@commercetools/platform-sdk': minor
---

Update development tooling and monorepo setup.
36 changes: 19 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aliases:
- &ml_ts_sdk ~/commercetools-typescript-sdk
- &working_directory ~/commercetools-typescript-sdk

- &restore_yarn_cache
name: 'Restoring yarn cache'
Expand All @@ -15,59 +15,61 @@ aliases:
- .cache
- node_modules

executors:
node_14:
docker:
- image: cimg/node:14.17.4
Copy link
Member Author

Choose a reason for hiding this comment

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

Optimized image for circleci


version: 2.1
jobs:
build_and_test:
working_directory: *ml_ts_sdk
docker:
- image: node:12.22.1
executor: node_14
working_directory: *working_directory
steps:
- checkout
- restore_cache: *restore_yarn_cache
- run:
name: install dependencies
name: Installing dependencies
command: yarn install --frozen-lockfile
- save_cache: *save_yarn_cache
# TODO: remove once we use preconstruct
- run:
name: building platform-sdk package
command: yarn --cwd packages/platform-sdk build
name: Building packages
command: yarn build
- run:
name: test
name: Running tests
command: yarn test
- store_artifacts:
path: packages/ml-sdk/test-results
prefix: tests
- store_artifacts:
path: packages/platform-sdk/test-results
prefix: tests
- store_test_results:
path: packages/ml-sdk/test-results
- store_test_results:
path: packages/platform-sdk/test-results

update_ml_sdk_from_spec:
executor: node_14
working_directory: ~/commercetools-typescript-spec
docker:
- image: node:12.22.1
steps:
- checkout
- run:
name: configure git
name: Configure git
command: git config --global user.email "$GIT_AUTHOR_EMAIL" && git config --global user.name "$GIT_AUTHOR_NAME"
- add_ssh_keys:
fingerprints:
- "bd:28:56:34:9d:80:55:fb:74:c4:1f:9d:f4:4e:f1:4b"
- run:
name: Install java
name: Installing Java
command: apt update && apt install default-jre -y
- run:
name: install rmf cli
name: Installing RMF cli
command: export VRAP_VERSION=1.0.0-20200304142749 && curl -o- -s https://raw.githubusercontent.com/vrapio/rmf-codegen/master/scripts/install.sh | bash
- restore_cache: *restore_yarn_cache
- run:
name: install dependencies
name: Installing dependencies
command: yarn install --frozen-lockfile
- save_cache: *save_yarn_cache

workflows:
version: 2
validate_spec:
Expand Down
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

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 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12
14
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
12 changes: 3 additions & 9 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,19 @@
"semi": false,
"trailingComma": "es5",
"singleQuote": true,
"parser": "babel-flow",
"parser": "typescript",
"overrides": [
{
"files": "*.ts",
"files": "*.json",
"options": {
"parser": "typescript"
"parser": "json"
}
},
{
"files": "*.md",
"options": {
"parser": "markdown"
}
},
{
"files": "*.json",
"options": {
"parser": "json"
}
}
]
}
84 changes: 84 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Contributing

Hi, thanks for taking an interest in contributing to the **TypeScript SDK** repository. We welcome any kind of contribution, from reporting issues or idea to submitting pull requests for bug fixes, improvements, new features, etc.

Please take a moment to review this document in order to make the contribution process straightforward and effective for everyone involved.

## Core ideas

The repository primarily contains SDK packages in TypeScript generated from the commercetools platform API reference.

## Repository structure

This repository is managed as a monorepo, meaning it contains multiple (sub)packages located in the [`packages`](./packages) directory.

```
packages/
...
```

### Development tools

At commercetools we use the following development tools:

#### Yarn

We use [Yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/) to manage dependencies between multiple packages.

#### Jest

We use [Jest](https://jestjs.io/) as the main framework for testing. Additionally, we take advantage of the Jest runners to run other tasks such as ESLint.

#### Prettier

We rely on [Prettier](https://prettier.io/) to consistently format our code.

#### TypeScript

We prefer to implement our UI components using [TypeScript](https://www.typescriptlang.org/). This has the benefit of provide packages with type declarations, thus a better developer experience, but also to have the codebase more maintainable and less error-prone.

#### Preconstruct

We rely on [Preconstruct](https://preconstruct.tools/) to build the packages.

#### Commitlint

Commit messages should follow a [conventional commit format](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional).

## Opening an Issue

In general, it's a good idea to open an issue first, no matter if it's a bug report, a new feature, etc. Doing so allows maintainers and other contributors to be aware of the context when an associated pull request is provided. It also gives a chance to provide early feedback and suggestions on what the pull request should focus on and what the expectations, avoiding unnecessary work during a pull request.

## Submitting a Pull Request

Good pull requests, such as patches, improvements, and new features, are a fantastic help. They should remain focused in scope and avoid containing unrelated commits.

If possible, please try to provide a [related issue first](#opening-an-issue), where the topic is discussed and agreed upon before starting to work on that. This is helpful for both you and the maintainers to be familiar with the changes beforehand.

## Getting started

1. Clone the repository.
2. Run `yarn` in the root folder to install the dependencies.

Some useful commands to work with the repository:

- `yarn test` and `yarn test --watch`
- `yarn typecheck`
- `yarn build`

## Adding changesets

commercetools sdk-typescript uses [changesets](https://github.com/atlassian/changesets) to do versioning and creating changelogs.

As a contributor you need to add a changeset by running `yarn changeset`.
The command will prompt to select the packages that should be bumped, their associated semver bump types and some markdown which will be inserted into the changelogs.

When opening a Pull Request, a `changeset-bot` checks that the Pull Request contains a changeset. A changeset is **NOT required**, as things like documentation or other changes in the repository itself generally don't need a changeset.

## Releasing packages

commercetools sdk-typescript uses [changesets](https://github.com/atlassian/changesets) to do versioning and publishing a release.

A [Changesets release GitHub Action](https://github.com/changesets/action) opens a `Version Packages` Pull Request whenever there are some changesets that have not been released yet.

When the `Version Packages` Pull Request gets merged, the Changesets release GitHub Action will automatically trigger the release.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ prettify: yarn_install
yarn run format

post_process: yarn_install
yarn run lerna run post_process_generate
yarn manypkg run post_process_generate

codegen_install:
curl -o- -s https://raw.githubusercontent.com/vrapio/rmf-codegen/master/scripts/install.sh | bash
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# commercetools typescript sdks

<img src="http://dev.commercetools.com/assets/img/CT-logo.svg" width="550px" alt="CT-logo"></img>
<h2 align="center">commercetools TypeScript SDKs 💅</h2>
<p align="center">
<i>✨ Monorepository with generated TypeScript SDKs for the commercetools platform 🛠</i>
</p>

## Introduction

This repository contains the commercetools platform, import-api and machine learning packages for typescript generated from our api reference.

<p align="center">

</p>
This repository contains several SDK packages generated from the commercetools platform API reference.

## Support

Expand All @@ -23,10 +20,13 @@ If you have any urgent issues regarding this repository please create a support
| [`platform-sdk`](/packages/platform-sdk) | [![platform-sdk Version][platform-sdk-icon]][platform-sdk-version] |
| [`importapi-sdk`](/packages/importapi-sdk) | [![importapi-sdk Version][importapi-sdk-icon]][importapi-sdk-version] |
| [`ml-sdk`](/packages/ml-sdk) | [![ml-sdk Version][ml-sdk-icon]][ml-sdk-version] |
| [`history-sdk`](/packages/history-sdk) | [![history-sdk Version][history-sdk-icon]][history-sdk-version] |
Copy link
Member Author

Choose a reason for hiding this comment

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

Was it forgotten or was it omitted on purpose?

Copy link
Contributor

Choose a reason for hiding this comment

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

Note sure, but I think it's fine to have it as part of the packages listed in the README.md


[platform-sdk-version]: https://www.npmjs.com/package/@commercetools/platform-sdk
[platform-sdk-icon]: https://img.shields.io/npm/v/@commercetools/platform-sdk.svg?style=flat-square
[importapi-sdk-version]: https://www.npmjs.com/package/@commercetools/platform-sdk
[importapi-sdk-icon]: https://img.shields.io/npm/v/@commercetools/platform-sdk.svg?style=flat-square
[ml-sdk-version]: https://www.npmjs.com/package/@commercetools/platform-sdk
[ml-sdk-icon]: https://img.shields.io/npm/v/@commercetools/platform-sdk.svg?style=flat-square
[importapi-sdk-version]: https://www.npmjs.com/package/@commercetools/importapi-sdk
[importapi-sdk-icon]: https://img.shields.io/npm/v/@commercetools/importapi-sdk.svg?style=flat-square
[ml-sdk-version]: https://www.npmjs.com/package/@commercetools/ml-sdk
[ml-sdk-icon]: https://img.shields.io/npm/v/@commercetools/ml-sdk.svg?style=flat-square
[history-sdk-version]: https://www.npmjs.com/package/@commercetools/history-sdk
[history-sdk-icon]: https://img.shields.io/npm/v/@commercetools/history-sdk.svg?style=flat-square
7 changes: 7 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @type {import('@babel/core').TransformOptions}
*/
module.exports = {
presets: ['@babel/env', '@babel/preset-typescript'],
plugins: ['@babel/proposal-class-properties'],
}
15 changes: 14 additions & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
module.exports = { extends: ['@commitlint/config-conventional'] }
/* eslint-disable */
module.exports = {
extends: ['@commitlint/config-conventional'],
parserPreset: {
parserOpts: {
// Allow to write a "scope" with slashes
// E.g. `refactor(app/my-component): something`
headerPattern: /^(\w*)(?:\(([\w\$\.\/\-\* ]*)\))?\: (.*)$/,
},
},
rules: {
'header-max-length': [0, 'always', 100],
},
}
6 changes: 0 additions & 6 deletions husky.config.js

This file was deleted.

23 changes: 23 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @type {import('@jest/types').Config.ProjectConfig}
*/
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.js$': 'babel-jest',
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: '\\.(test|spec)\\.[j|t]sx?$',
moduleFileExtensions: ['ts', 'js', 'json'],
watchPlugins: ['jest-watch-typeahead/filename'],
reporters: [
'default',
process.env.CI === 'true'
? [
'jest-junit',
{ outputName: 'results.xml', outputDirectory: 'test-results' },
]
Comment on lines +17 to +20
Copy link
Member Author

Choose a reason for hiding this comment

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

Do you know why are we using and storing test results as artifacts? Are they used somewhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not really, but I will also look into it.

: null,
].filter(Boolean),
}
55 changes: 38 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
{
"name": "root",
"name": "commercetools-sdk-typescript",
"private": true,
"devDependencies": {
"@changesets/changelog-github": "0.4.0",
"@changesets/cli": "2.16.0",
"@commitlint/config-conventional": "8.3.4",
"@rollup/plugin-typescript": "3.0.0",
"husky": "4.3.8",
"lerna": "3.20.2",
"prettier": "1.19.1",
"rimraf": "3.0.2"
},
"workspaces": ["packages/*"],
"scripts": {
"generate": "lerna run generate && yarn format",
"prepare": "husky install",
"postinstall": "manypkg check && preconstruct dev",
"generate": "manypkg run generate && yarn format",
"format": "prettier --write '**/*.{js,ts,json,md}'",
"build": "lerna run build",
"test": "lerna run test",
"pre-commit": "lerna run precommit",
"build": "preconstruct build",
"test": "jest --maxWorkers=2",
"typecheck": "tsc --noEmit",
"changeset": "changeset",
"changeset:version-and-format": "changeset version && prettier --write --parser json '**/package.json'"
},
"workspaces": ["packages/*"],
"dependencies": {
"@babel/core": "7.15.0",
"@babel/plugin-proposal-class-properties": "7.14.5",
"@babel/preset-env": "7.15.0",
"@babel/preset-typescript": "7.15.0",
"@changesets/changelog-github": "0.4.0",
"@changesets/cli": "2.16.0",
"@commitlint/cli": "13.1.0",
"@commitlint/config-conventional": "13.1.0",
"@manypkg/cli": "0.18.0",
"@preconstruct/cli": "2.1.0",
"@types/jest": "27.0.0",
"@types/node": "14.14.31",
"babel-jest": "27.0.6",
"husky": "7.0.1",
"jest": "27.0.6",
"jest-junit": "12.2.0",
"jest-watch-typeahead": "0.6.4",
"lint-staged": "11.1.2",
"prettier": "1.19.1",
"rimraf": "3.0.2",
"ts-jest": "27.0.4",
"tsc-files": "1.1.2",
"typescript": "4.3.5"
},
"lint-staged": {
"*.{js,ts,json,md}": "yarn format"
"*.{js,json,md}": ["prettier --write"],
"*.ts": ["prettier --write", "tsc-files --noEmit"]
},
"preconstruct": {
"packages": ["packages/*"]
}
}
Loading