1.0.1 • Published 9 months ago

wp-update-version v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

WP Update Version

wp-update-version is a command-line tool that updates the version number in various files within a WordPress project (theme or plugin). This allows you to synchronize your WP project's version number with the one in your package.json file.

Features

  • Updates the version number in CSS and PHP files' header comment blocks.
  • Optionally updates the version as constant declaration in specified PHP files.
  • Supports single or multiple files updates with one command.
  • Retrieves the version number from a package.json file (or allows you to specify it manually)

Installation

Save wp-update-version as a devDependency in your project:

npm install --save-dev wp-update-version

Usage

Run the script directly in your terminal using npx:

npx wp-update-version --file src/theme.scss --file plugin.php --project-version 2.1.0 --constant PLUGIN_VERSION

Or add it to your project's version script in package.json:

{
  "name": "my-wp-project",
  "version": "2.0.0",
  "scripts": {
    "build": "[compile src/theme.scss into style.css]",
    "version": "wp-update-version -f src/theme.scss && npm run build && git add ."
  }
}

For instance, when running npm version minor, the following will happen with the configuration above:

  1. (npm version) Updates the version number to 2.1.0 in package(-lock).json
  2. (wp-update-version) Updates the version number to 2.1.0 in src/theme.scss
  3. Builds style.css with version number 2.1.0
  4. Commits all updated files

Available options

OptionDescriptionDefault Value
-f <file> --file <file>Specify the file(s) to be updated. Can be repeated to update multiple files../style.css, ./<dirname>.php
-p <file> --package-json <file>Specify the location of the package.json file../package.json
--project-version <version>(Optional) Specify the new version number to apply. Overrides the value from package.json-
--constant <constant>(Optional) Specify a constant declaration to be updated in the PHP file(s).-

Development

Permission issue

When building and running your own version of the command, you might need to run chmod u+r bin/* to allow the program to execute.

Testing

This project uses Vitest for unit and integration testing.

  • Run npm test for a single test suite run.
  • Run npm run test:watch to enable test-based development.

Contributing

If you encounter any issues or have suggestions for improvements, please feel free to open a new issue or submit a pull request.

Credits

This tool was inspired by and derived from the following:

License

This project is licensed under the MIT License.

1.0.1

9 months ago

1.0.0

9 months ago