0.1.9 • Published 5 years ago

use-pkg-version v0.1.9

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Build Status Coverage Status Greenkeeper badge NPM version Vue 2 Vue CLI 3 Commitizen friendly Contributions welcome Hit count License MIT

Update any static file with the version number from the package.json file.

Ever had the problem that you have a version number in a static file that needs to be updated when a new version is released? This module is intended for this use case. I use it for example with the _coverpage.md of docsify and the version number in this README.md file.

Installation

Global

Install as a globally available CLI tool using npm:

npm install --global use-pkg-version

Or install using yarn:

yarn global add use-pkg-version

Local

Install as a devDependency using npm:

npm install --save-dev use-pkg-version

Or install using yarn:

yarn add --dev use-pkg-version

The following entry will be added to the devDependencies section in the package.json file.

{
  "devDependencies": {
    "use-pkg-version": "^0.1.8"
  }
}

Add the following entry to the scripts section in the package.json file:

{
  "scripts": {
    "upd-version": "use-pkg-version"
  }
}

Now you can run npm run build:upd-version from the command line. You can pass it arguments using double dashes (--), e.g. npm run build:upd-version -- info.

Go to Table of Contents

Usage

Minimum configuration

The easiest way to use this module is adding it as a prebuild script in the package.json file. The following example demonstrates how to run use-pkg-version when before the build process starts. It uses sane defaults, if no package.json file is specified it assumes the package.json is in the current directory.

{
  "scripts": {
    "prebuild": "use-pkg-version update --search-for "^[0-9].[0-9].[0-9]" --replace-with "^{{version}}" README.md",
    "build": "<your-build-command>"
  }
}

You can call this script directly by executing npm run prebuild or yarn prebuild.

Go to Table of Contents

Using a configuration file

You can also use a configuration file instead of passing options as commandline arguments. Change the script to the following.

{
  "scripts": {
    "prebuild": "use-pkg-version update README.md",
    "build": "<your-build-command>"
  }
}

Create a .use-pkg-versionrc.json file with the following configuration object.

{
  "search-for": "\\^[0-9].[0-9].[0-9]",
  "replace-with": "^{{version}}"
}

IMPORTANT Commandline options overrule settings in the configuration object.

The configuration can be a configuration object specified in one of the following ways.

  1. A use-pkg-version section to the package.json file

    {
      "use-pkg-version": {
        "search-for": "\\^[0-9].[0-9].[0-9]",
        "replace-with": "^{{version}}"
      }
    }
  2. A .use-pkg-versionrc file with JSON or YAML syntax

  3. A .use-pkg-versionrc.json file
  4. A .use-pkg-versionrc.yaml, .use-pkg-versionrc.yml or .use-pkg-versionrc.js file
  5. A .use-pkg-versionrc.config.js file

Files must be located in the root directory of the project. The order specified is the order the configuration will be looked for, the first match is used.

If the configuration file has a name that does not match the above, then you can use the `-c to specify it.

The names of the configuration object properties are the same as the commandline options.

Go to Table of Contents

Other options

  • --help: Using npm run build:upd-version -- --help will list the available commands.

  • \<command> --help: Using npm run build:upd-version -- <command> --help will display information about the specified command and its options.

  • info: Using npm run build:upd-version -- info will display information about your operating system and other environment information that is useful if you need to submit an issue.

Go to Table of Contents

Roadmap

Currently there is nothing on the roadmap. Suggestions? Please submit an issue.

Go to Table of Contents

Contributing

We welcome pull requests! What follows is the simplified version of the contribution process, please read here to fully understand our contribution policy and here to understand our code of conduct.

  1. Fork the repository here!
  2. Create your feature branch: git checkout -b my-new-feature
  3. If relevant, don't forget to add your tests
  4. Commit your changes: npm run commit
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request :-)

Go to Table of Contents

Support & brag about us

If you like this project, please support us by starring ⭐ this repository. Thx!

Please let the world know about us! Brag about us using Twitter, email, blog, Discord, Slack, forums, etc. etc. Thx!

Go to Table of Contents

Author

nidkil © nidkil, released under the MIT license. Authored and maintained by nidkil with help from contributors.

Website · GitHub @nidkil · Twitter @nidkil