use-pkg-version v0.1.9
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
- Usage
- Using a configuration file
- Other options
- Roadmap
- Contributing
- Support & brag about us
- Author
Installation
Global
Install as a globally available CLI tool using npm:
npm install --global use-pkg-versionOr install using yarn:
yarn global add use-pkg-versionLocal
Install as a devDependency using npm:
npm install --save-dev use-pkg-versionOr install using yarn:
yarn add --dev use-pkg-versionThe 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.
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.
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.
A
use-pkg-versionsection to thepackage.jsonfile{ "use-pkg-version": { "search-for": "\\^[0-9].[0-9].[0-9]", "replace-with": "^{{version}}" } }A
.use-pkg-versionrcfile with JSON or YAML syntax- A
.use-pkg-versionrc.jsonfile - A
.use-pkg-versionrc.yaml,.use-pkg-versionrc.ymlor.use-pkg-versionrc.jsfile - A
.use-pkg-versionrc.config.jsfile
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.
Other options
--help: Using
npm run build:upd-version -- --helpwill list the available commands.\<command> --help: Using
npm run build:upd-version -- <command> --helpwill display information about the specified command and its options.info: Using
npm run build:upd-version -- infowill display information about your operating system and other environment information that is useful if you need to submit an issue.
Roadmap
Currently there is nothing on the roadmap. Suggestions? Please submit an issue.
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.
- Fork the repository here!
- Create your feature branch:
git checkout -b my-new-feature - If relevant, don't forget to add your tests
- Commit your changes:
npm run commit - Push to the branch:
git push origin my-new-feature - Submit a pull request :-)
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!
Author
nidkil © nidkil, released under the MIT license. Authored and maintained by nidkil with help from contributors.