├── .gitignore ├── .travis.yml ├── .all-contributorsrc ├── bin └── branch-it.js ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | cache: 4 | directories: 5 | - ~/.npm 6 | node_js: 7 | - "8.3" 8 | notifications: 9 | email: false 10 | script: 11 | - npm run test 12 | 13 | # after_success: 14 | # - npm run codecov 15 | 16 | jobs: 17 | include: 18 | - stage: release 19 | node_js: lts/* 20 | script: 21 | - npm run update-branch && npm run semantic-release 22 | branches: 23 | except: 24 | - /^v\d+\.\d+\.\d+$/ 25 | -------------------------------------------------------------------------------- /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "branch-it", 3 | "projectOwner": "kibibit", 4 | "repoType": "github", 5 | "repoHost": "https://github.com", 6 | "files": [ 7 | "README.md" 8 | ], 9 | "imageSize": 100, 10 | "commit": true, 11 | "contributors": [ 12 | { 13 | "login": "Thatkookooguy", 14 | "name": "Neil Kalman", 15 | "avatar_url": "https://avatars0.githubusercontent.com/u/10427304?s=460&v=4", 16 | "profile": "https://github.com/Thatkookooguy", 17 | "contributions": [ 18 | "infra", 19 | "design", 20 | "code" 21 | ] 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /bin/branch-it.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('manakin').global; 4 | 5 | try { 6 | const fs = require('fs-extra'); 7 | const _ = require('lodash'); 8 | const branchName = require('current-git-branch'); 9 | const findUp = require('find-up'); 10 | const prettyjson = require('prettyjson'); 11 | 12 | 13 | const optionDefinitions = [{ 14 | name: 'tag', 15 | alias: 't', 16 | type: String 17 | }, 18 | { 19 | name: 'branch', 20 | alias: 'b', 21 | type: String 22 | } 23 | ]; 24 | 25 | const commandLineArgs = require('command-line-args'); 26 | const options = commandLineArgs(optionDefinitions); 27 | 28 | let packagePath; 29 | 30 | findUp('package.json', { 31 | cwd: process.cwd() 32 | }) 33 | .then((path) => { 34 | packagePath = path; 35 | return require(path); 36 | }) 37 | .then((pkg) => { 38 | pkg = pkg; 39 | 40 | const branch = options.branch || process.env.TRAVIS_BRANCH || branchName(); 41 | 42 | options.tag = options.tag || _.get(pkg, `release.versionMapping.${ branch }`); 43 | 44 | if (!options.tag) { 45 | throw new Error(`a tag was not defined by parameter or package.json for branch "${ branch }"`); 46 | } 47 | 48 | console.info('Updating package.json release params to:\n'); 49 | console.log(prettyjson.render({ 50 | 'release.branch': branch, 51 | 'publishConfig.tag': options.tag 52 | })); 53 | 54 | if (_.get(pkg, 'release.branch')) { 55 | pkg.release.branch = branch; 56 | } 57 | 58 | if (_.get(pkg, 'publishConfig.tag')) { 59 | pkg.publishConfig.tag = options.tag; 60 | } 61 | 62 | return fs.writeJson(packagePath, pkg, { 63 | spaces: 2 64 | }); 65 | }) 66 | .then(() => console.success('\n~ package.json updated ~\n')) 67 | .catch((err) => console.error(err)); 68 | 69 | } catch (err) { 70 | console.error(err); 71 | } 72 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@kibibit/branch-it", 3 | "version": "1.4.0", 4 | "description": "updates branch references in package.json", 5 | "main": "bin/branch-it.js", 6 | "bin": { 7 | "branch-it": "bin/branch-it.js" 8 | }, 9 | "scripts": { 10 | "update:dep": "npm-check", 11 | "test": "echo \"Error: no test specified\" && exit 0", 12 | "semantic-release": "semantic-release", 13 | "contributors:add": "all-contributors add", 14 | "contributors:generate": "all-contributors generate", 15 | "update-branch": "node ./bin/branch-it.js" 16 | }, 17 | "author": "neilkalman@gmail.com", 18 | "license": "MIT", 19 | "dependencies": { 20 | "command-line-args": "^5.0.2", 21 | "current-git-branch": "^1.1.0", 22 | "find-up": "^3.0.0", 23 | "fs-extra": "^7.0.1", 24 | "lodash": "^4.17.11", 25 | "manakin": "^0.5.2", 26 | "prettyjson": "^1.2.1" 27 | }, 28 | "devDependencies": { 29 | "@semantic-release/commit-analyzer": "^6.1.0", 30 | "@semantic-release/git": "^7.1.0-beta.3", 31 | "@semantic-release/github": "^5.2.10", 32 | "@semantic-release/npm": "^5.1.4", 33 | "@semantic-release/release-notes-generator": "^7.1.4", 34 | "all-contributors-cli": "^6.1.2", 35 | "npm-check": "^5.9.0", 36 | "semantic-release": "^16.0.0-beta.18", 37 | "semantic-release-cli": "^4.1.0" 38 | }, 39 | "repository": { 40 | "type": "git", 41 | "url": "https://github.com/Kibibit/branch-it.git" 42 | }, 43 | "release": { 44 | "branches": [ 45 | "+([1-9])?(.{+([1-9]),x}).x", 46 | "master", 47 | { 48 | "name": "beta", 49 | "prerelease": true 50 | }, 51 | { 52 | "name": "next", 53 | "prerelease": true 54 | } 55 | ], 56 | "plugins": [ 57 | "@semantic-release/release-notes-generator", 58 | "@semantic-release/github", 59 | "@semantic-release/npm", 60 | [ 61 | "@semantic-release/git", 62 | { 63 | "assets": [ 64 | "package.json" 65 | ], 66 | "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" 67 | } 68 | ] 69 | ], 70 | "versionMapping": { 71 | "master": "stable", 72 | "develop": "next", 73 | "next": "next" 74 | } 75 | }, 76 | "publishConfig": { 77 | "tag": "stable" 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
11 | update branch and tag references for semantic-release 12 |
13 |Neil Kalman 🚇 🎨 💻 |