forked from iVis-at-Bilkent/cytoscape.js-expand-collapse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
127 lines (107 loc) · 3.03 KB
/
gulpfile.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
123
124
125
126
127
var gulp = require('gulp');
var watch = require('gulp-watch');
var replace = require('gulp-replace');
var shell = require('gulp-shell');
var jshint = require('gulp-jshint');
var jshStylish = require('jshint-stylish');
var exec = require('child_process').exec;
var runSequence = require('run-sequence');
var prompt = require('gulp-prompt');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
var gutil = require('gulp-util');
var notifier = require('node-notifier');
var derequire = require('gulp-derequire');
var version;
var browserifyOpts = {
entries: './src/index.js',
debug: true,
standalone: 'cytoscape-expand-collapse'
};
var logError = function (err) {
notifier.notify({ title: 'cytoscape-expand-collapse', message: 'Error: ' + err.message });
gutil.log(gutil.colors.red('Error in watch:'), gutil.colors.red(err));
};
gulp.task('build', function () {
return browserify(browserifyOpts)
.bundle()
.on('error', logError)
.pipe(source('cytoscape-expand-collapse.js'))
.pipe(buffer())
.pipe(derequire())
.pipe(gulp.dest('.'))
});
gulp.task('default', ['build'], function (next) {
next();
});
// watch for changes in files, run build immediately
gulp.task('dev', ['build'], function () {
watch('src/*.js', () => {
gulp.run('build');
});
});
gulp.task('publish', [], function (next) {
runSequence('confver', 'pkgver', 'push', 'tag', 'npm', next);
});
gulp.task('confver', ['version'], function () {
return gulp.src('.')
.pipe(prompt.confirm({ message: 'Are you sure version `' + version + '` is OK to publish?' }))
;
});
gulp.task('version', function (next) {
var now = new Date();
version = process.env['VERSION'];
if (version) {
done();
} else {
exec('git rev-parse HEAD', function (error, stdout, stderr) {
var sha = stdout.substring(0, 10); // shorten so not huge filename
version = ['snapshot', sha, +now].join('-');
done();
});
}
function done() {
console.log('Using version number `%s` for building', version);
next();
}
});
gulp.task('pkgver', ['version'], function () {
return gulp.src([
'package.json',
'bower.json'
])
.pipe(replace(/\"version\"\:\s*\".*?\"/, '"version": "' + version + '"'))
.pipe(gulp.dest('./'))
;
});
gulp.task('push', shell.task([
'git add -A',
'git commit -m "pushing changes for v$VERSION release" || echo Nothing to commit',
'git push || echo Nothing to push'
]));
gulp.task('tag', shell.task([
'git tag -a $VERSION -m "tagging v$VERSION"',
'git push origin $VERSION'
]));
gulp.task('npm', shell.task([
'npm publish .'
]));
// http://www.jshint.com/docs/options/
gulp.task('lint', function () {
return gulp.src('cytoscape-*.js')
.pipe(jshint({
funcscope: true,
laxbreak: true,
loopfunc: true,
strict: true,
unused: 'vars',
eqnull: true,
sub: true,
shadow: true,
laxcomma: true
}))
.pipe(jshint.reporter(jshStylish))
.pipe(jshint.reporter('fail'))
;
});