@versett/versett-scripts v0.16.0
versett-scripts
Collection of scripts that are useful for all V// projects.
Usage
versett-scripts runs automatically based on git hooks and CI configuration, provided you add it as a dependency in your project and configure it according to the instructions below.
Whenever you commit or push code to your project, versett-scripts will run its validations in order to enforce good practices on branch names and commit messages.
Furthermore, versett-scripts adds support for automated changelog, release, and npmjs publishing.
Installation
- Run
yarn add @versett/versett-scripts --dev - In order to enable the git hook commands, you have to add husky configuration to your
package.json. There are currently four commands supported byversett-scripts. Here's a configuration example containing all four, which can be added to yourpackage.json's root:
"husky": {
"hooks": {
"commit-msg": "versett-scripts commitmsg ${HUSKY_GIT_PARAMS}",
"pre-commit": "versett-scripts precommit",
"prepare-commit-msg": "versett-scripts preparecommitmsg ${HUSKY_GIT_PARAMS}",
"pre-push": "versett-scripts prepush"
}
}This will ensure that the versett-scripts commands run whenever you do a commit or push in the target repository.
- For the
precommithook, you also need some minimal lint-staged config. You should have it match the characteristics of your project as to what kind of linting is going to be done. Here's an example, which can be added to yourpackage.json's root:
"lint-staged": {
"*.{js,json,css,md,ts,tsx}": ["prettier --write", "git add"]
}- For the
releasecommand, you also need to set the following in yourpackage.json's root:
"version": "0.0.0-semantically-released",
"scripts": {
"release": "yarn && versett-scripts release"
},
"release": {
"getLastRelease": "last-release-git"
}- Append
versett-scripts testto your CI test script:
"scripts": {
"test:ci": "... && versett-scripts test"
}- If you want to publish your package to npm, you can add the
--npm-publishflag to the release command:
"release": "yarn && versett-scripts release --npm-publish"Your CI server should be configured to run
releaseon new commits tomaster.In order to get
releaseto work on CI servers, make sure you set theGH_TOKENandNPM_TOKENenvironment variables. They should contain the tokens issued by your Github and NPM accounts.For a commit to show up on the automated changelog, it has to have a template message, as defined in conventional changelog. Every pull request needs to have at least one template commit.
If you are using Circle CI, you should add the following to the
package.json
"release": {
"verifyConditions": "condition-circle"
}Commands and features
For the following, let's assume that you enabled all commands as described in the Installation section.
versett-scriptswill use git hooks to perform checks on all commits to your repo. Whenever a commit is made, the following commands will be ran, in order:prepare-commit-msg,commit-msg,pre-commit. If any of the check fails, nothing will be committed.prepare-commit-msg: Automatically appends the issue ID based on the branch name ((#ISSUEID)) to your commit message. If the branch name doesn't contain an issue ID (e.g.master),prepare-commit-msgwon't append anything. This might imply that other checks will fail.commit-msg: It checks whether the commit message is a template one. If it is, it's enforced to follow the pattern ((feat|fix|perf): COMMITMESSAGE (#ISSUEID)).pre-commit: - Automatically applies Prettier to the staged files, according to thelint-stagedconfiguration on yourpackage.json.
versett-scriptswill validate your branch name before any push by using thepre-pushhook. Every branch name has to follow the pattern(feature|bugfix|hotfix)/ISSUEID-ISSUE-DESCRIPTION. If the check fails, nothing gets pushed.- Note: commit and push validations can be skipped by using a
--no-verifyflag in yourgitcommand. However, the--no-verifyflag defeats the purpose of enforcing good practices and is meant for exceptional situations only. Here's an example:
git add my-file git commit -m "My commit message (#123)" --no-verify git push --no-verify- Note: commit and push validations can be skipped by using a
versett-scriptswill test your branch's commit messages using thetestcommand to make sure each branch contains at least one semantic commit before getting merged.
versett-scriptswill be able to publish your package to npmjs, by means of thereleasecommand. The release command:- Automatically calculates the new version number by using get-latest-release and the new commits that follow the template.
- Pushes a tag with the version number to Github.
- Publishes a Github release containing the changelog based on your template commits.
Development
To get started on development run these commands:
nvm use
yarnFor testing purposes you can use yarn link (or npm link):
cd versett-scripts
yarn linkthen
cd my-project
yarn link @versett/versett-scriptsAfter that, a symbolic link is added to node_modules of the project directory.
Contributing
Please read the contributing guide for details on our process for submitting pull requests.
Versioning
Versioning is done automatically by versett-scripts when a branch is merged with master and our CI/CD runs.
Need help?
Open an issue, we're happy to chat!
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago