This repository has been archived by the owner on Apr 2, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add grunt, linting, enable in travis-ci and make pass
- Loading branch information
Showing
11 changed files
with
313 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"extends": "kartotherian", | ||
"rules": { | ||
"comma-dangle": [2,"never"], | ||
"one-var": [2,"always"], | ||
"no-param-reassign": [2,{"props":false}], | ||
"no-plusplus": [2,{"allowForLoopAfterthoughts": true}] | ||
}, | ||
"env": { | ||
"browser": true | ||
}, | ||
"globals": { | ||
"L": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "stylelint-config-wikimedia", | ||
"rules": { | ||
"declaration-no-important": null, | ||
"selector-max-id": null, | ||
"indentation": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- "4" | ||
- "8" | ||
before_script: | ||
- npm install grunt-cli -g |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-env node */ | ||
module.exports = function Gruntfile(grunt) { | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
grunt.loadNpmTasks('grunt-eslint'); | ||
grunt.loadNpmTasks('grunt-stylelint'); | ||
|
||
grunt.initConfig({ | ||
eslint: { | ||
code: { | ||
src: [ | ||
'**/*.js', | ||
'!node_modules/**', | ||
'!vendor/**', | ||
'!tests/externals/**', | ||
'!static/lib/**' | ||
] | ||
} | ||
}, | ||
// Lint – Styling | ||
stylelint: { | ||
options: { | ||
syntax: 'less' | ||
}, | ||
all: [ | ||
'static/**/*.css', | ||
'!static/lib/**' | ||
] | ||
} | ||
}); | ||
|
||
grunt.registerTask('lint', ['eslint', 'stylelint']); | ||
grunt.registerTask('test', 'lint'); | ||
grunt.registerTask('default', 'test'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "../.eslintrc.json", | ||
"env": { | ||
"node": true, | ||
"es6": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,38 @@ | ||
'use strict'; | ||
|
||
let Promise = require('bluebird'), | ||
pathLib = require('path'), | ||
express = require('express'), | ||
compression = require('compression'); | ||
|
||
module.exports.init = function(opts) { | ||
|
||
return Promise.try(function () { | ||
let router = express.Router(), | ||
handlers = opts.requestHandlers || []; | ||
|
||
handlers.unshift(require('./tiles'), require('./info')); | ||
return Promise.mapSeries(handlers, function (reqHandler) { | ||
return reqHandler(opts.core, router); | ||
}).return(router); | ||
|
||
}).then(function (router) { | ||
// Add before static to prevent disk IO on each tile request | ||
let app = opts.app, | ||
staticOpts = { | ||
setHeaders: function (res) { | ||
if (app.conf.cache) { | ||
res.header('Cache-Control', app.conf.cache); | ||
} | ||
if (res.req.originalUrl.endsWith('.pbf')) { | ||
res.header('Content-Encoding', 'gzip'); | ||
} | ||
} | ||
}; | ||
|
||
app.use('/', router); | ||
|
||
// Compression is nativelly handled by the tiles, so only statics need its | ||
app.use(compression()); | ||
app.use('/', express.static(pathLib.resolve(__dirname, '../static'), staticOpts)); | ||
app.use('/leaflet', express.static(pathLib.dirname(require.resolve('leaflet')), staticOpts)); | ||
|
||
opts.core.metrics.increment('init'); | ||
}); | ||
const Promise = require('bluebird'), | ||
pathLib = require('path'), | ||
express = require('express'), | ||
compression = require('compression'), | ||
tiles = require('./tiles'), | ||
info = require('./info'); | ||
|
||
module.exports.init = function init(opts) { | ||
return Promise.try(() => { | ||
const router = express.Router(), | ||
handlers = opts.requestHandlers || []; | ||
|
||
handlers.unshift(tiles, info); | ||
return Promise.mapSeries(handlers, reqHandler => reqHandler(opts.core, router)).return(router); | ||
}).then((router) => { | ||
// Add before static to prevent disk IO on each tile request | ||
const { app } = opts, | ||
staticOpts = { | ||
setHeaders(res) { | ||
if (app.conf.cache) { | ||
res.header('Cache-Control', app.conf.cache); | ||
} | ||
if (res.req.originalUrl.endsWith('.pbf')) { | ||
res.header('Content-Encoding', 'gzip'); | ||
} | ||
} | ||
}; | ||
|
||
app.use('/', router); | ||
|
||
// Compression is nativelly handled by the tiles, so only statics need its | ||
app.use(compression()); | ||
app.use('/', express.static(pathLib.resolve(__dirname, '../static'), staticOpts)); | ||
app.use('/leaflet', express.static(pathLib.dirname(require.resolve('leaflet')), staticOpts)); | ||
|
||
opts.core.metrics.increment('init'); | ||
}); | ||
}; |
Oops, something went wrong.