Skip to content

Commit

Permalink
Refactor to use modules + eslint + CI
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Jan 18, 2024
1 parent d4ba037 commit d896ee2
Show file tree
Hide file tree
Showing 106 changed files with 713 additions and 661 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# EditorConfig is awesome: https://EditorConfig.org

[*.{js,json,yml}]
charset = utf-8
end_of_line = crlf
indent_style = tabs
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.{yaml,yml}]
charset = utf-8
end_of_line = crlf
indent_style = spaces
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
15 changes: 15 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
env:
node: true
extends:
- eslint:recommended
- plugin:n/recommended
parserOptions:
ecmaVersion: 2022
sourceType: module
globals:
ee: readonly
rules:
n/no-extraneous-import:
- error
- allowModules:
- restify-errors
15 changes: 11 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ on: [push, pull_request]
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 17 # minimum req. vbrsion right now
- lts/*
- latest
steps:
- uses: actions/setup-node@v1
- uses: actions/setup-node@v4
with:
node-version: '16'
- uses: actions/checkout@v2
node-version: ${{ matrix.node-version }}
- uses: actions/checkout@v4
- run: npm install
- run: npm test
- run: npm run lint
- run: npm test
20 changes: 0 additions & 20 deletions jest.config.js

This file was deleted.

17 changes: 17 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"testEnvironment": "node",
"collectCoverage": true,
"coverageDirectory": "coverage",
"errorOnDeprecated": true,
"reporters": [
"default",
[
"./node_modules/jest-html-reporter",
{ "pageTitle": "Test Report for openeo-earthengine-driver" }
]
],
"transform": {},
"fakeTimers": {
"enableGlobally": true
}
}
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
"stac_version": "1.0.0",
"description": "An openEO driver for Google Earth Engine.",
"main": "src/server.js",
"type": "module",
"scripts": {
"dev": "nodemon src/server.js --trace-warnings",
"up": "npm run sync && pm2 start src/server.js",
"down": "pm2 stop src/server.js",
"sync": "node src/sync.js",
"adduser": "node src/adduser.js",
"test": "jest --env=node",
"debug": "node --nolazy --inspect src/server.js"
"test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js",
"debug": "node --nolazy --inspect src/server.js",
"lint": "eslint src/"
},
"author": "Matthias Mohr",
"license": "Apache-2.0",
Expand All @@ -24,6 +26,8 @@
"url": "https://github.com/Open-EO/openeo-earthengine-editor.git"
},
"devDependencies": {
"eslint": "^8.56.0",
"eslint-plugin-n": "^16.6.2",
"jest": "^29.7.0",
"jest-html-reporter": "^3.10.2",
"nodemon": "^3.0.2",
Expand All @@ -43,8 +47,8 @@
"proj4": "^2.10.0",
"restify": "^11.1.0"
},
"engines" : {
"node" : ">=17.0.0"
"engines": {
"node": ">=17.0.0"
},
"nodemonConfig": {
"watch": [
Expand Down
73 changes: 35 additions & 38 deletions src/adduser.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
const ServerContext = require("./servercontext");
const { createInterface } = require('node:readline/promises');
/*eslint n/no-process-exit: "off"*/
import ServerContext from "./utils/servercontext.js";
import { createInterface } from 'node:readline/promises';

async function run() {
const serverContext = new ServerContext();
const users = serverContext.users();
const serverContext = new ServerContext();
const users = serverContext.users();

const rl = createInterface({
input: process.stdin,
output: process.stdout
});
const stop = (code) => {
rl.close();
process.exit(code);
}

const username = await rl.question('Enter a username: ');
if (username && username.length < 4) {
console.error("Username must be at least 4 characters long.");
stop(1);
}
const exists = await users.exists(username);
if (exists) {
console.error("User with the given name already exists.");
stop(1);
}
const rl = createInterface({
input: process.stdin,
output: process.stdout
});
const stop = (code) => {
rl.close();
process.exit(code);
}

const password = await rl.question('Enter a password: ');
if (password && password.length < 4) {
console.error("Password must be at least 4 characters long.");
stop(1);
}
const username = await rl.question('Enter a username: ');
if (username && username.length < 4) {
console.error("Username must be at least 4 characters long.");
stop(1);
}
const exists = await users.exists(username);
if (exists) {
console.error("User with the given name already exists.");
stop(1);
}

try {
await users.register(username, password);
console.log('User created!');
stop(0);
} catch (err) {
console.error(err);
stop(1);
}
const password = await rl.question('Enter a password: ');
if (password && password.length < 4) {
console.error("Password must be at least 4 characters long.");
stop(1);
}

run();
try {
await users.register(username, password);
console.log('User created!');
stop(0);
} catch (err) {
console.error(err);
stop(1);
}
8 changes: 4 additions & 4 deletions src/api/capabilities.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Utils = require('../utils/utils');
const packageInfo = require('../../package.json');
import Utils from '../utils/utils.js';
const packageInfo = Utils.require('../../package.json');

module.exports = class CapabilitiesAPI {
export default class CapabilitiesAPI {

constructor(context) {
this.endpoints = [];
Expand Down Expand Up @@ -134,4 +134,4 @@ module.exports = class CapabilitiesAPI {
output: this.context.outputFormats
});
}
};
}
14 changes: 7 additions & 7 deletions src/api/collections.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const Utils = require('../utils/utils');
const Errors = require('../utils/errors');
import Utils from '../utils/utils.js';
import Errors from '../utils/errors.js';

module.exports = class Data {
export default class Data {

constructor(context) {
this.catalog = context.collections();

this.geeSourceCatalogLink = {
href: 'https://earthengine-stac.storage.googleapis.com/catalog/catalog.json',
href: 'https://earthengine-stac.storage.googleapis.com/catalog/catalog.json',
rel: 'alternate',
type: 'application/json',
title: 'Machine-readable Earth Engine Data Catalog'
Expand Down Expand Up @@ -65,7 +65,7 @@ module.exports = class Data {
]
});
}

async getCollectionById(req, res) {
const id = req.params['*'];
if (id.length === 0) {
Expand All @@ -92,7 +92,7 @@ module.exports = class Data {
if (req.params['*'] && !req.params.collection_id) {
id = req.params['*'].replace(/\/queryables$/, '');
}

const collection = this.catalog.getData(id);
if (collection === null) {
throw new Errors.CollectionNotFound();
Expand All @@ -108,4 +108,4 @@ module.exports = class Data {
});
}

};
}
18 changes: 9 additions & 9 deletions src/api/files.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const fse = require('fs-extra');
const path = require('path');
const Errors = require('../utils/errors');
const Utils = require('../utils/utils');
const HttpUtils = require('../utils/http');
import fse from 'fs-extra';
import path from 'path';
import Errors from '../utils/errors.js';
import Utils from '../utils/utils.js';
import HttpUtils from '../utils/http.js';

// ToDo files: This is a mock and only uploads to the driver workspace, but not into the actual
// Google cloud storage, which would be required to use it in processes. #11
module.exports = class FilesAPI {
export default class FilesAPI {

constructor(context) {
this.workspace = context.files();
Expand Down Expand Up @@ -61,10 +61,10 @@ module.exports = class FilesAPI {
throw new Errors.FilePathInvalid();
}
} catch (e) {
// File doesn't exist => not a problem for uploading; create missing folders and continue process chain.
// File doesn't exist => not a problem for uploading; create missing folders and continue process chain.
await fse.ensureDir(path.dirname(p));
}

let octetStream = 'application/octet-stream';
if (req.contentType() !== octetStream) {
throw new Errors.ContentTypeInvalid({types: octetStream});
Expand Down Expand Up @@ -137,4 +137,4 @@ module.exports = class FilesAPI {
});
}

};
}
Loading

0 comments on commit d896ee2

Please sign in to comment.