Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

chore: Add gulp release task #137

Merged
merged 1 commit into from
Nov 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Contributing

## Setup

You should have [node.js], [npm] and [gulp] installed.

## Linting

Linting is done using [eslint] and the rules are based on [standard]

```bash
$ gulp lint
```

## Tests

Tests in node

```bash
$ gulp test:node
```

Tests in the browser

```bash
$ gulp test:browser
```

## Building browser version

```bash
$ gulp build
```

## Releases

The `release` task will

1. Run a build
2. Commit the build
3. Bump the version in `package.json`
4. Commit the version change
5. Create a git tag
6. Run `git push` to `upstream/master` (You can change this with `--remote my-remote`)

```bash
# Major release
$ gulp release --major
# Minor relase
$ gulp release --minor
# Patch release
$ gulp release
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I've been using npm-release for this, cool :)

```

[node.js]: https://nodejs.org/
[npm]: http://npmjs.org/
[gulp]: http://gulpjs.com/
[eslint]: http://eslint.org/
[standard]: https://github.com/feross/standard
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@
"eslint-config-standard": "^4.4.0",
"eslint-plugin-standard": "^1.3.1",
"gulp": "^3.9.0",
"gulp-bump": "^1.0.0",
"gulp-eslint": "^1.0.0",
"gulp-filter": "^3.0.1",
"gulp-git": "^1.6.0",
"gulp-load-plugins": "^1.0.0",
"gulp-mocha": "^2.1.3",
"gulp-size": "^2.0.0",
"gulp-tag-version": "^1.3.0",
"gulp-util": "^3.0.7",
"https-browserify": "0.0.1",
"ipfsd-ctl": "^0.6.1",
Expand All @@ -53,6 +57,7 @@
"require-dir": "^0.3.0",
"rimraf": "^2.4.3",
"run-sequence": "^1.1.4",
"semver": "^5.1.0",
"stream-equal": "^0.1.7",
"stream-http": "^2.0.2",
"uglify-js": "^2.4.24",
Expand Down
86 changes: 86 additions & 0 deletions tasks/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
'use strict'

const gulp = require('gulp')
const $ = require('gulp-load-plugins')()
const runSequence = require('run-sequence')
const semver = require('semver')
const fs = require('fs')
const exec = require('child_process').exec

function getCurrentVersion () {
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version
}

function npmPublish (done) {
exec('npm publish', (err, stdout, stderr) => {
if (err) throw err
$.util.log('Published to npm')
})
}

function fail (msg) {
$.util.log($.util.colors.red(msg))
process.exit(1)
}

function getType () {
if ($.util.env.major) return 'major'
if ($.util.env.minor) return 'minor'

return 'patch'
}

gulp.task('release:build', ['build'], () => {
return gulp.src('./dist')
.pipe($.git.add())
.pipe($.git.commit('chore: build', {args: '-n'}))
})

gulp.task('release:bump', () => {
const type = getType()
const newVersion = semver.inc(getCurrentVersion(), type)

return gulp.src('./package.json')
.pipe($.bump({version: newVersion}))
.pipe(gulp.dest('./'))
.pipe($.git.add())
.pipe($.git.commit(`chore: release version v${newVersion}`, {args: '-n'}))
.pipe($.filter('package.json'))
.pipe($.tagVersion())
})

gulp.task('release:push', () => {
const remote = $.util.remote || 'upstream'

$.git.push(remote, 'master', {args: '--tags'}, err => {
if (err) return fail(err.message)

$.util.log(`Pushed to git ${remote}:master`)
})
})

gulp.task('release:publish', done => {
$.git.status({args: '-s'}, (err, stdout) => {
if (err) return fail(err.message)

const isDirty = stdout.trim().length > 0

if (isDirty) {
return fail('Dirt workspace, cannot push to npm')
}

npmPublish(done)
})
})

gulp.task('release', done => {
runSequence(
'lint',
'test',
'release:build',
'release:bump',
'release:push',
'release:publish',
done
)
})