Skip to content

Commit 23b9845

Browse files
committed
upgrade to ESM modules
1 parent 3bde9b6 commit 23b9845

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+442
-441
lines changed

.eslintrc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
"mongo": true,
77
"es2021": true
88
},
9-
"extends": ["airbnb-base"],
9+
"extends": [
10+
"airbnb-base",
11+
"plugin:import/recommended"
12+
],
1013
"parserOptions": {
11-
"ecmaVersion": 2021,
12-
"impliedStrict": true
14+
"ecmaVersion": "latest",
15+
"impliedStrict": true,
16+
"sourceType": "module"
1317
},
1418
"rules": {
1519
"no-console": 0,
@@ -19,6 +23,7 @@
1923
{
2024
"devDependencies": ["test/*.test.js", "scripts/*.js"]
2125
}
22-
]
26+
],
27+
"import/extensions": ["always"]
2328
}
2429
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2017-2021 Jake Meyer
189+
Copyright 2017-2022 Jake Meyer
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

app.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
const conditional = require('koa-conditional-get');
2-
const etag = require('koa-etag');
3-
const cors = require('koa2-cors');
4-
const helmet = require('koa-helmet');
5-
const Koa = require('koa');
6-
const bodyParser = require('koa-bodyparser');
7-
const mongoose = require('mongoose');
8-
const { logger } = require('./middleware/logger');
9-
const { responseTime, errors } = require('./middleware');
10-
const routes = require('./routes');
1+
import conditional from 'koa-conditional-get';
2+
import etag from 'koa-etag';
3+
import cors from 'koa2-cors';
4+
import helmet from 'koa-helmet';
5+
import Koa from 'koa';
6+
import bodyParser from 'koa-bodyparser';
7+
import mongoose from 'mongoose';
8+
import { responseTime, errors, logger } from './middleware/index.js';
9+
import routes from './routes/index.js';
1110

1211
const app = new Koa();
1312

@@ -58,10 +57,7 @@ app.use(cors({
5857
// Set header with API response time
5958
app.use(responseTime);
6059

61-
// Request logging
62-
// app.use(requestLogger);
63-
6460
// Register routes
65-
app.use(routes());
61+
app.use(await routes());
6662

67-
module.exports = app;
63+
export default app;

jobs/capsules.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const got = require('got');
2-
const cheerio = require('cheerio');
3-
const { logger } = require('../middleware/logger');
1+
import got from 'got';
2+
import cheerio from 'cheerio';
3+
import { logger } from '../middleware/index.js';
44

55
const API = process.env.SPACEX_API;
66
const KEY = process.env.SPACEX_KEY;
@@ -11,7 +11,7 @@ const REDDIT_CAPSULES = 'https://old.reddit.com/r/spacex/wiki/capsules';
1111
* Update capsule landings/reuse count
1212
* @return {Promise<void>}
1313
*/
14-
module.exports = async () => {
14+
export default async () => {
1515
try {
1616
const capsules = await got.post(`${API}/capsules/query`, {
1717
json: {

jobs/cores.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const got = require('got');
2-
const cheerio = require('cheerio');
3-
const { logger } = require('../middleware/logger');
1+
import got from 'got';
2+
import cheerio from 'cheerio';
3+
import { logger } from '../middleware/index.js';
44

55
const REDDIT_CORES = 'https://old.reddit.com/r/spacex/wiki/cores';
66
const API = process.env.SPACEX_API;
@@ -11,7 +11,7 @@ const HEALTHCHECK = process.env.CORES_HEALTHCHECK;
1111
* Update cores
1212
* @return {Promise<void>}
1313
*/
14-
module.exports = async () => {
14+
export default async () => {
1515
try {
1616
const cores = await got.post(`${API}/cores/query`, {
1717
json: {

jobs/landpads.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const got = require('got');
2-
const { logger } = require('../middleware/logger');
1+
import got from 'got';
2+
import { logger } from '../middleware/index.js';
33

44
const API = process.env.SPACEX_API;
55
const KEY = process.env.SPACEX_KEY;
@@ -9,7 +9,7 @@ const HEALTHCHECK = process.env.LANDPADS_HEALTHCHECK;
99
* Update landpad attempts/successes
1010
* @return {Promise<void>}
1111
*/
12-
module.exports = async () => {
12+
export default async () => {
1313
try {
1414
const landpads = await got.post(`${API}/landpads/query`, {
1515
json: {

jobs/launch-library.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const got = require('got');
2-
const moment = require('moment-timezone');
3-
const { fail, success } = require('../lib/healthchecks');
4-
const { logger } = require('../middleware/logger');
1+
import got from 'got';
2+
import moment from 'moment-timezone';
3+
import { fail, success } from '../lib/healthchecks/index.js';
4+
import { logger } from '../middleware/index.js';
55

66
const {
77
SPACEX_KEY,
@@ -14,7 +14,7 @@ const LAUNCH_LIBRARY_API = 'https://ll.thespacedevs.com/2.1.0/launch/upcoming';
1414
* Attach Launch Library v2 launch id's to upcoming launches
1515
* @return {Promise<void>}
1616
*/
17-
module.exports = async () => {
17+
export default async () => {
1818
try {
1919
const log = {
2020
name: 'launch-library',

jobs/launches.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const _ = require('lodash');
2-
const got = require('got');
3-
const { logger } = require('../middleware/logger');
1+
import _ from 'lodash';
2+
import got from 'got';
3+
import { logger } from '../middleware/index.js';
44

55
const API = process.env.SPACEX_API;
66
const KEY = process.env.SPACEX_KEY;
@@ -10,7 +10,7 @@ const HEALTHCHECK = process.env.LAUNCHES_HEALTHCHECK;
1010
* Update launch arrays
1111
* @return {Promise<void>}
1212
*/
13-
module.exports = async () => {
13+
export default async () => {
1414
try {
1515
const launches = await got.post(`${API}/launches/query`, {
1616
json: {

jobs/launchpads.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const got = require('got');
2-
const { logger } = require('../middleware/logger');
1+
import got from 'got';
2+
import { logger } from '../middleware/index.js';
33

44
const API = process.env.SPACEX_API;
55
const KEY = process.env.SPACEX_KEY;
@@ -9,7 +9,7 @@ const HEALTHCHECK = process.env.LAUNCHPADS_HEALTHCHECK;
99
* Update launchpad attempts/successes
1010
* @return {Promise<void>}
1111
*/
12-
module.exports = async () => {
12+
export default async () => {
1313
try {
1414
const launchpads = await got.post(`${API}/launchpads/query`, {
1515
json: {

jobs/payloads.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const got = require('got');
2-
const { CookieJar } = require('tough-cookie');
3-
const { logger } = require('../middleware/logger');
1+
import got from 'got';
2+
import { CookieJar } from 'tough-cookie';
3+
import { logger } from '../middleware/index.js';
44

55
const API = process.env.SPACEX_API;
66
const KEY = process.env.SPACEX_KEY;
@@ -10,7 +10,7 @@ const HEALTHCHECK = process.env.PAYLOADS_HEALTHCHECK;
1010
* Update payload orbit params
1111
* @return {Promise<void>}
1212
*/
13-
module.exports = async () => {
13+
export default async () => {
1414
try {
1515
const cookieJar = new CookieJar();
1616
const [payloads] = await Promise.all([

jobs/roadster.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-secrets/no-secrets */
2-
const got = require('got');
3-
const moment = require('moment-timezone');
4-
const { logger } = require('../middleware/logger');
2+
import got from 'got';
3+
import moment from 'moment-timezone';
4+
import { logger } from '../middleware/index.js';
55

66
const API = process.env.SPACEX_API;
77
const KEY = process.env.SPACEX_KEY;
@@ -14,7 +14,7 @@ const HEALTHCHECK = process.env.ROADSTER_HEALTHCHECK;
1414
* See https://ssd-api.jpl.nasa.gov/doc/horizons.html for more information
1515
* @return {Promise<void>}
1616
*/
17-
module.exports = async () => {
17+
export default async () => {
1818
// Using date range so Horizons doesn't give us the default 10 day data
1919
const today = moment().format('YYYY-MMM-DD HH:mm:ss');
2020
const tomorrow = moment().add(1, 'day').format('YYYY-MMM-DD HH:mm:ss');

jobs/starlink.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const got = require('got');
2-
const { CookieJar } = require('tough-cookie');
3-
const Moment = require('moment-timezone');
4-
const MomentRange = require('moment-range');
5-
const { getSatelliteInfo } = require('tle.js');
6-
const { logger } = require('../middleware/logger');
1+
import got from 'got';
2+
import { CookieJar } from 'tough-cookie';
3+
import Moment from 'moment-timezone';
4+
import MomentRange from 'moment-range';
5+
import { getSatelliteInfo } from 'tle.js';
6+
import { logger } from '../middleware/index.js';
77

88
const API = process.env.SPACEX_API;
99
const KEY = process.env.SPACEX_KEY;
@@ -40,7 +40,7 @@ const starlinkVersion = (date, name) => {
4040
* Update Starlink orbits
4141
* @return {Promise<void>}
4242
*/
43-
module.exports = async () => {
43+
export default async () => {
4444
try {
4545
const cookieJar = new CookieJar();
4646

jobs/upcoming.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable no-continue */
22
/* eslint-disable no-restricted-syntax */
33

4-
const got = require('got');
5-
const cheerio = require('cheerio');
6-
const fuzz = require('fuzzball');
7-
const moment = require('moment-timezone');
8-
const { logger } = require('../middleware/logger');
4+
import got from 'got';
5+
import cheerio from 'cheerio';
6+
import * as fuzz from 'fuzzball';
7+
import moment from 'moment-timezone';
8+
import { logger } from '../middleware/index.js';
99

1010
const REDDIT_WIKI = 'https://old.reddit.com/r/spacex/wiki/launches/manifest';
1111
const API = process.env.SPACEX_API;
@@ -19,7 +19,7 @@ const HEALTHCHECK = process.env.UPCOMING_HEALTHCHECK;
1919
* id of the launch. It also corrects the flight number order based on the launch wiki order.
2020
* @return {Promise<void>}
2121
*/
22-
module.exports = async () => {
22+
export default async () => {
2323
try {
2424
const flightNumbers = [];
2525
const rawLaunches = await got.post(`${API}/launches/query`, {

jobs/webcast.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const got = require('got');
2-
const fuzz = require('fuzzball');
3-
const Parser = require('rss-parser');
4-
const { fail, success } = require('../lib/healthchecks');
5-
const { logger } = require('../middleware/logger');
1+
import got from 'got';
2+
import * as fuzz from 'fuzzball';
3+
import Parser from 'rss-parser';
4+
import { fail, success } from '../lib/healthchecks/index.js';
5+
import { logger } from '../middleware/index.js';
66

77
const YOUTUBE_PREFIX = 'https://youtu.be';
88
const CHANNEL_ID = 'UCtI0Hodo5o5dUb67FeUjDeA';
@@ -16,7 +16,7 @@ const {
1616
* Check for new SpaceX webcast links
1717
* @return {Promise<void>}
1818
*/
19-
module.exports = async () => {
19+
export default async () => {
2020
try {
2121
let updated = false;
2222
let match = false;

jobs/worker.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
const { CronJob } = require('cron');
2-
const { logger } = require('../middleware/logger');
3-
const launches = require('./launches');
4-
const payloads = require('./payloads');
5-
const landpads = require('./landpads');
6-
const launchpads = require('./launchpads');
7-
const capsules = require('./capsules');
8-
const cores = require('./cores');
9-
const roadster = require('./roadster');
10-
const upcoming = require('./upcoming');
11-
const starlink = require('./starlink');
12-
const webcast = require('./webcast');
13-
const launchLibrary = require('./launch-library');
1+
import { CronJob } from 'cron';
2+
import { logger } from '../middleware/index.js';
3+
import launches from './launches.js';
4+
import payloads from './payloads.js';
5+
import landpads from './landpads.js';
6+
import launchpads from './launchpads.js';
7+
import capsules from './capsules.js';
8+
import cores from './cores.js';
9+
import roadster from './roadster.js';
10+
import upcoming from './upcoming.js';
11+
import starlink from './starlink.js';
12+
import webcast from './webcast.js';
13+
import launchLibrary from './launch-library.js';
1414

1515
// Every 10 minutes
1616
const launchesJob = new CronJob('*/10 * * * *', launches);

lib/constants.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
/**
22
* Healthchecks.io API prefix
33
*/
4-
module.exports.HEALTHCHECK_PREFIX = 'https://hc-ping.com';
4+
export const HEALTHCHECK_PREFIX = 'https://hc-ping.com';
5+
6+
/**
7+
* Default Port
8+
*/
9+
export const DEFAULT_PORT = 6673;

lib/healthchecks/fail.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* Imports
33
*/
4-
const got = require('got');
5-
const { HEALTHCHECK_PREFIX } = require('../constants');
4+
import got from 'got';
5+
import { HEALTHCHECK_PREFIX } from '../constants.js';
66

77
/**
88
* Send fail signal to healthcheck.io
@@ -11,7 +11,7 @@ const { HEALTHCHECK_PREFIX } = require('../constants');
1111
* @param {String|Object} [msg] Message to pass to healthcheck
1212
* @returns {Boolean} True if successful
1313
*/
14-
module.exports = async (id = null, msg = {}) => {
14+
export default async (id = null, msg = {}) => {
1515
if (id) {
1616
const response = await got.post({
1717
prefixUrl: HEALTHCHECK_PREFIX,

lib/healthchecks/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/**
2-
* Export healthcheck.io funcs
3-
*/
4-
module.exports.fail = require('./fail');
5-
module.exports.start = require('./start');
6-
module.exports.success = require('./success');
1+
export { default as fail } from './fail.js';
2+
export { default as start } from './start.js';
3+
export { default as success } from './success.js';

lib/healthchecks/start.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* Imports
33
*/
4-
const got = require('got');
5-
const { HEALTHCHECK_PREFIX } = require('../constants');
4+
import got from 'got';
5+
import { HEALTHCHECK_PREFIX } from '../constants.js';
66

77
/**
88
* Send start signal to healthcheck.io
@@ -11,7 +11,7 @@ const { HEALTHCHECK_PREFIX } = require('../constants');
1111
* @param {String|Object} [msg] Message to pass to healthcheck
1212
* @returns {Boolean} True if successful
1313
*/
14-
module.exports = async (id = null, msg = {}) => {
14+
export default async (id = null, msg = {}) => {
1515
if (id) {
1616
const response = await got.post({
1717
prefixUrl: HEALTHCHECK_PREFIX,

0 commit comments

Comments
 (0)