Skip to content

Commit

Permalink
feat: update package to ESM (#7)
Browse files Browse the repository at this point in the history
* ci: refactor circleci config

- Add `gitleaks` job for detecting unwanted secrets in code
- Run `test` job in both 14 and 16 Node versions
- Use [Cache](https://circleci.com/docs/2.0/caching/) for storing
  `node_modules` cross runs
- Use [Workspace](https://circleci.com/docs/2.0/workspaces/) for storing
  files cross jobs
- Add Workflow for PR branches

* build: add githooks

* build: add "commitlint" to enforce Conventional Commits message format

[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) -
A specification for adding human and machine readable meaning to commit
messages

* chore: rename _env

* chore: link eslintignore and prettierignore to gitignore

* build: update semantic-release to git push package version after bump

* style: sync prettier's "endOfLine" with editorconfig

* feat: update package to ESM

BREAKING CHANGE: @asd14/blocks is now ESM only and requires node
`^14.13.1 || >=16.0.0`

* feat: update package to ESM

BREAKING CHANGE: @asd14/blocks is now ESM only and requires node
`^14.13.1 || >=16.0.0`

* chore: format

* chore: fix CHANGELOG.md typo

Co-authored-by: David Gil <[email protected]>

* fix: remove prepare step from package.json to avoid messing up with the consuming repo's environment

Co-authored-by: David Gil <[email protected]>
  • Loading branch information
andreidmt and dgilperez authored May 19, 2022
1 parent d546f23 commit afce4d4
Show file tree
Hide file tree
Showing 64 changed files with 20,546 additions and 23,888 deletions.
206 changes: 121 additions & 85 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,112 +1,148 @@
# Javascript Node CircleCI 2.0 configuration file
# CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2

#
# YAML variable templates
#
job_defaults: &job_defaults
working_directory: ~/blocks
docker:
- image: circleci/node:12

job_filter: &job_filter
filters:
branches:
only:
- master
version: 2.1

# Executors - https://circleci.com/docs/2.0/executor-intro/
#
# Run all jobs in sequence
# The underlying technology or environment in which to run a job

executors:
gitleaks:
docker:
- image: zricethezav/gitleaks:latest
node14:
docker:
- image: cimg/node:14.13.1
node16:
docker:
- image: cimg/node:16.14.2

# Jobs - https://circleci.com/docs/2.0/configuration-reference/#jobs
#
workflows:
version: 2
deploy_npm:
jobs:
- setup:
<<: *job_filter
- test:
<<: *job_filter
requires:
- setup
- coverage:
<<: *job_filter
requires:
- test
- publish:
<<: *job_filter
requires:
- coverage
# Atomic parts of the pipeline that will be composed and configured in one or
# more Workflows

#
# Define atomic jobs
#
jobs:
setup:
<<: *job_defaults

detect-secrets:
executor: gitleaks
working_directory: &JOB_WORKING_DIR "~/blocks"
steps:
- checkout

- run:
name: "blocks: Install npm packages"
command: "npm run setup:ci"
name: "[gitleaks] Detect secrets in repository history"
command: |
gitleaks detect --redact --verbose
- persist_to_workspace:
root: &WORKSPACE_ROOT "~/"
paths:
- blocks

setup:
executor: node16
working_directory: *JOB_WORKING_DIR
steps:
- attach_workspace:
at: *WORKSPACE_ROOT
- restore_cache:
name: '[circleci] Restore cached "node_modules" folder'
key:
&CACHE_KEY_NODE_MODULES 'blocks-v1-{{ arch }}-{{ checksum
"package-lock.json" }}'
- run:
name: "[npm]: Install packages"
command: |
node -v && npm -v
npm run setup
- save_cache:
paths:
- node_modules
- src
- tests
- .git
- .eslintrc
- .gitignore
- .nycrc
- .prettierrc
- README.md
- CHANGELOG.md
- package-lock.json
- package.json
key: blocks-{{ .Branch }}-{{ .Revision }}
key: *CACHE_KEY_NODE_MODULES
- persist_to_workspace:
root: *WORKSPACE_ROOT
paths:
- blocks

test:
<<: *job_defaults

parameters:
node-version:
type: string
executor: node<< parameters.node-version >>
working_directory: *JOB_WORKING_DIR
steps:
- restore_cache:
keys:
- blocks-{{ .Branch }}-{{ .Revision }}

- attach_workspace:
at: *WORKSPACE_ROOT
- run:
name: "blocks: Run linter"
command: "npm run lint"

name: "[eslint, markdownlint]: Lint"
command: |
npm run lint
- run:
name: "blocks: Run tests"
command: "npm run test"

coverage:
<<: *job_defaults
name: "[tape]: Unit tests"
command: "npm test"

submit-coverage:
executor: node16
working_directory: *JOB_WORKING_DIR
steps:
- restore_cache:
keys:
- blocks-{{ .Branch }}-{{ .Revision }}

- attach_workspace:
at: *WORKSPACE_ROOT
- run:
name: "blocks: Publish test coverage to COVERALLS"
command: "npm run coverage:ci"

publish:
<<: *job_defaults
name: "[coveralls]: Publish test coverage to COVERALLS"
command: "npm run coverage"

release-npm:
executor: node16
working_directory: *JOB_WORKING_DIR
steps:
- restore_cache:
keys:
- blocks-{{ .Branch }}-{{ .Revision }}

- attach_workspace:
at: *WORKSPACE_ROOT
- run:
name: "blocks: Release to npm with semantic-release"
command: "npx semantic-release"
name:
"[semantic-release]: Update version, generate release, publish npm
package"
command: "npm run release"

# Workflows - https://circleci.com/docs/2.0/workflows/
#
# Treat workflows as a jobs/commands pipe:
# cmd1 -p1 lorem | cmd2 -foo bar | ... | cmdN)

workflows:
test:
jobs:
- detect-secrets:
filters:
branches:
ignore: [master]
- setup:
requires: [detect-secrets]
- test:
name: "test_node14"
requires: [setup]
node-version: "14"
- test:
name: "test_node16"
requires: [setup]
node-version: "16"

release:
jobs:
- detect-secrets:
filters:
branches:
only: [master]
- setup:
requires: [detect-secrets]
- test:
name: "test_node14"
requires: [setup]
node-version: "14"
- test:
name: "test_node16"
requires: [setup]
node-version: "16"
- submit-coverage:
requires: [test_node14, test_node16]
- release-npm:
requires: [test_node14, test_node16]
3 changes: 3 additions & 0 deletions .commitlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@commitlint/config-conventional"]
}
File renamed without changes.
1 change: 1 addition & 0 deletions .eslintignore
14 changes: 2 additions & 12 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
{
"parser": "babel-eslint",
"root": true,
"extends": [
"@asd14/eslint-config/targets/node"
],
"extends": ["@asd14/eslint-config/targets/node-esm"],
"settings": {
"import/resolver": "node",

// Recommended if you use eslint_d
"import/cache": {
"lifetime": 5
}
},
"rules": {
"unicorn/consistent-function-scoping": "warn",
"promise/avoid-new": "off",
"valid-jsdoc": "off"
},
"rules": {}
}
9 changes: 9 additions & 0 deletions .githooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

# Dont run when in CI environment.
# For ex. when pushing changelogs via "semantic-release".
if [ -n "$CI" ]; then
exit 0
fi

npx --no-install commitlint < "$1"
12 changes: 12 additions & 0 deletions .githooks/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

# Exit script if any statement returns a non-true return value
set -e

packageLockChanged=$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD \
| grep -c "package-lock.json" \
)

if [ "$packageLockChanged" != "0" ]; then
npm install --no-audit --progress=false
fi
12 changes: 12 additions & 0 deletions .githooks/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

# Exit script if any statement returns a non-true return value
set -e

packageLockChanged=$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD \
| grep -c "package-lock.json" \
)

if [ "$packageLockChanged" != "0" ]; then
npm install --no-audit --progress=false
fi
3 changes: 3 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

npx --no-install lint-staged
7 changes: 7 additions & 0 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# Exit script if any statement returns a non-true return value
set -e

npm run lint
npm run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typings/

# dotenv environment variables file
.env
!.env.*

# next.js build output
.next
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
7 changes: 5 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"tabWidth": 2,
"useTabs": false,
"singleQuote": false,
"quoteProps": "consistent",
"trailingComma": "es5",
"bracketSpacing": true,
"jsxBracketSameLine": true,
"arrowParens": "avoid"
"bracketSameLine": true,
"arrowParens": "avoid",
"proseWrap": "always",
"endOfLine": "lf"
}
33 changes: 33 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"branches": [{ "name": "master" }],
"plugins": [
"@semantic-release/commit-analyzer",
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{ "type": "feat", "section": "Features" },
{ "type": "fix", "section": "Bug Fixes" },
{ "type": "perf", "section": "Performance Improvements" },
{ "type": "style", "section": "Styles", "hidden": false },
{ "type": "test", "section": "Tests", "hidden": false },
{ "type": "docs", "section": "Documentation", "hidden": false },
{ "type": "build", "section": "Build System", "hidden": false },
{ "type": "refactor", "section": "Refactors", "hidden": false },
{ "type": "ci", "section": "CI", "hidden": false }
]
}
}
],
"@semantic-release/npm",
[
"@semantic-release/git",
{
"assets": ["package.json", "package-lock.json"]
}
],
"@semantic-release/github"
]
}
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

# Changelog

Releases and changelog are automaticly handled by [semantic-release](https://github.com/semantic-release/semantic-release).
Releases and changelog are automatically handled by
[semantic-release](https://github.com/semantic-release/semantic-release).

All releases are based on Angular's [Git commit message](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) patterns.
All releases are based on Angular's
[Git commit message](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines)
patterns.

See the [releases section](https://github.com/asd-xiv/blocks/releases) for details.
See the [releases section](https://github.com/asd-xiv/blocks/releases) for
details.
Loading

0 comments on commit afce4d4

Please sign in to comment.