From 335a94656be7ec1f0dabc95364cb49e35019accf Mon Sep 17 00:00:00 2001 From: Marc Harter Date: Tue, 7 Jul 2020 14:43:35 -0500 Subject: [PATCH] Fix broken windows Includes: Update dependencies Switch to GitHub Workflow PR: https://github.com/wavded/ogre/pull/85 --- .eslintrc | 1 + .github/workflows/main.yml | 18 ++++++++++++++++++ .prettierrc | 4 +--- index.js | 16 ++++++++-------- package.json | 9 +++++---- readme.md | 4 ++-- test/api-test.js | 32 ++++++++++++++++---------------- 7 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/main.yml diff --git a/.eslintrc b/.eslintrc index b28f99f..754d119 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,4 +1,5 @@ { + "root": true, "extends": ["eslint:recommended", "plugin:prettier/recommended"], "env": { "node": true, diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..3be8229 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,18 @@ +name: build +on: push +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + node: ['10', '12'] + name: Node v${{ matrix.node }} + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + - run: sudo apt-get install gdal-bin + - run: yarn install + - run: yarn lint + - run: yarn test diff --git a/.prettierrc b/.prettierrc index 3b6b0d8..653c512 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,7 +1,5 @@ { "semi": false, "singleQuote": true, - "trailingComma": "es5", - "bracketSpacing": false, - "printWidth": 80 + "bracketSpacing": false } diff --git a/index.js b/index.js index 7a4b8cb..e236d1d 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ function enableCors(req, res, next) { } function optionsHandler(methods) { - return function(req, res) { + return function (req, res) { res.header('Allow', methods) res.send(methods) } @@ -34,7 +34,7 @@ function safelyParseJson(json) { function noop() {} -exports.createServer = function(opts) { +exports.createServer = function (opts) { if (!opts) opts = {} let app = express() @@ -45,14 +45,14 @@ exports.createServer = function(opts) { app.options('/convertJson', enableCors, optionsHandler('POST')) app.use(express.static(join(__dirname, '/public'))) - app.get('/', function(req, res) { + app.get('/', function (req, res) { res.render('home') }) app.use(urlencoded({extended: false, limit: 3000000})) // 3mb app.use(multiparty({maxFilesSize: 100000000})) // 100mb - app.post('/convert', enableCors, function(req, res, next) { + app.post('/convert', enableCors, function (req, res, next) { if (!req.files.upload || !req.files.upload.name) { res.status(400).json({error: true, msg: 'No file provided'}) return @@ -87,7 +87,7 @@ exports.createServer = function(opts) { res.attachment() } - ogr.exec(function(er, data) { + ogr.exec(function (er, data) { fs.unlink(req.files.upload.path, noop) if (isOgreFailureError(er)) { @@ -105,7 +105,7 @@ exports.createServer = function(opts) { }) }) - app.post('/convertJson', enableCors, function(req, res, next) { + app.post('/convertJson', enableCors, function (req, res, next) { if (!req.body.jsonUrl && !req.body.json) return res.status(400).json({error: true, msg: 'No json provided'}) @@ -136,7 +136,7 @@ exports.createServer = function(opts) { let format = req.body.format || 'shp' - ogr.format(format).exec(function(er, buf) { + ogr.format(format).exec(function (er, buf) { if (isOgreFailureError(er)) return res .status(400) @@ -152,7 +152,7 @@ exports.createServer = function(opts) { }) /* eslint no-unused-vars: [0, { "args": "none" }] */ - app.use(function(er, req, res, next) { + app.use(function (er, req, res, next) { console.error(er.stack) res.header('Content-Type', 'application/json') res.status(500).json({error: true, msg: er.message}) diff --git a/package.json b/package.json index 4f6294c..c8756a0 100644 --- a/package.json +++ b/package.json @@ -28,15 +28,16 @@ "connect-multiparty": "^2.0.0", "express": "^4.10.2", "ogr2ogr": "^2.0.0", - "pug": "^2.0.0-rc.3" + "pug": "^3.0.0" }, "devDependencies": { - "eslint": "^6.8.0", + "eslint": "^7.4.0", "eslint-config-prettier": "^6.10.0", "eslint-plugin-prettier": "^3.1.2", - "prettier": "^1.19.1", + "nyc": "^15.1.0", + "prettier": "^2.0.5", "supertest": "^4.0.2", - "tape": "^4.8.0" + "tape": "^5.0.1" }, "engines": { "node": ">=10" diff --git a/readme.md b/readme.md index ecd6e00..c096031 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -[![Build Status](https://jenkins.adc4gis.com/buildStatus/icon?job=ogre)](https://jenkins.adc4gis.com/job/ogre/) [![NPM](https://img.shields.io/npm/v/ogre.svg)](https://npmjs.com/package/ogre) ![NPM Downloads](https://img.shields.io/npm/dt/ogre.svg) +![Build Status](https://github.com/wavded/ogre/workflows/build/badge.svg?branch=master) [![NPM](https://img.shields.io/npm/v/ogre.svg)](https://npmjs.com/package/ogre) ![NPM Downloads](https://img.shields.io/npm/dt/ogre.svg) The instructions below are only if you are interested in running the project locally. For help on how to use the web service, visit the [Ogre homepage](http://ogre.adc4gis.com). Ogre makes use of the [ogr2ogr](https://github.com/wavded/ogr2ogr) module. @@ -44,7 +44,7 @@ Options: (The MIT License) -Copyright (c) 2016 Marc Harter +Copyright (c) 2020 Marc Harter Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/test/api-test.js b/test/api-test.js index 3c3471b..8b7426d 100644 --- a/test/api-test.js +++ b/test/api-test.js @@ -4,7 +4,7 @@ const request = require('supertest') const join = require('path').join let server -test('create server', function(t) { +test('create server', function (t) { let app = ogre.createServer() t.ok(app.request, 'is express') server = app.listen(9876) @@ -12,13 +12,13 @@ test('create server', function(t) { t.end() }) -test('convert', function(t) { +test('convert', function (t) { t.plan(7) request(server) .post('/convert') .attach('upload', join(__dirname, '/samples/sample.shp.zip')) - .end(function(er, res) { + .end(function (er, res) { if (er) throw er let data = res.body @@ -31,7 +31,7 @@ test('convert', function(t) { .field('targetSrs', 'EPSG:3857') .attach('upload', join(__dirname, '/samples/sample.shp.zip')) .expect('Content-Type', 'application/json; charset=utf-8') - .end(function(er, res) { + .end(function (er, res) { t.notOk(er, 'no error', {error: er}) if (res.body.crs) // testable on gdal 0.10.x or greater @@ -44,7 +44,7 @@ test('convert', function(t) { .field('forcePlainText', '') .attach('upload', join(__dirname, '/samples/sample.shp.zip')) .expect('Content-Type', 'text/plain; charset=utf-8') - .end(function(er) { + .end(function (er) { t.notOk(er, 'no error', {error: er}) }) @@ -56,7 +56,7 @@ test('convert', function(t) { .expect('Allow', 'POST') .expect('Content-Type', 'text/html; charset=utf-8') .expect('POST') - .end(function(er, res) { + .end(function (er, res) { if (er) throw er t.ok(res, 'responded') }) @@ -65,7 +65,7 @@ test('convert', function(t) { .post('/convert') .expect('Content-Type', 'application/json; charset=utf-8') .expect(400, {error: true, msg: 'No file provided'}) - .end(function(er, res) { + .end(function (er, res) { if (er) throw er t.ok(res, 'bad request when no file uploaded') }) @@ -75,13 +75,13 @@ test('convert', function(t) { .attach('upload', join(__dirname, '/samples/sample.bad')) .expect('Content-Type', 'application/json; charset=utf-8') .expect(400) - .end(function(er, res) { + .end(function (er, res) { if (er) throw er t.ok(res.body.errors.length > 0, 'bad request on failure') }) }) -test('convertJson', function(t) { +test('convertJson', function (t) { t.plan(5) request(server) .post('/convertJson') @@ -90,7 +90,7 @@ test('convertJson', function(t) { jsonUrl: 'https://gist.github.com/wavded/7376428/raw/6dd3ad3de8157956b40f1cf09633e78bbdb1af18/test-single.geojson', }) - .end(function(er, res) { + .end(function (er, res) { if (er) throw er let buf = res.text @@ -105,7 +105,7 @@ test('convertJson', function(t) { .expect('Allow', 'POST') .expect('Content-Type', 'text/html; charset=utf-8') .expect('POST') - .end(function(er, res) { + .end(function (er, res) { if (er) throw er t.ok(res, 'responded') }) @@ -114,7 +114,7 @@ test('convertJson', function(t) { .post('/convertJson') .expect('Content-Type', 'application/json; charset=utf-8') .expect(400, {error: true, msg: 'No json provided'}) - .end(function(er, res) { + .end(function (er, res) { if (er) throw er t.ok(res, 'bad request when no json sent') }) @@ -125,7 +125,7 @@ test('convertJson', function(t) { .send({json: '{'}) .expect('Content-Type', 'application/json; charset=utf-8') .expect(400, {error: true, msg: 'Invalid json provided'}) - .end(function(er, res) { + .end(function (er, res) { if (er) throw er t.ok(res, 'bad request on invalid json') }) @@ -136,14 +136,14 @@ test('convertJson', function(t) { .send({json: '{ "invalid": "geojson" }'}) .expect('Content-Type', 'application/json; charset=utf-8') .expect(400) - .end(function(er, res) { + .end(function (er, res) { if (er) throw er t.ok(res.body.errors.length > 0, 'bad request on failure') }) }) -test('close server', function(t) { - server.close(function() { +test('close server', function (t) { + server.close(function () { t.end() }) })