Skip to content

Commit 2e2dfdd

Browse files
committed
refactor(gulp): Break up gulpfile
1 parent b398e3d commit 2e2dfdd

File tree

14 files changed

+247
-180
lines changed

14 files changed

+247
-180
lines changed

gulp/config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// this is needed because it *looks* like karma wants an absolute
2+
// path to the conf file
3+
import {resolve} from 'path';
4+
5+
const karmaConfigPath = resolve('.') + '/karma.conf.js';
6+
7+
export default {
8+
source: './src',
9+
dist: './dist',
10+
example: './example',
11+
importance: 'patch',
12+
test: {
13+
karma: karmaConfigPath
14+
}
15+
};

gulp/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import './tasks/browser-sync';
2+
import './tasks/build';
3+
import './tasks/changelog';
4+
import './tasks/clean';
5+
import './tasks/default';
6+
import './tasks/lint';
7+
import './tasks/release';
8+
import './tasks/scripts';
9+
import './tasks/test';
10+
import './tasks/watch';

gulp/options.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import minimist from 'minimist';
2+
3+
/*
4+
Capture any args that might have been passed in
5+
*/
6+
var knownOptions = {
7+
string: 'env',
8+
'boolean': 'debug',
9+
'default': {
10+
env: process.env.NODE_ENV || 'development',
11+
debug: false
12+
}
13+
};
14+
15+
export default minimist(process.argv.slice(2), knownOptions);

gulp/tasks/browser-sync.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import config from '../config';
2+
3+
import gulp from 'gulp';
4+
5+
import {create} from 'browser-sync';
6+
7+
const browserSync = create();
8+
9+
gulp.task('serve', function() {
10+
browserSync.init({
11+
server: {
12+
baseDir: config.example
13+
},
14+
port: 8080,
15+
notify: false
16+
});
17+
});

gulp/tasks/build.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import gulp from 'gulp';
2+
3+
import runSequence from 'run-sequence';
4+
5+
gulp.task('build', function() {
6+
runSequence('lint', 'test:once', 'scripts');
7+
});

gulp/tasks/changelog.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import gulp from 'gulp';
2+
3+
import changelog from 'gulp-conventional-changelog';
4+
5+
gulp.task('changelog', function() {
6+
return gulp.src('CHANGELOG.md', {
7+
buffer: false
8+
})
9+
.pipe(changelog({
10+
preset: 'angular'
11+
}))
12+
.pipe(gulp.dest('./'));
13+
});

gulp/tasks/clean.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import config from '../config';
2+
3+
import gulp from 'gulp';
4+
5+
gulp.task('clean', function(cb) {
6+
require('del')([config.dist, config.example + '/lib'], {
7+
force: true
8+
}, cb);
9+
});

gulp/tasks/default.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import gulp from 'gulp';
2+
3+
gulp.task('default', [
4+
'scripts',
5+
'serve',
6+
'watch'
7+
]);
8+
9+
gulp.task('pre-push', [
10+
'lint',
11+
'test:once'
12+
]);

gulp/tasks/lint.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import config from '../config';
2+
3+
import gulp from 'gulp';
4+
import plumber from 'gulp-plumber';
5+
import eslint from 'gulp-eslint';
6+
7+
gulp.task('lint', function() {
8+
return gulp.src(config.source + '/*.js')
9+
.pipe(plumber())
10+
.pipe(eslint())
11+
.pipe(eslint.format());
12+
});

gulp/tasks/release.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import gulp from 'gulp';
2+
import bump from 'gulp-bump';
3+
import git from 'gulp-git';
4+
import filter from 'gulp-filter';
5+
import tag from 'gulp-tag-version';
6+
7+
import runSequence from 'run-sequence';
8+
9+
var config = {
10+
importance: 'patch'
11+
};
12+
13+
function getImportance() {
14+
return config.importance;
15+
}
16+
17+
function release() {
18+
runSequence(
19+
'test:once',
20+
'scripts',
21+
'bump',
22+
'changelog',
23+
'commit-release'
24+
);
25+
}
26+
27+
gulp.task('bump', function() {
28+
return gulp.src([
29+
'./bower.json',
30+
'./package.json'
31+
])
32+
.pipe(bump({
33+
type: getImportance()
34+
}))
35+
.pipe(gulp.dest('./'));
36+
});
37+
38+
gulp.task('commit-release', function() {
39+
return gulp.src([
40+
'./bower.json',
41+
'./package.json',
42+
'./CHANGELOG.md',
43+
'./dist'
44+
])
45+
.pipe(git.add({
46+
args: '-f -A'
47+
}))
48+
.pipe(git.commit('chore(release): New ' + getImportance() + ' release'))
49+
.pipe(filter('bower.json'))
50+
.pipe(tag());
51+
});
52+
53+
gulp.task('release:patch', function() {
54+
return release();
55+
});
56+
57+
gulp.task('release:minor', function() {
58+
config.importance = 'minor';
59+
60+
return release();
61+
});
62+
63+
gulp.task('release:major', function() {
64+
config.importance = 'major';
65+
66+
return release();
67+
});

0 commit comments

Comments
 (0)