Skip to content

Commit

Permalink
Improve dev + release tools (#1)
Browse files Browse the repository at this point in the history
* refactor: use typescrypt, github actions, changesets

* docs: changeset

* chore: add linter hooks
  • Loading branch information
emmenko authored Dec 5, 2020
1 parent 612ec9f commit f968e80
Show file tree
Hide file tree
Showing 23 changed files with 5,296 additions and 2,486 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/master/docs/common-questions.md)
13 changes: 13 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": [
"@changesets/changelog-github",
{
"repo": "emmenko/omit-empty-es"
}
],
"commit": false,
"linked": [],
"access": "restricted",
"baseBranch": "master"
}
5 changes: 5 additions & 0 deletions .changeset/forty-fishes-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'omit-empty-es': minor
---

Use TypeScript, improve CI tools.
67 changes: 67 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:jest/recommended',
'prettier',
'prettier/@typescript-eslint',
],
plugins: ['import', 'jest', 'prettier', '@typescript-eslint/eslint-plugin'],
rules: {
'@typescript-eslint/ban-types': 0,
'@typescript-eslint/naming-convention': 0,
'@typescript-eslint/consistent-type-definitions': 0,
'@typescript-eslint/no-explicit-any': 2,
'@typescript-eslint/no-use-before-define': [
'error',
{
functions: false,
},
],
'@typescript-eslint/no-var-requires': 0,
'@typescript-eslint/unbound-method': 0,
'import/no-extraneous-dependencies': 0,
'import/no-named-as-default': 0,
'import/no-named-as-default-member': 0,
'import/default': 0,
'import/no-unresolved': 2,
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.js', '.jsx', '.ts', '.tsx'],
},
'import/resolver': {
'eslint-import-resolver-typescript': true,
typescript: {},
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
overrides: [
{
files: ['*.spec.ts'],
env: {
jest: true,
},
},
{
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/explicit-member-accessibility': [
2,
{
accessibility: 'no-public',
},
],
'@typescript-eslint/no-require-imports': 0,
'@typescript-eslint/promise-function-async': 0,
},
},
],
};
25 changes: 0 additions & 25 deletions .eslintrc.yaml

This file was deleted.

54 changes: 54 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Main workflow

# The event triggers are configured as following:
# - on branch main, trigger the workflow on every push
# - on any pull request, trigger the workflow
# This is to avoid running the workflow twice on pull requests.
on:
push:
branches:
- main
pull_request:

jobs:
build_lint_and_test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Read .nvmrc
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
id: nvm

- name: Setup Node (uses version in .nvmrc)
uses: actions/setup-node@v1
with:
node-version: "${{ steps.nvm.outputs.NVMRC }}"

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Building packages
run: yarn build

- name: Running static type checking
run: yarn typecheck

- name: Running linters and tests
run: yarn lint

- name: Running linters and tests
run: yarn test
77 changes: 77 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Release

on:
push:
branches:
- master

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
# Fetch git history with a depth of 50 commits so that Changesets can generate
# changelogs with the correct commits information.
# Note: this means that if we have merged >50 PRs since the last release,
# the changelogs might not contain all correct information.
# We could set `fetch-depth: 0`, but that would cause the entire history
# to be cloned. Using 50 seems like a good balance to start with.
fetch-depth: 50
# Pass a personal access token to be able to trigger other workflows
# https://help.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token
# https://github.community/t/action-does-not-trigger-another-on-push-tag-action/17148/8
token: ${{ secrets.RELEASE_GITHUB_TOKEN }}

- name: Read .nvmrc
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
id: nvm

- name: Setup Node (uses version in .nvmrc)
uses: actions/setup-node@v1
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Installing dependencies
run: yarn install --frozen-lockfile

- name: Creating .npmrc
run: |
cat << EOF > "$HOME/.npmrc"
email=$NPM_EMAIL
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
env:
NPM_EMAIL: ${{ secrets.NPM_EMAIL }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Creating Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@master
with:
publish: yarn changeset publish
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }}

# Publish canary releases only if the packages weren't published already
- name: Publishing canary releases to npm registry
if: steps.changesets.outputs.published != 'true'
run: |
git checkout master
yarn changeset version --snapshot canary
yarn changeset publish --tag canary
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14
10 changes: 9 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"trailingComma": "es5",
"singleQuote": true,
"parser": "babel"
"parser": "typescript",
"overrides": [
{
"files": "*.json",
"options": {
"parser": "json"
}
}
]
}
21 changes: 0 additions & 21 deletions .travis.yaml

This file was deleted.

79 changes: 72 additions & 7 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,72 @@
module.exports = {
presets: ['@babel/preset-env'],
plugins: [
'@babel/plugin-transform-regenerator',
'@babel/plugin-transform-runtime',
],
};
module.exports = function getBabelPreset(api) {
if (api) {
// Cache the returned value forever and don't call this function again.
api.cache(true);
}

// This is similar to how `env` works in Babel:
// https://babeljs.io/docs/usage/babelrc/#env-option
// We are not using `env` because it’s ignored in versions > [email protected]:
// https://github.com/babel/babel/issues/4539
// https://github.com/facebook/create-react-app/issues/720
// It’s also nice that we can enforce `NODE_ENV` being specified.
const env = process.env.BABEL_ENV || process.env.NODE_ENV;
const isEnvDevelopment = env === 'development';
const isEnvProduction = env === 'production';
const isEnvTest = env === 'test';

if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) {
throw new Error(
'The babel preset of requires that you specify `NODE_ENV` or ' +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
`"test", and "production". Instead, received: ${JSON.stringify(env)}.`
);
}

return {
presets: [
isEnvTest && [
// ES features necessary for user's Node version
require('@babel/preset-env').default,
{
targets: {
browsers: ['last 2 versions'],
node: 'current',
},
},
],
(isEnvProduction || isEnvDevelopment) && [
// Latest stable ECMAScript features
require('@babel/preset-env').default,
{
targets: {
browsers: ['last 2 versions'],
},
corejs: { version: 3, proposals: true },
// `entry` transforms `@babel/polyfill` into individual requires for
// the targeted browsers. This is safer than `usage` which performs
// static code analysis to determine what's required.
// This is probably a fine default to help trim down bundles when
// end-users inevitably import '@babel/polyfill'.
useBuiltIns: 'entry',
// Do not transform modules to CJS
modules: false,
include: ['transform-classes'],
},
],
[require('@babel/preset-typescript').default],
].filter(Boolean),
plugins: [
// Polyfills the runtime needed for async/await and generators
[
require('@babel/plugin-transform-runtime').default,
{
corejs: 3,
// To be able to use `runtime` in Rollup babel plugin
helpers: true,
regenerator: true,
},
],
],
};
};
14 changes: 14 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* 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],
},
};
Loading

0 comments on commit f968e80

Please sign in to comment.