-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
215 lines (180 loc) · 5.01 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
var _ = require('lodash');
var async = require('async');
var clean = require('gulp-clean');
var exec = require('child_process').exec;
var firstline = require('firstline');
var format = require('string-format');
var fs = require('fs');
var gulp = require('gulp');
var gzip = require('gulp-gzip');
var reader = require('line-reader');
var rename = require('gulp-rename');
var semver = require('semver');
var tar = require('gulp-tar');
var shell = require('gulp-shell');
var version;
var title;
format.extend(String.prototype);
function get_changelog(cb) {
var file = 'docs/CHANGES.txt';
var counter = 0;
var lines = [];
reader.eachLine(file, function(line) {
counter++;
var trimmed = line.trim();
if (counter === 1) {
return;
}
if (line === '') {
return;
}
if (trimmed.startsWith('--')) {
return false; // stop reading
} else {
lines.push(trimmed);
}
}, function(err) {
if (err) {
cb(err);
}
var fixed = [];
_.each(lines, function(line) {
if (line.startsWith('*')) {
fixed.push(line);
} else {
fixed[fixed.length - 1] = fixed[fixed.length - 1] + ' ' + line;
}
});
cb(null, fixed);
});
}
function get_version() {
var changes = 'docs/CHANGES.txt';
return firstline(changes);
}
gulp.task('version', function(callback) {
get_version().then(function(version_string) {
version = version_string;
title = 'osdf-{}'.format(version);
callback();
});
});
var sources = [
'README.md',
'*.js',
'!gulpfile.js',
'bin/**',
'conf/**',
'debian/**',
'docs/**',
'lib/**',
'logs/**',
'node_modules/**',
'test/**',
'util/**',
'working/**'
];
// remove the build and dist directories
gulp.task('clean', function() {
return gulp.src(['build', 'dist'])
.pipe(clean());
});
// Compile the jison based parser.
gulp.task('oql_parser', function() {
gulp.src('./util/oql.jison')
.pipe(shell(['./node_modules/.bin/jison <%= file.path %> -o oql_jison_parser.js']));
});
gulp.task('deps', ['oql_parser'], function() {
gulp.src('')
.pipe(shell(['npm install']));
});
gulp.task('build', ['version', 'deps'], function() {
return gulp.src(sources, {'base': '.'})
.pipe(gulp.dest('build/' + title));
});
gulp.task('tar', ['build'], function() {
return gulp.src('build/' + title + '/**', {'base': 'build'})
.pipe(tar(title + '.tar'))
.pipe(gulp.dest('build'));
});
gulp.task('gzip', ['tar'], function() {
var tarfile = 'build/{}.tar'.format(title);
return gulp.src(tarfile, {'base': 'build'})
.pipe(gzip())
.pipe(gulp.dest('build'));
});
gulp.task('bump_package_files', ['version'], function(cb) {
var filename = './package.json';
fs.readFile(filename, 'utf-8', function(err, data) {
var parsed = JSON.parse(data);
parsed.version = version;
if (! semver.valid(parsed.version)) {
cb('Invalid version ' + version);
return;
}
fs.writeFile(filename, JSON.stringify(parsed, null, 4), function(err) {
if (err) {
cb(err);
} else {
cb();
}
});
});
});
gulp.task('latest_changes', function(cb) {
get_changelog(function(err, lines) {
console.log(lines.join('\n'));
cb();
});
});
gulp.task('deb_orig_tarball', ['gzip'], function() {
return gulp.src('build/{}.tar.gz'.format(title))
.pipe(rename('osdf_{}.orig.tar.gz'.format(version)))
.pipe(gulp.dest('build'));
});
// Create the deb package file.
gulp.task('deb', ['deb_orig_tarball'], function(callback) {
var debuild = 'debuild -us -uc --lintian-opts ' +
'--suppress-tags bad-distribution-in-changes-file';
var opts = {
cwd: './build/' + title
};
exec(debuild, opts, function(err, stdout, stderr) {
if (stderr) {
console.log(stderr);
}
callback(err);
});
});
// Run the unit tests in the test directory.
gulp.task('test', function() {
var test_scripts = [
'./test/aux-*.js',
'./test/linkage-*.js',
'./test/namespace-*.js',
'./test/node-*.js',
'./test/oql*.js',
'./test/osdf-info.js',
'./test/permissions.js',
'./test/schema-*.js'
];
gulp.src(test_scripts)
.pipe(shell(['nodeunit <%= file.path %>'],
{env: {NODE_PATH: '.:./lib'}}
));
});
gulp.task('dist', ['deb'], function() {
var base = 'build/osdf_' + version;
var tarball = 'build/osdf-{}.tar.gz'.format(version);
var files = [
base + '*.buildinfo',
base + '*.changes',
base + '*.debian.tar.xz',
base + '*.deb',
base + '*.dsc',
tarball
];
return gulp.src(files)
.pipe(gulp.dest('dist'));
});
gulp.task('default', ['dist']);