Browse Source

Merge pull request #63 from butlerx/bugfix/linting

fix linting!
pull/67/head
Cormac Smartt 4 years ago
committed by GitHub
parent
commit
6aead782d0
4 changed files with 49 additions and 43 deletions
  1. +4
    -5
      bin/check-event-json
  2. +11
    -10
      bin/generate.js
  3. +25
    -25
      gulpfile.js
  4. +9
    -3
      package.json

+ 4
- 5
bin/check-event-json View File

@@ -1,8 +1,8 @@
#!/usr/bin/env node
var fs = require('fs');
var file = process.argv[2];
var glob = require("glob")
'use strict';
const fs = require('fs');
const file = process.argv[2];
const glob = require('glob');

if(file !== undefined && file !== null) {
checkJson(file);
@@ -22,7 +22,6 @@ if(file !== undefined && file !== null) {
function checkJson (filename) {
try {
JSON.parse(fs.readFileSync(filename, 'utf8'));
console.log(filename + ' looks good');
} catch (err) {
console.error(filename, err);
process.exit(1);


+ 11
- 10
bin/generate.js View File

@@ -1,23 +1,24 @@
'use strict';
const Handlebars = require('handlebars');
const fs = require('fs');
const path = require('path');
const config = require(__dirname + '/../config.json');
const template = fs.readFileSync(__dirname + '/../template.handlebars', "utf-8");
const template = fs.readFileSync(__dirname + '/../template.handlebars', 'utf-8');

let pages = path.join(__dirname, '..', 'pages');
if(config.folder) {
pages = path.join(__dirname, '..', config.folder);
}

let outputDir = path.join(__dirname, '..', 'dist')
let outputDir = path.join(__dirname, '..', 'dist');
if (config.output) {
outputDir = path.join(__dirname, '..', config.output);
}

function render (template, page, url) {
let output = (Handlebars.compile(template))(page);
const output = (Handlebars.compile(template))(page);
if (!fs.existsSync(outputDir)) { fs.mkdirSync(outputDir); }
let dir = outputDir
let dir = outputDir;
if (url) {
dir = path.join(dir, url);
if (!fs.existsSync(dir)){
@@ -28,14 +29,14 @@ function render (template, page, url) {
}

Handlebars.registerHelper('splitTitle', function(title) {
let middle = Math.floor(title.length / 2);
let s1 = title.substr(0, middle);
let s2 = title.substr(middle);
return s1 + "</span>" + s2;
const middle = Math.floor(title.length / 2);
const s1 = title.substr(0, middle);
const s2 = title.substr(middle);
return s1 + '</span>' + s2;
});

for (let page of config.pages) {
let json = require(path.join(pages, page.file));
for (const page of config.pages) {
const json = require(path.join(pages, page.file));
json.pages = config.pages;
json.title = config.title;
render(template, json, page.url);


+ 25
- 25
gulpfile.js View File

@@ -7,34 +7,34 @@ const rename = require('gulp-rename');
const connect = require('gulp-connect');
const jsonSchema = require('gulp-json-schema');
const babel = require('gulp-babel');
const shell = require('gulp-shell')
const shell = require('gulp-shell');
const htmlmin = require('gulp-htmlmin');

gulp.task('dev', ['webserver'], function () {
gulp.watch(['./css/*.scss', './js/*.js', './**/*.handlebars', './**/*.json'], ['scss', 'compress', 'generate', 'html']);
gulp.watch(['./css/*.scss', './js/*.js', './**/*.handlebars', './**/*.json'], ['scss', 'compress', 'generate', 'html']);
});

gulp.task('compress', function() {
gulp.src(['./node_modules/jquery/dist/jquery.js', './js/*.js', './node_modules/materialize-css/dist/js/materialize.js'])
.pipe(concat('main.js'))
.pipe(babel())
.pipe(minify({
ext:{
min:'.min.js'
},
exclude: ['tasks'],
noSource: true,
ignoreFiles: ['.combo.js', '*.min.js']
}))
.pipe(gulp.dest('dist/js'));
return gulp.src(['./node_modules/jquery/dist/jquery.js', './js/*.js', './node_modules/materialize-css/dist/js/materialize.js'])
.pipe(concat('main.js'))
.pipe(babel())
.pipe(minify({
ext:{
min:'.min.js'
},
exclude: ['tasks'],
noSource: true,
ignoreFiles: ['.combo.js', '*.min.js']
}))
.pipe(gulp.dest('dist/js'));
});

gulp.task('scss', function() {
return gulp.src('css/main.scss')
.pipe(sass())
.pipe(cleanCSS({compatibility: 'ie8', processImport: false}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist/css'));
.pipe(sass())
.pipe(cleanCSS({compatibility: 'ie8', processImport: false}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist/css'));
});

gulp.task('webserver',['default'], function() {
@@ -49,23 +49,23 @@ gulp.task('webserver',['default'], function() {

gulp.task('fonts', function() {
return gulp.src('./node_modules/materialize-css/fonts/**')
.pipe(gulp.dest('dist/fonts'));
.pipe(gulp.dest('dist/fonts'));
});

gulp.task('html', function() {
gulp.src('./**/*.html')
.pipe(connect.reload());
return gulp.src('./**/*.html')
.pipe(connect.reload());
});

gulp.task('validate', function() {
return gulp.src(['./events/*.json'])
.pipe(jsonSchema('schema.json'));
.pipe(jsonSchema('schema.json'));
});

gulp.task('generate', ['validate'], shell.task("node bin/generate.js"));
gulp.task('generate', ['validate'], shell.task('node bin/generate.js'));

gulp.task('default', ['generate', 'compress', 'scss', 'fonts'], function () {
return gulp.src('dist/**/*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('dist'));
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('dist'));
});

+ 9
- 3
package.json View File

@@ -4,10 +4,11 @@
"description": "This repository contains the Techweek website",
"main": "gulpfile.js",
"scripts": {
"test": "eslint js/main,js && bin/check-event-json && gulp",
"test": "eslint js/* bin/* && bin/check-event-json && gulp",
"dev": "gulp dev",
"postinstall": "npm rebuild node-sass && gulp",
"gulp": "gulp"
"postinstall": "gulp",
"lint": "eslint",
"build": "gulp"
},
"repository": {
"type": "git",
@@ -46,10 +47,15 @@
"env": {
"browser": true,
"es6": true,
"node": true,
"jquery": true
},
"globals": {
"start": true
},
"extends": "eslint:recommended",
"rules": {
"no-console": 0,
"indent": [
"error",
2


Loading…
Cancel
Save