npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@codedesignplus/git-version

v0.1.0

Published

Semver versioning based on the git history and commit messages of your repository.

Downloads

18

Readme

Table of Contents

About The Project

This project centers on version management within a Git repository, particularly determining previous and new versions based on commit history and tags. It utilizes the semver library for semver-related operations.

Key features include:

  • Determining the previous version based on Git tags.
  • Calculating the new version based on commits since the last tag and certain predefined rules.
  • Accounting for different branches like release, release candidate, and beta to determine version type (e.g., prerelease).
  • Fetching the current commit hash.
  • Executing Git commands and fetching results.

This project is an essential tool for those seeking automated version management in their repositories, ensuring that each change, whether it's a major feature, a minor enhancement, or a simple patch, is properly reflected in the project's version.

Prerequisites

  1. Node.js Environment: As the code is in TypeScript/JavaScript, you'll need to have Node.js installed on your machine to run and develop the project.

  2. Libraries and Modules: The following libraries and modules are necessary:

    • semver: A library for working with semantic version numbers.
    • child_process: This native Node.js module is used to execute shell commands, in this case, Git commands.
  3. Git Repository: Since this project is designed to work with Git tags and commits, you'll need a Git repository where you intend to apply the version management.

  4. Git Installed: As the code utilizes Git commands via child_process, it's essential to have Git installed in the environment where the code is run.

  5. Appropriate Permissions: To fetch tags, commit history, and other information, as well as possibly set new tags, the environment running this code should have the proper permissions to interact with the Git repository.

Getting Started

To kickstart your journey with our project, begin by cloning the repository to your local machine. Once you've secured a copy, ensure you have the necessary prerequisites installed a list can be found in our "Prerequisites" section. Open the project using your preferred IDE (we recommend Visual Studio Code for optimal compatibility). Follow the installation steps detailed in the "Installation" segment to set up your development environment. After completing these foundational steps, you're all set to dive into the code, experiment with its features, and contribute to our growing community. Happy coding!

Installation

  1. Clone the repo
    git clone https://github.com/codedesignplus/CodeDesignPlus.Npm.GitVersion.git
  2. Retore Packages
    npm install
  3. Build Project
    npm run bundle
  4. Run test
    npm run test

Commands NPM

The following table provides an overview of the available npm scripts for this project, detailing their purpose and respective commands. These scripts assist in tasks ranging from formatting and linting to testing and packaging.

| Name | Description | Command | |-----------------|----------------------------------------------------------------------------------------------------------------------------|-------------------------| | bundle | First, it formats the files and then runs the packaging. | npm run bundle | | ci-test | Runs tests using Jest. | npm run ci-test | | format:write | Formats the TypeScript (*.ts) files and overwrites any non-standard formatting. | npm run format:write | | format:check | Checks the format of the TypeScript (*.ts) files but doesn't make changes. | npm run format:check | | lint | Runs eslint on the entire project with a specific configuration. | npm run lint | | package | Packages the src/index.ts file and sets the license file. | npm run package | | package:watch | Packages src/index.ts and repackages if there are changes (monitoring mode). | npm run package:watch | | test | Runs tests with Jest and creates a coverage badge. If tests fail, it will still generate the badge. | npm run test | | all | Runs several commands in sequence: formats files, checks linting, runs tests, and packages the project. | npm run all |

Usage

The key function of this project is to calculate versions based on certain criteria and configurations. This project looks at the commit history and, based on specific identifiers and configurations, determines the appropriate version for the next release.

Detailed Steps:

  1. Repository Checkout: Ensure that you've checked out the code in your repository before running any version calculation.

  2. Configuring Version Calculation:

    The tool can be configured to determine versions based on various parameters, including:

    • Directory to run the command in.
    • The name of branches like main, rc, and dev.
    • Identifiers for major and minor releases, such as breaking and feat.
    • Prefixes like v to be added before the version number.
    • Directories affected inside a monorepo to calculate changes.
    • Flags to determine whether to return the previous version or calculate a new one.
  • Accessing the results: After the version calculation process, the results can be utilized in various ways, such as tagging the repository, printing them, or integrating them into other tools or systems.

Options

Below is a table outlining the various configuration options available when utilizing the GitVersion class. These options determine how the class calculates and interprets versions based on Git commit history, tags, and branch specifics.

| Configuration Option | Description | Default Value | |----------------------------|-------------------------------------------------------------------------------------------------------|----------------| | folder | Directory in which the Git commands will run. | './' | | releaseBranch | Primary branch for releasing stable versions. | 'main' | | releaseCandidateBranch | Branch used for release candidates, undergoing final tests before becoming a stable release. | 'rc' | | betaBranch | Branch for beta releases, meant for early feedback or testing. | 'dev' | | majorIdentifier | Keyword in commit messages to signal major changes. | 'breaking' | | minorIdentifier | Keyword in commit messages to signal minor feature additions. | 'feat' | | prefix | Prefix added before version numbers. | 'v' | | dirAffected | Specifies which directory inside a monorepo should be considered for version calculation. | './' |

Example:

Once you have set up and executed the Calculate Version step, you can print its results or use them in subsequent actions:

import { GitVersion } from './git-version';

const gitVersion = new GitVersion({
    folder: './path-to-your-git-repo',  // Point this to your repository's local path
    releaseBranch: 'main', 
    releaseCandidateBranch: 'rc',
    betaBranch: 'dev',
    majorIdentifier: 'breaking',
    minorIdentifier: 'feat',
    prefix: 'v',
    dirAffected: './'
});

// Fetch the previous version from Git tags
const previousVersion = await gitVersion.getPreviousVersion();
console.log(`Previous Version: ${previousVersion}`);

// Calculate the new version based on commit messages since the last Git tag
const newVersion = await gitVersion.getNewVersion();
console.log(`New Version: ${newVersion}`);

// Get the last commit's hash
const lastCommit = await gitVersion.getLastCommit();
console.log(`Last Commit Hash: ${lastCommit}`);

Roadmap

Refer to issues for a list of proposed features and known issues.

Contributing

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b features/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

CodeDesignPlus - @CodeDesignPlus - [email protected]

Project Link: CodeDesignPlus.Core

Acknowledgements

  • https://github.com/codacy/git-version