Fix release tasks after upgrade to Gulp 4 (#210)

Completion always needs to be signalled now, use the callback.

'release:init' and 'clean' called twice: 'series' is explicit execution,
not a dependency, implicit duplicate dependency resolving not supported
anymore. Remove 'series' at tasks, solely use seperate 'series' for
execution order.

'process.exit' gets "tasks did not complete" complaint, error code
ignored. Use callback with error instead.
This commit is contained in:
Norbert Renner 2019-06-28 17:26:42 +02:00
parent 88bc4a563f
commit e694629f8a

View file

@ -89,13 +89,10 @@ gulp.task('clean', function(cb) {
}); });
// libs that require loading before config.js // libs that require loading before config.js
gulp.task( gulp.task('scripts_config', function() {
'scripts_config', // just copy for now
gulp.series('clean', function() { return gulp.src(paths.scriptsConfig).pipe(gulp.dest(paths.dest));
// just copy for now });
return gulp.src(paths.scriptsConfig).pipe(gulp.dest(paths.dest));
})
);
gulp.task('scripts', function() { gulp.task('scripts', function() {
if (debug) gutil.log(gutil.colors.yellow('Running in Debug mode')); if (debug) gutil.log(gutil.colors.yellow('Running in Debug mode'));
@ -208,98 +205,75 @@ var tags = { patch: 'patch', minor: 'minor', major: 'major' };
var nextVersion; var nextVersion;
var ghToken; var ghToken;
gulp.task('release:init', function() { gulp.task('release:init', function(cb) {
var tag = gutil.env.tag; var tag = gutil.env.tag;
if (!tag) { if (!tag) {
gutil.log(gutil.colors.red('--tag is required')); return cb(new Error('--tag is required'));
process.exit(1);
} }
if (['major', 'minor', 'patch'].indexOf(tag) < 0) { if (['major', 'minor', 'patch'].indexOf(tag) < 0) {
gutil.log(gutil.colors.red('--tag must be major, minor or patch')); return cb(new Error('--tag must be major, minor or patch'));
process.exit(2);
} }
ghToken = gutil.env.token; ghToken = gutil.env.token;
if (!ghToken) { if (!ghToken) {
gutil.log( return cb(
gutil.colors.red( new Error('--token is required (github personnal access token')
'--token is required (github personnal access token)'
)
); );
process.exit(3);
} }
if (ghToken.length != 40) { if (ghToken.length != 40) {
gutil.log(gutil.colors.red('--token length must be 40')); return cb(new Error('--token length must be 40'));
process.exit(4);
} }
nextVersion = semver.inc(pkg.version, tag);
git.status({ args: '--porcelain', quiet: true }, function(err, stdout) { git.status({ args: '--porcelain', quiet: true }, function(err, stdout) {
if (err) throw err; if (err) return cb(err);
if (stdout.length > 0) { if (stdout.length > 0) {
gutil.log( return cb(
gutil.colors.red( new Error(
'Repository is not clean. Please commit or stash your pending modification' 'Repository is not clean. Please commit or stash your pending modification'
) )
); );
process.exit(5);
} }
cb();
}); });
nextVersion = semver.inc(pkg.version, tag);
return;
}); });
gulp.task( gulp.task('bump:json', function() {
'bump:json', gutil.log(gutil.colors.green('Bump to ' + nextVersion));
gulp.series('release:init', function() { return gulp
gutil.log(gutil.colors.green('Bump to ' + nextVersion)); .src(['./package.json'])
return gulp .pipe(bump({ version: nextVersion }))
.src(['./package.json']) .pipe(gulp.dest('./'));
.pipe(bump({ version: nextVersion })) });
.pipe(gulp.dest('./'));
})
);
gulp.task( gulp.task('bump:html', function() {
'bump:html', return gulp
gulp.series('release:init', function() { .src('./index.html')
return gulp .pipe(
.src('./index.html') replace(
.pipe( /<sup class="version">(.*)<\/sup>/,
replace( '<sup class="version">' + nextVersion + '</sup>'
/<sup class="version">(.*)<\/sup>/,
'<sup class="version">' + nextVersion + '</sup>'
)
) )
.pipe(gulp.dest('.')); )
}) .pipe(gulp.dest('.'));
); });
gulp.task('bump', gulp.series('bump:json', 'bump:html')); gulp.task('bump', gulp.series('bump:json', 'bump:html'));
gulp.task( gulp.task('release:commit', function() {
'release:commit', return gulp
gulp.series('bump', function() { .src(['./index.html', './package.json'])
return gulp .pipe(git.commit('release: ' + nextVersion));
.src(['./index.html', './package.json']) });
.pipe(git.commit('release: ' + nextVersion));
})
);
gulp.task( gulp.task('release:tag', function(cb) {
'release:tag', return git.tag(nextVersion, '', cb);
gulp.series('release:commit', function() { });
return git.tag(nextVersion, '', function(err) {
if (err) throw err;
});
})
);
gulp.task( gulp.task('release:push', function(cb) {
'release:push', git.push('origin', 'master', { args: '--tags' }, cb);
gulp.series('release:tag', function() { });
git.push('origin', 'master', { args: '--tags' }, function(err) {
if (err) throw err;
});
})
);
gulp.task('i18next', function() { gulp.task('i18next', function() {
return gulp return gulp
@ -335,38 +309,36 @@ gulp.task('layers_config', function() {
}); });
// Bundles layer files. To download and extract run "yarn layers" // Bundles layer files. To download and extract run "yarn layers"
gulp.task( gulp.task('layers', function() {
'layers', return (
gulp.series('layers_config', function() { gulp
return ( .src(paths.layers)
gulp // Workaround to get file extension removed from the dictionary key
.src(paths.layers) .pipe(rename({ extname: '.json' }))
// Workaround to get file extension removed from the dictionary key .pipe(
.pipe(rename({ extname: '.json' })) jsonConcat(paths.layersDestName, function(data) {
.pipe( var header =
jsonConcat(paths.layersDestName, function(data) { '// Licensed under the MIT License (https://github.com/nrenner/brouter-web#license + Credits and Licenses),\n' +
var header = '// except JOSM imagery database (dataSource=JOSM) is licensed under Creative Commons (CC-BY-SA),\n' +
'// Licensed under the MIT License (https://github.com/nrenner/brouter-web#license + Credits and Licenses),\n' + '// see https://josm.openstreetmap.de/wiki/Maps#Otherimportantinformation\n';
'// except JOSM imagery database (dataSource=JOSM) is licensed under Creative Commons (CC-BY-SA),\n' + return Buffer.from(
'// see https://josm.openstreetmap.de/wiki/Maps#Otherimportantinformation\n'; header +
return Buffer.from( 'BR.layerIndex = ' +
header + JSON.stringify(data, null, 2) +
'BR.layerIndex = ' + ';'
JSON.stringify(data, null, 2) + );
';' })
); )
}) .pipe(gulp.dest(paths.dest))
) );
.pipe(gulp.dest(paths.dest)) });
);
})
);
gulp.task( gulp.task(
'default', 'default',
gulp.series( gulp.series(
'clean', 'clean',
'scripts_config', 'scripts_config',
'layers_config',
'layers', 'layers',
'scripts', 'scripts',
'styles', 'styles',
@ -378,47 +350,34 @@ gulp.task(
gulp.task( gulp.task(
'debug', 'debug',
gulp.series(function(done) { gulp.series(function(cb) {
debug = true; debug = true;
done(); cb();
}, 'default') }, 'default')
); );
gulp.task( gulp.task('release:zip', function() {
'release:zip', gutil.log(gutil.colors.green('Build brouter-web.' + nextVersion + '.zip'));
gulp.series('release:tag', 'default', function() { return gulp
gutil.log( .src(
gutil.colors.green('Build brouter-web.' + nextVersion + '.zip') ['dist/**', 'index.html', 'config.template.js', 'keys.template.js'],
); {
return gulp base: '.'
.src( }
[ )
'dist/**', .pipe(zip('brouter-web.' + nextVersion + '.zip'))
'index.html', .pipe(gulp.dest('.'));
'config.template.js', });
'keys.template.js'
],
{
base: '.'
}
)
.pipe(zip('brouter-web.' + nextVersion + '.zip'))
.pipe(gulp.dest('.'));
})
);
gulp.task( gulp.task('release:publish', function() {
'release:publish', return gulp.src('./brouter-web.' + nextVersion + '.zip').pipe(
gulp.series('release:zip', function() { release({
gulp.src('./brouter-web.' + nextVersion + '.zip').pipe( tag: nextVersion,
release({ token: ghToken,
tag: nextVersion, manifest: pkg
token: ghToken, })
manifest: pkg );
}) });
);
})
);
gulp.task( gulp.task(
'release', 'release',
@ -428,6 +387,7 @@ gulp.task(
'release:commit', 'release:commit',
'release:tag', 'release:tag',
'release:push', 'release:push',
'default',
'release:zip', 'release:zip',
'release:publish' 'release:publish'
) )