surfingkeys-conf/gulpfile.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

const gulp = require('gulp');
const concat = require('gulp-concat');
const replace = require('gulp-replace');
const rename = require('gulp-rename');
const jshint = require('gulp-jshint');
const del = require('del');
const os = require('os');
const { URL } = require('url');
const compl = require('./completions');
2017-08-28 03:24:24 +00:00
var paths = {
scripts: ['conf.priv.js', 'completions.js', 'conf.js'],
gulpfile: ['gulpfile.js'],
readme: ['README.tmpl.md'],
2017-08-28 03:24:24 +00:00
};
// This notice will be injected into the generated README.md file
const disclaimer = `\
<!--
NOTICE:
This is an automatically generated file - Do not edit it directly.
The source file is README.tmpl.md
-->`;
2017-08-28 03:24:24 +00:00
gulp.task('clean', function() {
return del(['build']);
});
2017-09-17 23:25:38 +00:00
gulp.task('lint', function() {
return gulp.src([].concat(paths.scripts, paths.gulpfile))
2017-09-17 23:25:38 +00:00
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('build', ['clean', 'lint', 'readme'], function() {
2017-08-28 03:24:24 +00:00
return gulp.src(paths.scripts)
.pipe(concat('.surfingkeys'))
.pipe(gulp.dest('build'));
});
gulp.task('install', ['build'], function() {
return gulp.src('build/.surfingkeys')
.pipe(gulp.dest(os.homedir()));
});
2017-08-28 03:24:24 +00:00
gulp.task('watch', function() {
2017-10-31 07:36:11 +00:00
gulp.watch([].concat(paths.scripts, paths.gulpfile), ['build']);
gulp.watch(paths.readme, ['readme']);
2017-08-28 03:24:24 +00:00
});
gulp.task('readme', function() {
2017-10-31 07:36:11 +00:00
var table = compl.sort(function(a, b) {
if (a.alias < b.alias) return -1;
if (a.alias > b.alias) return 1;
return 0;
2017-10-31 07:36:11 +00:00
}).reduce(function(a, c) {
var u = new URL(c.search);
2017-10-31 07:36:11 +00:00
return a + `| \`${c.alias}\` | \`${c.name}\` | \`${u.hostname}\` |\n`;
}, "");
gulp.src(['./README.tmpl.md'])
.pipe(replace("<!--DISCLAIMER-->", disclaimer))
.pipe(replace("<!--COMPL_COUNT-->", compl.length))
.pipe(replace("<!--COMPL_TABLE-->", table))
.pipe(rename('README.md'))
.pipe(gulp.dest('.'));
});
2017-08-28 03:24:24 +00:00
gulp.task('default', ['build']);