-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
122 lines (104 loc) · 3.37 KB
/
gulpfile.babel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
require('dotenv').config()
const gulp = require('gulp')
const fs = require('fs')
const del = require('del')
const runSequence = require('run-sequence')
const util = require('gulp-util')
const rollup = require('rollup').rollup
const commonjs = require('rollup-plugin-commonjs')
const babel = require('rollup-plugin-babel')
const nodeResolve = require('rollup-plugin-node-resolve')
const stylus = require('gulp-stylus')
const connect = require('gulp-connect')
const bump = require('gulp-bump')
const git = require('gulp-git')
const conventionalGithubReleaser = require('conventional-github-releaser')
const port = process.env.PORT || 8080;
// Configs for all tasks
// Comments are just examples how to add posible configurations to the tasks
const rollupConf = {
entry: 'src/index.js',
external: [ 'react' ],
plugins: [
//nodeResolve({ jsnext: true }),
babel(),
commonjs({
//include: 'node_modules/**'
})
]
}
//A self-executing function, suitable for inclusion as a <script> tag format
const iifeBundleConf = {
format: 'iife',
moduleName: 'component',
dest: 'dist/index.iife.js'
}
//CommonJS, suitable for Node and Browserify/Webpack format
const cjsBundleConf = {
format: 'cjs',
dest: 'dist/index.js'
}
//example server confin
const exampleServConf = {
root: ['demo'],
port: port,
livereload: true
}
gulp.task('serv', () => connect.server(exampleServConf))
gulp.task('reload-js', () => gulp.src('dist/*.js').pipe(connect.reload()))
gulp.task('build:iife', () => rollup(rollupConf).then((bundle) => bundle.write(iifeBundleConf)))
gulp.task('build:cjs', () => rollup(rollupConf).then((bundle) => bundle.write(cjsBundleConf)))
gulp.task('style', () => gulp.src('style/*.styl').pipe(stylus()).pipe(gulp.dest('dist')))
gulp.task('style:min', () => gulp.src('style/*.styl').pipe(stylus({ compress: true })).pipe(gulp.dest('dist')))
gulp.task('build', ['build:cjs', 'build:iife', 'style:min'])
gulp.task('clean', () => del(['dist']) )
gulp.task('watch', () => {
gulp.watch('src/*.js', ['build:iife', 'build:cjs', 'reload-js'])
gulp.watch('style/*.styl', ['style'])
})
// Tasks for the github release
gulp.task('bump-ver', () => {
const options = { type: util.env.type || 'patch' }
gulp.src('./package.json')
.pipe(bump(options)).on('error', util.log)
.pipe(gulp.dest('./'))
})
//git commit task
gulp.task('commit-changes', () => gulp.src('.')
.pipe(git.add())
.pipe(git.commit('Bumped version number'))
)
//git push taks
gulp.task('push-changes', cb => git.push('origin', 'master', cb))
//git create new tag task
gulp.task('create-new-tag', cb => {
const version = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version
git.tag(version, 'Created Tag for version: ' + version, error => {
if (error) return cb(error)
git.push('origin', 'master', { args: '--tags' }, cb)
})
})
//github release task
gulp.task('github-release', done => {
conventionalGithubReleaser({
type: 'oauth',
token: process.env.OAUTH // change this to your own GitHub token or use an environment variable
}, {}, done)
})
gulp.task('release', callback => {
runSequence(
'bump-ver',
'commit-changes',
'push-changes',
'create-new-tag',
'github-release',
error => {
if (error) {
console.log(error.message)
} else {
console.log('Release done')
}
callback(error)
})
})
gulp.task('default', ['clean', 'watch'])