132 lines
4.0 KiB
JavaScript
132 lines
4.0 KiB
JavaScript
var gulp = require('gulp');
|
|
var bower = require('gulp-bower');
|
|
var help = require('gulp-task-listing');
|
|
var clean = require('gulp-clean');
|
|
var toml = require('gulp-toml');
|
|
var sass = require('gulp-sass');
|
|
var rename = require("gulp-rename");
|
|
var yaml = require('gulp-yaml');
|
|
var template = require('gulp-template');
|
|
var wrapper = require('gulp-wrapper');
|
|
var webserver = require('gulp-webserver');
|
|
var marked = require('marked');
|
|
var spritz = require('spritzjs');
|
|
var modify = require('gulp-modify');
|
|
var _ = require('lodash');
|
|
|
|
gulp.task('help', help);
|
|
|
|
gulp.task('bower', function(){
|
|
return bower()
|
|
.pipe(gulp.dest('lib/'))
|
|
.on('error', console.log);
|
|
});
|
|
|
|
gulp.task('sass', ['bower'], function(){
|
|
var extraSassPath = ['./lib/'];
|
|
return gulp.src('./scss/*.scss')
|
|
.pipe(sass({includePaths: extraSassPath}).on('error', console.log))
|
|
.pipe(gulp.dest('./css'));
|
|
});
|
|
|
|
gulp.task('clean', function(){
|
|
return gulp.src(["lib/", "css/"], {read: false})
|
|
.pipe(clean());
|
|
});
|
|
|
|
gulp.task('compile-results', function(){
|
|
return gulp.src('data/*.yaml')
|
|
.pipe(yaml({safe: true}))
|
|
.pipe(gulp.dest('./api'));
|
|
});
|
|
|
|
var encryptFile = function(message){
|
|
var keyLengthInBytes = 128;
|
|
var salt = process.env.SALT || '';
|
|
var stringKey = salt + (process.env.KEY || 'qwerty');
|
|
var key = spritz.hash(stringKey, keyLengthInBytes);
|
|
var byteArrMessage = spritz.stringToUtf8ByteArray(message);
|
|
var cypher = spritz.encrypt(key, byteArrMessage);
|
|
return JSON.stringify(cypher);
|
|
};
|
|
|
|
gulp.task('encrypt-results', ['compile-results'], function(){
|
|
return gulp.src('api/*.clear.json')
|
|
.pipe(modify({
|
|
fileModifier: function(file, content) {
|
|
return encryptFile(content);
|
|
}
|
|
}))
|
|
.pipe(rename(function(path){
|
|
path.basename = path.basename.replace(/\.clear$/i, '');
|
|
path.extname = '.json.spritz';
|
|
return path;
|
|
}))
|
|
.pipe(gulp.dest('./api'));
|
|
});
|
|
|
|
gulp.task('template-prod', function () {
|
|
return gulp.src('index.tmpl.html')
|
|
.pipe(rename("index.html"))
|
|
.pipe(template({production: true, salt: process.env.SALT, playerListLocation: process.env.PLAYER_LIST_LOCATION}))
|
|
.pipe(gulp.dest('.'));
|
|
});
|
|
|
|
gulp.task('template-dev', function () {
|
|
return gulp.src('index.tmpl.html')
|
|
.pipe(rename("index.html"))
|
|
.pipe(template({production: false, salt: '', playerListLocation: 'api/players.json.spritz'}))
|
|
.pipe(gulp.dest('.'));
|
|
});
|
|
|
|
gulp.task('compile-articles', function(){
|
|
|
|
var transformArticle = function(article){
|
|
var isMarkdownKey = /markdown/i;
|
|
_.each(article, function(section, sectionName){
|
|
_.each(section, function(value, key){
|
|
if(isMarkdownKey.test(key) && _.isString(value)){
|
|
section[key] = marked(value);
|
|
}
|
|
});
|
|
});
|
|
return JSON.stringify(article, null, 4);
|
|
};
|
|
|
|
gulp.src('data/articles/**/*.toml.md')
|
|
.pipe(toml({to: transformArticle}))
|
|
.pipe(wrapper({
|
|
header: "define(['m', '_'], function (m, _ ) {\nreturn ",
|
|
footer: ';\n});\n'
|
|
}))
|
|
.pipe(rename(function(path){
|
|
path.basename = path.basename.replace(/\.toml$/i, '');
|
|
path.extname = '.js';
|
|
return path;
|
|
}))
|
|
.pipe(gulp.dest('./script/articles/'));
|
|
|
|
});
|
|
|
|
gulp.task('default', ['bower', 'sass', 'encrypt-results', 'compile-results', 'compile-articles']);
|
|
|
|
gulp.task('prod', ['default', 'template-prod']);
|
|
|
|
gulp.task('webserver', function(){
|
|
return gulp.src('.')
|
|
.pipe(webserver({
|
|
host: '0.0.0.0',
|
|
port: 2222,
|
|
livereload: false,
|
|
directoryListing: false,
|
|
}));
|
|
});
|
|
|
|
|
|
gulp.task('dev', ['default', 'webserver', 'template-dev', 'bower'], function(){
|
|
gulp.watch('./scss/*.scss', ['sass']);
|
|
gulp.watch('*.tmpl.html', ['template-dev']);
|
|
gulp.watch('./data/articles/**/*', ['compile-articles']);
|
|
return gulp.watch('./data/*.yaml', ['encrypt-results', 'compile-results']);
|
|
});
|