2017-10-31 05:39:21 +00:00
|
|
|
const gulp = require('gulp');
|
|
|
|
const concat = require('gulp-concat');
|
|
|
|
const replace = require('gulp-replace');
|
|
|
|
const rename = require('gulp-rename');
|
|
|
|
const jshint = require('gulp-jshint');
|
2017-11-17 14:31:29 +00:00
|
|
|
const path = require('path');
|
2017-10-31 05:39:21 +00:00
|
|
|
const del = require('del');
|
|
|
|
const os = require('os');
|
2017-11-17 14:31:29 +00:00
|
|
|
const fs = require('fs');
|
2017-11-17 14:29:09 +00:00
|
|
|
const spawn = require('child_process').spawn;
|
2017-10-31 05:39:21 +00:00
|
|
|
const { URL } = require('url');
|
|
|
|
const compl = require('./completions');
|
2017-08-28 03:24:24 +00:00
|
|
|
|
|
|
|
var paths = {
|
2017-10-31 05:39:21 +00:00
|
|
|
scripts: ['conf.priv.js', 'completions.js', 'conf.js'],
|
2017-10-31 07:27:41 +00:00
|
|
|
gulpfile: ['gulpfile.js'],
|
2017-10-31 05:39:21 +00:00
|
|
|
readme: ['README.tmpl.md'],
|
2017-11-17 14:31:29 +00:00
|
|
|
screenshots: 'assets/screenshots',
|
2017-08-28 03:24:24 +00:00
|
|
|
};
|
|
|
|
|
2017-10-31 07:27:41 +00:00
|
|
|
// This notice will be injected into the generated README.md file
|
2017-10-31 05:39:21 +00:00
|
|
|
const disclaimer = `\
|
|
|
|
<!--
|
|
|
|
|
|
|
|
NOTICE:
|
|
|
|
This is an automatically generated file - Do not edit it directly.
|
|
|
|
The source file is README.tmpl.md
|
|
|
|
|
|
|
|
-->`;
|
|
|
|
|
2017-11-17 14:29:09 +00:00
|
|
|
gulp.task('gulp-autoreload', function() {
|
|
|
|
var p;
|
|
|
|
var spawnChildren = function() {
|
|
|
|
if (p) p.kill();
|
|
|
|
p = spawn('gulp', ['lint-gulpfile', 'install', 'watch-nogulpfile'], {stdio: 'inherit'});
|
|
|
|
};
|
|
|
|
gulp.watch('gulpfile.js', spawnChildren);
|
|
|
|
spawnChildren();
|
|
|
|
});
|
|
|
|
|
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() {
|
2017-10-31 07:27:41 +00:00
|
|
|
return gulp.src([].concat(paths.scripts, paths.gulpfile))
|
2017-09-17 23:25:38 +00:00
|
|
|
.pipe(jshint())
|
|
|
|
.pipe(jshint.reporter('jshint-stylish'));
|
|
|
|
});
|
|
|
|
|
2017-11-17 14:29:09 +00:00
|
|
|
gulp.task('lint-gulpfile', function() {
|
|
|
|
return gulp.src([].concat(paths.gulpfile))
|
|
|
|
.pipe(jshint())
|
|
|
|
.pipe(jshint.reporter('jshint-stylish'));
|
|
|
|
});
|
|
|
|
|
2017-10-31 05:39:21 +00:00
|
|
|
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-10-31 07:27:41 +00:00
|
|
|
});
|
2017-08-28 03:24:24 +00:00
|
|
|
|
|
|
|
gulp.task('watch', function() {
|
2017-11-17 14:29:09 +00:00
|
|
|
gulp.watch([].concat(paths.scripts, paths.gulpfile), ['readme', 'install']);
|
|
|
|
gulp.watch(paths.readme, ['readme']);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('watch-nogulpfile', function() {
|
|
|
|
gulp.watch([].concat(paths.scripts), ['readme', 'install']);
|
2017-10-31 05:39:21 +00:00
|
|
|
gulp.watch(paths.readme, ['readme']);
|
2017-08-28 03:24:24 +00:00
|
|
|
});
|
|
|
|
|
2017-10-31 05:39:21 +00:00
|
|
|
gulp.task('readme', function() {
|
2017-11-17 14:31:29 +00:00
|
|
|
var screens = {};
|
|
|
|
var screenshotList = "";
|
|
|
|
fs.readdirSync(path.join(__dirname, paths.screenshots)).forEach(function(s) {
|
|
|
|
var file = path.basename(s, '.png').split('-');
|
|
|
|
var alias = file[0];
|
|
|
|
if (!screens[alias]) {
|
|
|
|
screens[alias] = [];
|
|
|
|
}
|
|
|
|
screens[alias].push(path.join(paths.screenshots, path.basename(s)));
|
|
|
|
});
|
2017-11-14 07:22:07 +00:00
|
|
|
var table = Object.keys(compl).sort(function(a, b) {
|
|
|
|
if (a < b) return -1;
|
|
|
|
if (a > b) return 1;
|
2017-10-31 05:39:21 +00:00
|
|
|
return 0;
|
2017-11-14 07:22:07 +00:00
|
|
|
}).reduce(function(a, k) {
|
|
|
|
var c = compl[k];
|
2017-10-31 05:39:21 +00:00
|
|
|
var u = new URL(c.search);
|
2017-11-17 14:31:29 +00:00
|
|
|
var domain = (u.hostname === "cse.google.com") ? "Google Custom Search" : u.hostname;
|
|
|
|
var s = "";
|
|
|
|
if (screens[c.alias]) {
|
|
|
|
screens[c.alias].forEach(function(url, i) {
|
|
|
|
var num = (i > 0) ? ` ${i+1}` : "";
|
|
|
|
s += `[\\[${i+1}\\]](#${c.name}${num.replace(' ', '-')}) `;
|
|
|
|
screenshotList += `##### ${c.name}${num}\n`;
|
|
|
|
screenshotList += `![${c.name} screenshot](./${url})\n\n`;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return a + `| \`${c.alias}\` | \`${c.name}\` | \`${domain}\` | ${s} |\n`;
|
2017-10-31 07:36:11 +00:00
|
|
|
}, "");
|
2017-10-31 07:41:45 +00:00
|
|
|
return gulp.src(['./README.tmpl.md'])
|
2017-10-31 05:39:21 +00:00
|
|
|
.pipe(replace("<!--DISCLAIMER-->", disclaimer))
|
2017-11-14 07:22:07 +00:00
|
|
|
.pipe(replace("<!--COMPL_COUNT-->", Object.keys(compl).length))
|
2017-10-31 07:27:41 +00:00
|
|
|
.pipe(replace("<!--COMPL_TABLE-->", table))
|
2017-11-17 14:31:29 +00:00
|
|
|
.pipe(replace("<!--SCREENSHOTS-->", screenshotList))
|
2017-10-31 05:39:21 +00:00
|
|
|
.pipe(rename('README.md'))
|
|
|
|
.pipe(gulp.dest('.'));
|
2017-10-31 07:27:41 +00:00
|
|
|
});
|
2017-10-31 05:39:21 +00:00
|
|
|
|
2017-08-28 03:24:24 +00:00
|
|
|
gulp.task('default', ['build']);
|