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

Commit ac65107

Browse files
committedNov 22, 2015
chore: Add gulp release task
1 parent 06094d1 commit ac65107

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed
 

‎CONTRIBUTING.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Contributing
2+
3+
## Setup
4+
5+
You should have [node.js], [npm] and [gulp] installed.
6+
7+
## Linting
8+
9+
Linting is done using [eslint] and the rules are based on [standard]
10+
11+
```bash
12+
$ gulp lint
13+
```
14+
15+
## Tests
16+
17+
Tests in node
18+
19+
```bash
20+
$ gulp test:node
21+
```
22+
23+
Tests in the browser
24+
25+
```bash
26+
$ gulp test:browser
27+
```
28+
29+
## Building browser version
30+
31+
```bash
32+
$ gulp build
33+
```
34+
35+
## Releases
36+
37+
The `release` task will
38+
39+
1. Run a build
40+
2. Commit the build
41+
3. Bump the version in `package.json`
42+
4. Commit the version change
43+
5. Create a git tag
44+
6. Run `git push` to `upstream/master` (You can change this with `--remote my-remote`)
45+
46+
```bash
47+
# Major release
48+
$ gulp release --major
49+
# Minor relase
50+
$ gulp release --minor
51+
# Patch release
52+
$ gulp release
53+
```
54+
55+
[node.js]: https://nodejs.org/
56+
[npm]: http://npmjs.org/
57+
[gulp]: http://gulpjs.com/
58+
[eslint]: http://eslint.org/
59+
[standard]: https://github.com/feross/standard

‎package.json

+5
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@
3232
"eslint-config-standard": "^4.4.0",
3333
"eslint-plugin-standard": "^1.3.1",
3434
"gulp": "^3.9.0",
35+
"gulp-bump": "^1.0.0",
3536
"gulp-eslint": "^1.0.0",
37+
"gulp-filter": "^3.0.1",
38+
"gulp-git": "^1.6.0",
3639
"gulp-load-plugins": "^1.0.0",
3740
"gulp-mocha": "^2.1.3",
3841
"gulp-size": "^2.0.0",
42+
"gulp-tag-version": "^1.3.0",
3943
"gulp-util": "^3.0.7",
4044
"https-browserify": "0.0.1",
4145
"ipfsd-ctl": "^0.6.1",
@@ -53,6 +57,7 @@
5357
"require-dir": "^0.3.0",
5458
"rimraf": "^2.4.3",
5559
"run-sequence": "^1.1.4",
60+
"semver": "^5.1.0",
5661
"stream-equal": "^0.1.7",
5762
"stream-http": "^2.0.2",
5863
"uglify-js": "^2.4.24",

‎tasks/release.js

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
'use strict'
2+
3+
const gulp = require('gulp')
4+
const $ = require('gulp-load-plugins')()
5+
const runSequence = require('run-sequence')
6+
const semver = require('semver')
7+
const fs = require('fs')
8+
const exec = require('child_process').exec
9+
10+
function getCurrentVersion () {
11+
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version
12+
}
13+
14+
function npmPublish (done) {
15+
exec('npm publish', (err, stdout, stderr) => {
16+
if (err) throw err
17+
$.util.log('Published to npm')
18+
})
19+
}
20+
21+
function fail (msg) {
22+
$.util.log($.util.colors.red(msg))
23+
process.exit(1)
24+
}
25+
26+
function getType () {
27+
if ($.util.env.major) return 'major'
28+
if ($.util.env.minor) return 'minor'
29+
30+
return 'patch'
31+
}
32+
33+
gulp.task('release:build', ['build'], () => {
34+
return gulp.src('./dist')
35+
.pipe($.git.add())
36+
.pipe($.git.commit('chore: build', {args: '-n'}))
37+
})
38+
39+
gulp.task('release:bump', () => {
40+
const type = getType()
41+
const newVersion = semver.inc(getCurrentVersion(), type)
42+
43+
return gulp.src('./package.json')
44+
.pipe($.bump({version: newVersion}))
45+
.pipe(gulp.dest('./'))
46+
.pipe($.git.add())
47+
.pipe($.git.commit(`chore: release version v${newVersion}`, {args: '-n'}))
48+
.pipe($.filter('package.json'))
49+
.pipe($.tagVersion())
50+
})
51+
52+
gulp.task('release:push', () => {
53+
const remote = $.util.remote || 'upstream'
54+
55+
$.git.push(remote, 'master', {args: '--tags'}, err => {
56+
if (err) return fail(err.message)
57+
58+
$.util.log(`Pushed to git ${remote}:master`)
59+
})
60+
})
61+
62+
gulp.task('release:publish', done => {
63+
$.git.status({args: '-s'}, (err, stdout) => {
64+
if (err) return fail(err.message)
65+
66+
const isDirty = stdout.trim().length > 0
67+
68+
if (isDirty) {
69+
return fail('Dirt workspace, cannot push to npm')
70+
}
71+
72+
npmPublish(done)
73+
})
74+
})
75+
76+
gulp.task('release', done => {
77+
runSequence(
78+
'lint',
79+
'test',
80+
'release:build',
81+
'release:bump',
82+
'release:push',
83+
'release:publish',
84+
done
85+
)
86+
})

0 commit comments

Comments
 (0)
This repository has been archived.