├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── __tests__ ├── .eslintrc └── index.js ├── package.json └── src ├── cli.js ├── git.js ├── index.js └── utils.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"], 3 | "plugins": ["transform-async-to-generator"] 4 | } 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | # default 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | coverage/ 2 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["airbnb-base"] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | npm-debug.log 3 | .DS_Store 4 | example/ 5 | coverage/ 6 | lib/ 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '6' 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Vu Tran 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # composer-version 2 | 3 | > Command-line helper for [Composer](https://getcomposer.org) to bump versions similar to `npm version`. 4 | 5 | Composer doesn't support a command to [bump the version](https://github.com/composer/composer/issues/4939) of your package easily. `composer-version` was created to replicate the feature of `npm version` to allow package publishers to quickly bump their package's version using [semver](http://semver.org/). 6 | 7 | It simply creates a new git commit and tag based on the type. (`major`, `minor`, or `patch`). 8 | 9 | ## Install 10 | 11 | ```bash 12 | $ npm install -g composer-version 13 | ``` 14 | 15 | ## Usage 16 | 17 | ``` 18 | $ composer-version [major | minor | patch] 19 | ``` 20 | 21 | ## License 22 | 23 | MIT © [Vu Tran](https://github.com/vutran/) 24 | -------------------------------------------------------------------------------- /__tests__/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "env": { 4 | "jest": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /__tests__/index.js: -------------------------------------------------------------------------------- 1 | import utils from '../src/utils'; 2 | 3 | describe('utils', () => { 4 | it('should get the next major version', () => { 5 | expect(utils.getNextVersion('1.0.0', 'major')).toEqual('2.0.0'); 6 | }); 7 | 8 | it('should get the next minor version', () => { 9 | expect(utils.getNextVersion('1.0.0', 'minor')).toEqual('1.1.0'); 10 | }); 11 | 12 | it('should get the next patch version', () => { 13 | expect(utils.getNextVersion('1.0.0', 'patch')).toEqual('1.0.1'); 14 | }); 15 | 16 | it('should throw an error', () => { 17 | expect(() => utils.getNextVersion('1.0.0')).toThrow(); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "composer-version", 3 | "version": "0.2.0", 4 | "description": "Command-line helper for Composer to bump versions similar to npm version.", 5 | "main": "lib/index.js", 6 | "files": [ 7 | "lib" 8 | ], 9 | "bin": { 10 | "composer-version": "./lib/cli.js" 11 | }, 12 | "author": "Vu Tran ", 13 | "license": "MIT", 14 | "devDependencies": { 15 | "babel-cli": "^6.14.0", 16 | "babel-eslint": "^6.1.2", 17 | "babel-jest": "^15.0.0", 18 | "babel-plugin-transform-async-to-generator": "^6.8.0", 19 | "babel-polyfill": "^6.13.0", 20 | "babel-preset-es2015": "^6.14.0", 21 | "eslint": "^3.5.0", 22 | "eslint-config-airbnb-base": "^7.1.0", 23 | "eslint-plugin-import": "^1.14.0", 24 | "jest": "^15.1.1" 25 | }, 26 | "scripts": { 27 | "lint": "eslint src", 28 | "test": "jest --coverage", 29 | "build": "babel src --out-dir lib", 30 | "prepublish": "npm run build" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const composerVersion = require('./'); 4 | 5 | if (process.argv.length >= 3) { 6 | const args = process.argv[2].split(' '); 7 | composerVersion(args).then((tag) => { 8 | // eslint-disable-next-line no-console 9 | console.log(tag); 10 | }); 11 | } else { 12 | // eslint-disable-next-line no-console 13 | console.error('Please specify version increment type: (major, minor, patch)'); 14 | } 15 | -------------------------------------------------------------------------------- /src/git.js: -------------------------------------------------------------------------------- 1 | const { exec } = require('child_process'); 2 | 3 | /** 4 | * Creates a new git commit 5 | * 6 | * @param {String} tag - A tag name (eg: v1.2.3) 7 | * @return {Promise} - Resolves the tag name 8 | */ 9 | const createGitCommit = tag => new Promise((resolve) => { 10 | const cmdAdd = 'git add composer.json'; 11 | exec(cmdAdd, (err1) => { 12 | if (!err1) { 13 | const cmdCommit = `git commit -m ${tag}`; 14 | exec(cmdCommit, (err2) => { 15 | if (!err2) { 16 | resolve(tag); 17 | } 18 | }); 19 | } 20 | }); 21 | }); 22 | 23 | /** 24 | * Creates a new git tag 25 | * 26 | * @param {String} tag - A tag name (eg: v1.2.3) 27 | * @return {Promise} - Resolves the tag name 28 | */ 29 | const createGitTag = tag => new Promise((resolve) => { 30 | const cmd = `git tag -a ${tag} -m "${tag}"`; 31 | exec(cmd, (err) => { 32 | if (!err) { 33 | resolve(tag); 34 | } 35 | }); 36 | }); 37 | 38 | module.exports = { 39 | createGitCommit, 40 | createGitTag, 41 | }; 42 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const fs = require('fs'); 3 | const { getNextVersion } = require('./utils'); 4 | const { createGitCommit, createGitTag } = require('./git'); 5 | 6 | module.exports = args => new Promise((resolve) => { 7 | const composerJson = path.join(process.cwd(), 'composer.json'); 8 | // read the composer.json file 9 | // eslint-disable-next-line global-require 10 | const pkg = require(composerJson); 11 | // get the bump type 12 | const type = args[0]; 13 | // set the next version 14 | const nextVersion = pkg.version ? getNextVersion(pkg.version, type) : '0.0.0'; 15 | pkg.version = nextVersion; 16 | // write to the composer.json file 17 | fs.writeFileSync(composerJson, JSON.stringify(pkg, null, '\t')); 18 | // set tag name 19 | const tagName = `v${nextVersion}`; 20 | // create a new git commit and tag it 21 | createGitCommit(tagName) 22 | .then(createGitTag) 23 | .then(tag => resolve(tag)); 24 | }); 25 | -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Get the next version 3 | * 4 | * @param {String} version - The current version 5 | * @param {String} type - The type of increment (major, minor, patch) 6 | */ 7 | const getNextVersion = (version, type) => { 8 | const v = version.split('.'); 9 | let nextMajor = parseInt(v[0], 10); 10 | let nextMinor = parseInt(v[1], 10); 11 | let nextPatch = parseInt(v[2], 10); 12 | const bumpType = type ? type.toLowerCase() : ''; 13 | switch (bumpType) { 14 | case 'major': 15 | nextMajor += 1; 16 | nextMinor = 0; 17 | nextPatch = 0; 18 | break; 19 | case 'minor': 20 | nextMinor += 1; 21 | nextPatch = 0; 22 | break; 23 | case 'patch': 24 | nextPatch += 1; 25 | break; 26 | default: 27 | throw new Error('Invalid version.'); 28 | } 29 | return [nextMajor, nextMinor, nextPatch].join('.'); 30 | }; 31 | 32 | module.exports = { 33 | getNextVersion, 34 | }; 35 | --------------------------------------------------------------------------------