diff --git a/.nvmrc b/.nvmrc index 9a03714..e81924d 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -10 \ No newline at end of file +12.3.1 \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 1284a15..57fc95c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,17 +1,17 @@ /* eslint-disable no-console */ -const { +import { access, - constants: { X_OK, R_OK }, + constants as fsConstants, createReadStream, readFile, unlink, -} = require('fs'); -const { createHash } = require('crypto'); -const { parse } = require('url'); -const { join } = require('path'); -const { spawn } = require('child_process'); -const glob = require('glob'); +} from 'fs'; +import { createHash } from 'crypto'; +import { parse } from 'url'; +import { join } from 'path'; +import { spawn } from 'child_process'; +import glob from 'glob'; const env = process.env.NODE_ENV || 'development'; const HOME = env === 'development' ? process.env.HOME : '/home/hosting-user'; @@ -41,6 +41,7 @@ const executableArgs = [ `--ffmpeg-location=${ffmpegPath}`, ]; +const { X_OK, R_OK } = fsConstants; const allowedProtocols = ['http:', 'https:']; const forbiddenHosts = ['localhost', '127.0.0.1', '0.0.0.0']; const destPath = '/tmp/'; @@ -53,7 +54,7 @@ function isFileExecutable(path) { }); } -function isFileReadable(path) { +export function isFileReadable(path) { return new Promise(resolve => { access(path, R_OK, err => err @@ -124,7 +125,7 @@ function makeCleanup(event, output) { }; } -async function spawnYouTubeDL(url, req) { +export async function spawnYouTubeDL(url, req) { let aborted; if (req) { req.on('close', () => { @@ -224,8 +225,3 @@ async function spawnYouTubeDL(url, req) { throw new Error('Could not read audio extract file.'); } - -module.exports = { - spawnYouTubeDL, - isFileReadable, -}; diff --git a/package-lock.json b/package-lock.json index f419aef..5adff90 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1280,9 +1280,9 @@ } }, "combined-stream": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz", - "integrity": "sha512-brWl9y6vOB1xYPZcpZde3N9zDByXTosAeMDo4p1wzo6UMOX4vumB+TP1RZ76sfE6Md68Q0NJSrE/gbezd4Ul+w==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", "dev": true, "requires": { "delayed-stream": "~1.0.0" @@ -2919,9 +2919,9 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "fstream": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz", - "integrity": "sha1-XB+x8RdHcRTwYyoOtLcbPLD9MXE=", + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.12.tgz", + "integrity": "sha512-WvJ193OHa0GHPEL+AycEJgxvBEwyfRkN1vhjca23OaPVMCaLCXTd5qAu82AjTcgP1UJmytkOKb63Ypde7raDIg==", "dev": true, "requires": { "graceful-fs": "^4.1.2", @@ -4140,30 +4140,12 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" }, - "lodash.assign": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz", - "integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc=", - "dev": true - }, - "lodash.clonedeep": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", - "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=", - "dev": true - }, "lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", "integrity": "sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=", "dev": true }, - "lodash.mergewith": { - "version": "4.6.1", - "resolved": "https://registry.npmjs.org/lodash.mergewith/-/lodash.mergewith-4.6.1.tgz", - "integrity": "sha512-eWw5r+PYICtEBgrBE5hhlT6aAa75f411bgDz/ZL2KZqYV03USvucsxcHUIlGTDTECs1eunpI7HOV7U+WLDvNdQ==", - "dev": true - }, "lodash.tail": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/lodash.tail/-/lodash.tail-4.1.1.tgz", @@ -4590,9 +4572,9 @@ "dev": true }, "nan": { - "version": "2.13.2", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.13.2.tgz", - "integrity": "sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", + "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==", "dev": true }, "nanomatch": { @@ -4742,9 +4724,9 @@ } }, "node-sass": { - "version": "4.11.0", - "resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.11.0.tgz", - "integrity": "sha512-bHUdHTphgQJZaF1LASx0kAviPH7sGlcyNhWade4eVIpFp6tsn7SV8xNMTbsQFpEV9VXpnwTTnNYlfsZXgGgmkA==", + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.12.0.tgz", + "integrity": "sha512-A1Iv4oN+Iel6EPv77/HddXErL2a+gZ4uBeZUy+a8O35CFYTXhgA8MgLCWBtwpGZdCvTvQ9d+bQxX/QC36GDPpQ==", "dev": true, "requires": { "async-foreach": "^0.1.3", @@ -4754,12 +4736,10 @@ "get-stdin": "^4.0.1", "glob": "^7.0.3", "in-publish": "^2.0.0", - "lodash.assign": "^4.2.0", - "lodash.clonedeep": "^4.3.2", - "lodash.mergewith": "^4.6.0", + "lodash": "^4.17.11", "meow": "^3.7.0", "mkdirp": "^0.5.1", - "nan": "^2.10.0", + "nan": "^2.13.2", "node-gyp": "^3.8.0", "npmlog": "^4.0.0", "request": "^2.88.0", @@ -6346,9 +6326,9 @@ "dev": true }, "resolve": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz", - "integrity": "sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==", + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.0.tgz", + "integrity": "sha512-WL2pBDjqT6pGUNSUzMw00o4T7If+z4H2x3Gz893WoUQ5KW8Vr9txp00ykiP16VBaZF5+j/OcXJHZ9+PCvdiDKw==", "dev": true, "requires": { "path-parse": "^1.0.6" @@ -7058,9 +7038,9 @@ } }, "spdx-license-ids": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.3.tgz", - "integrity": "sha512-uBIcIl3Ih6Phe3XHK1NqboJLdGfwr1UN3k6wSD1dZpmPsIkb8AGNbZYJ1fOBk834+Gxy8rpfDxrS6XLEMZMY2g==", + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.4.tgz", + "integrity": "sha512-7j8LYJLeY/Yb6ACbQ7F76qy5jHkp0U6jgBfJsk97bwWlVUnUWsAgpyaCvo17h0/RQGnQ036tVDomiwoI4pDkQA==", "dev": true }, "split": { @@ -7452,13 +7432,13 @@ "dev": true }, "tar": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/tar/-/tar-2.2.1.tgz", - "integrity": "sha1-jk0qJWwOIYXGsYrWlK7JaLg8sdE=", + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/tar/-/tar-2.2.2.tgz", + "integrity": "sha512-FCEhQ/4rE1zYv9rYXJw/msRqsnmlje5jHP6huWeBZ704jUTy02c5AZyWujpMR1ax6mVw9NyJMfuK2CMDWVIfgA==", "dev": true, "requires": { "block-stream": "*", - "fstream": "^1.0.2", + "fstream": "^1.0.12", "inherits": "2" } }, diff --git a/package.json b/package.json index 10bcc4b..4ac7b22 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "postinstall": "[ -z \"$VHOST\" ] && exit 0; npm run build:prod", "deploy": "ssh $SOUNDSLICE_DEPLOY deploy default.git" }, + "type": "module", "author": "Timothée 'Tim' Pillard (https://twitter.com/tpillard)", "license": "AGPL-3.0-only", "repository": { @@ -68,7 +69,7 @@ "eslint": "^5.16.0", "file-loader": "^3.0.1", "mini-css-extract-plugin": "^0.5.0", - "node-sass": "^4.11.0", + "node-sass": "^4.12.0", "nodemon": "^1.18.10", "normalize.css": "^8.0.0", "optimize-css-assets-webpack-plugin": "^5.0.1", diff --git a/server/api/deleteSlice.js b/server/api/deleteSlice.js index 8f795fb..58ff0ee 100644 --- a/server/api/deleteSlice.js +++ b/server/api/deleteSlice.js @@ -1,8 +1,8 @@ -const { getClient, query } = require('../db'); -const { isFileReadable } = require('../../lib'); -const { unlinkAsync } = require('../utils'); +import { getClient, query } from '../db/index.js'; +import { isFileReadable } from '../../lib/index.js'; +import { unlinkAsync } from '../utils.js'; -async function deleteSlice(req, res) { +export default async function deleteSlice(req, res) { const id = req.params.id; if (!id) { @@ -92,5 +92,3 @@ async function deleteSlice(req, res) { res.writeHead(204); res.end(); } - -module.exports = deleteSlice; diff --git a/server/api/getSlice.js b/server/api/getSlice.js index 68bce43..6e272c9 100644 --- a/server/api/getSlice.js +++ b/server/api/getSlice.js @@ -1,10 +1,10 @@ -const { createReadStream } = require('fs'); -const { encode } = require('punycode'); +import { createReadStream } from 'fs'; +import { encode } from 'punycode'; -const { query } = require('../db'); -const { isFileReadable } = require('../../lib'); +import { query } from '../db/index.js'; +import { isFileReadable } from '../../lib/index.js'; -async function getSlice(req, res) { +export default async function getSlice(req, res) { const id = req.params.id; if (!id) { @@ -65,5 +65,3 @@ async function getSlice(req, res) { console.info('Streaming slice back to client', name); fileStream.pipe(res); } - -module.exports = getSlice; diff --git a/server/api/headSlice.js b/server/api/headSlice.js index ce11bd7..0516349 100644 --- a/server/api/headSlice.js +++ b/server/api/headSlice.js @@ -1,7 +1,7 @@ -const { query } = require('../db'); -const { isFileReadable } = require('../../lib'); +import { query } from '../db/index.js'; +import { isFileReadable } from '../../lib/index.js'; -async function headSlice(req, res) { +export default async function headSlice(req, res) { const id = req.params.id; if (!id) { @@ -57,5 +57,3 @@ async function headSlice(req, res) { res.writeHead(204, headers); res.end(); } - -module.exports = headSlice; diff --git a/server/api/index.js b/server/api/index.js index 69a1b8f..bb772da 100644 --- a/server/api/index.js +++ b/server/api/index.js @@ -1,7 +1,5 @@ -module.exports = { - getSlice: require('./getSlice'), - headSlice: require('./headSlice'), - deleteSlice: require('./deleteSlice'), - shareSlice: require('./shareSlice'), - link: require('./link'), -}; +export { default as getSlice } from './getSlice.js'; +export { default as headSlice } from './headSlice.js'; +export { default as deleteSlice } from './deleteSlice.js'; +export { default as shareSlice } from './shareSlice.js'; +export { default as link } from './link.js'; diff --git a/server/api/link.js b/server/api/link.js index 70f1c39..903d374 100644 --- a/server/api/link.js +++ b/server/api/link.js @@ -1,7 +1,7 @@ -const { encode } = require('punycode'); -const { spawnYouTubeDL } = require('../../lib'); +import { encode } from 'punycode'; +import { spawnYouTubeDL } from '../../lib/index.js'; -async function link(req, res) { +export default async function link(req, res) { if (!req.body) return res.sendStatus(400); const queue = req.app.locals.queue; @@ -25,5 +25,3 @@ async function link(req, res) { res.sendStatus(500); } } - -module.exports = link; diff --git a/server/api/shareSlice.js b/server/api/shareSlice.js index dc518cd..3ce6efa 100644 --- a/server/api/shareSlice.js +++ b/server/api/shareSlice.js @@ -1,14 +1,14 @@ -const path = require('path'); -const { createHash } = require('crypto'); -const get = require('lodash/get'); -const multiparty = require('multiparty'); +import path from 'path'; +import { createHash } from 'crypto'; +import { get } from 'lodash'; +import multiparty from 'multiparty'; -const { renameAsync } = require('../utils'); -const { getClient } = require('../db'); +import { renameAsync } from '../utils.js'; +import { getClient } from '../db/index.js'; const env = process.env.NODE_ENV || 'development'; -async function shareSlice(req, res) { +export default async function shareSlice(req, res) { const finalDir = res.app.locals.config.uploads.path || (env === 'development' ? '/tmp' : '/home/hosting-user/uploads'); @@ -99,5 +99,3 @@ async function shareSlice(req, res) { return; } - -module.exports = shareSlice; diff --git a/server/assetPath.js b/server/assetPath.js index d9e72c8..cf2c446 100644 --- a/server/assetPath.js +++ b/server/assetPath.js @@ -1,11 +1,11 @@ -const fs = require('fs'); -const url = require('url'); -const path = require('path'); +import fs from 'fs'; +import url from 'url'; +import path from 'path'; -const assetsManifestPath = path.join(__dirname, '..', 'dist/assets.json'); -const assets = JSON.parse(fs.readFileSync(assetsManifestPath, 'utf8')); +export default function makeAssetPath(base, publicDir) { + const assetsManifestPath = path.join(__dirname, '..', 'dist/assets.json'); + const assets = JSON.parse(fs.readFileSync(assetsManifestPath, 'utf8')); -function makeAssetPath(base, publicDir) { return function assetPath(asset, absolute = true) { const pathname = assets[asset] || asset; if (!absolute) { @@ -15,5 +15,3 @@ function makeAssetPath(base, publicDir) { return url.resolve(base, path.join(publicDir, pathname)); }; } - -module.exports = makeAssetPath; diff --git a/server/db/index.js b/server/db/index.js index e58b48c..830b8f1 100644 --- a/server/db/index.js +++ b/server/db/index.js @@ -1,6 +1,6 @@ /* eslint-disable no-console */ -const { Pool } = require('pg'); +import pg from 'pg'; // FIXME: configuration file const config = { @@ -11,9 +11,9 @@ const config = { database: 'soundslice', }; -const pool = new Pool(config); +const pool = new pg.Pool(config); -async function query(text, params) { +export async function query(text, params) { const start = Date.now(); const res = await pool.query(text, params); const duration = Date.now() - start; @@ -21,11 +21,6 @@ async function query(text, params) { return res; } -function getClient() { +export function getClient() { return pool.connect(); } - -module.exports = { - query, - getClient, -}; diff --git a/server/index.js b/server/index.js index 03b7aba..31bd145 100644 --- a/server/index.js +++ b/server/index.js @@ -1,23 +1,23 @@ /* Copyright (C) 2019 Timothée 'tim' Pillard (AGPL-3.0-only) */ /* eslint-disable no-console */ -const url = require('url'); -const path = require('path'); -const fs = require('fs'); - -const yaml = require('js-yaml'); -const express = require('express'); -const favicon = require('serve-favicon'); -const morgan = require('morgan'); -const bodyParser = require('body-parser'); -const serveStatic = require('serve-static'); - -const makeAssetPath = require('./assetPath'); -const Queue = require('./queue'); -const { getClient } = require('./db'); - -const routes = require('./routes'); -const api = require('./api'); +import * as url from 'url'; +import path from 'path'; +import fs from 'fs'; + +import yaml from 'js-yaml'; +import express from 'express'; +import favicon from 'serve-favicon'; +import morgan from 'morgan'; +import bodyParser from 'body-parser'; +import serveStatic from 'serve-static'; + +import makeAssetPath from './assetPath.js'; +import Queue from './queue.js'; +import { getClient } from './db/index.js'; + +import routes from './routes/index.js'; +import api from './api/index.js'; const env = process.env.NODE_ENV || 'development'; const DEV = env !== 'production'; diff --git a/server/queue.js b/server/queue.js index f66cb7a..167a5d1 100644 --- a/server/queue.js +++ b/server/queue.js @@ -7,7 +7,7 @@ * - no events * - no job error handling */ -class Queue { +export default class Queue { /** * Queue constructor. * @constructor @@ -83,5 +83,3 @@ class Queue { } } } - -module.exports = Queue; diff --git a/server/render.js b/server/render.js index 87e19c5..3e12d41 100644 --- a/server/render.js +++ b/server/render.js @@ -1,5 +1,5 @@ -const { async, wire } = require('viperhtml'); -const path = require('path'); +import { async, wire } from 'viperhtml'; +import path from 'path'; const view = new Proxy( new String(path.join(__dirname, '..', '..', 'shared', 'view')), { get: (base, module) => require(base + path.sep + module) } @@ -10,7 +10,7 @@ const renderers = { header: wire(), }; -module.exports = { +export default { // async wires - parent page: (chunks, model) => view.index(renderers.page(chunks), model), diff --git a/server/routes/home.js b/server/routes/home.js index fac5b23..a71f304 100644 --- a/server/routes/home.js +++ b/server/routes/home.js @@ -1,8 +1,8 @@ -const { wire } = require('hypermorphic'); -const Home = require('../../shared/components/Home'); -const view = require('../../shared/views/default'); +import { wire } from 'hypermorphic'; +import Home from '../../shared/components/Home.js'; +import view from '../../shared/views/default.js'; -function home(req, res) { +export default function home(req, res) { res.writeHead(200, { 'Content-Type': 'text/html', }); @@ -18,5 +18,3 @@ function home(req, res) { ); res.end(); } - -module.exports = home; diff --git a/server/routes/index.js b/server/routes/index.js index 77781f9..911a053 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -1,7 +1,5 @@ -module.exports = { - home: require('./home'), - link: require('./link'), - play: require('./play'), - saved: require('./saved'), - shared: require('./shared'), -}; +export { default as home } from './home.js'; +export { default as link } from './link.js'; +export { default as play } from './play.js'; +export { default as saved } from './saved.js'; +export { default as shared } from './shared.js'; diff --git a/server/routes/link.js b/server/routes/link.js index fef3ab8..c78d44d 100644 --- a/server/routes/link.js +++ b/server/routes/link.js @@ -1,8 +1,8 @@ -const { wire } = require('hypermorphic'); -const Link = require('../../shared/components/Link'); -const view = require('../../shared/views/default'); +import { wire } from 'hypermorphic'; +import Link from '../../shared/components/Link/index.js'; +import view from '../../shared/views/default.js'; -function link(req, res) { +export default function link(req, res) { res.writeHead(200, { 'Content-Type': 'text/html', }); @@ -18,5 +18,3 @@ function link(req, res) { ); res.end(); } - -module.exports = link; diff --git a/server/routes/play.js b/server/routes/play.js index 60994a6..cccc71f 100644 --- a/server/routes/play.js +++ b/server/routes/play.js @@ -1,5 +1,3 @@ -function play(req, res) { +export default function play(req, res) { res.redirect('/'); } - -module.exports = play; diff --git a/server/routes/saved.js b/server/routes/saved.js index 2cd7b8a..cc41121 100644 --- a/server/routes/saved.js +++ b/server/routes/saved.js @@ -1,8 +1,8 @@ -const { wire } = require('hypermorphic'); -const Saved = require('../../shared/components/Saved'); -const view = require('../../shared/views/default'); +import { wire } from 'hypermorphic'; +import Saved from '../../shared/components/Saved.js'; +import view from '../../shared/views/default.js'; -function saved(req, res) { +export default function saved(req, res) { res.writeHead(200, { 'Content-Type': 'text/html', }); @@ -18,5 +18,3 @@ function saved(req, res) { ); res.end(); } - -module.exports = saved; diff --git a/server/routes/shared.js b/server/routes/shared.js index c978f42..e82e643 100644 --- a/server/routes/shared.js +++ b/server/routes/shared.js @@ -1,10 +1,10 @@ -const { wire } = require('hypermorphic'); -const Home = require('../../shared/components/Home'); -const Shared = require('../../shared/components/Shared'); -const view = require('../../shared/views/default'); -const { query } = require('../db'); +import { wire } from 'hypermorphic'; +import Home from '../../shared/components/Home.js'; +import Shared from '../../shared/components/Shared.js'; +import view from '../../shared/views/default.js'; +import { query } from '../db/index.js'; -async function shared(req, res) { +export default async function shared(req, res) { const id = req.params.id; if (!id) { @@ -92,5 +92,3 @@ async function shared(req, res) { ); res.end(); } - -module.exports = shared; diff --git a/server/utils.js b/server/utils.js index ff14f61..a0c58eb 100644 --- a/server/utils.js +++ b/server/utils.js @@ -1,18 +1,13 @@ -const { unlink, rename } = require('fs'); +import { unlink, rename } from 'fs'; -function renameAsync(oldPath, newPath) { +export function renameAsync(oldPath, newPath) { return new Promise((resolve, reject) => { rename(oldPath, newPath, err => (err ? reject(err) : resolve())); }); } -function unlinkAsync(path) { +export function unlinkAsync(path) { return new Promise((resolve, reject) => { unlink(path, err => (err ? reject(err) : resolve())); }); } - -module.exports = { - renameAsync, - unlinkAsync, -}; diff --git a/shared/components/ErrorMessage.js b/shared/components/ErrorMessage.js index ae1b39d..997b124 100644 --- a/shared/components/ErrorMessage.js +++ b/shared/components/ErrorMessage.js @@ -1,6 +1,8 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function ErrorMessage(messages_ = 'Oops! Something went wrong.') { +export default function ErrorMessage( + messages_ = 'Oops! Something went wrong.' +) { const messages = Array.isArray(messages_) ? messages_.filter(Boolean) : [messages_]; @@ -11,5 +13,3 @@ function ErrorMessage(messages_ = 'Oops! Something went wrong.') {

`; } - -module.exports = ErrorMessage; diff --git a/shared/components/Home.js b/shared/components/Home.js index 3c655f2..37683bb 100644 --- a/shared/components/Home.js +++ b/shared/components/Home.js @@ -1,10 +1,10 @@ -const { Component, wire } = require('hypermorphic'); -const { encode } = require('punycode'); -const Upload = require('./Upload'); -const LinkForm = require('./Link/Form'); -const Source = require('./Source'); -const List = require('./List'); -const getDisplayName = require('../helpers/getDisplayName'); +import { Component, wire } from 'hypermorphic'; +import { encode } from 'punycode'; +import Upload from './Upload.js'; +import LinkForm from './Link/Form.js'; +import Source from './Source/index.js'; +import List from './List/index.js'; +import getDisplayName from '../helpers/getDisplayName.js'; const initialState = { linkLoading: false, @@ -24,7 +24,7 @@ function Description() { `; } -class Home extends Component { +export default class Home extends Component { constructor() { super(); this.state = Object.assign({}, initialState); @@ -93,5 +93,3 @@ class Home extends Component { ); } } - -module.exports = Home; diff --git a/shared/components/Icons/AlertCircle.js b/shared/components/Icons/AlertCircle.js index f7a8e24..ee7f9f2 100644 --- a/shared/components/Icons/AlertCircle.js +++ b/shared/components/Icons/AlertCircle.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import wire from 'hypermorphic'; -function AlertCircle(id = 'default') { +export default function AlertCircle(id = 'default') { return wire(AlertCircle, `:${id}`)` `; } - -module.exports = AlertCircle; diff --git a/shared/components/Icons/Check.js b/shared/components/Icons/Check.js index e1dd05e..d4aa7cd 100644 --- a/shared/components/Icons/Check.js +++ b/shared/components/Icons/Check.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Check(id = 'default') { +export default function Check(id = 'default') { return wire(Check, `:${id}`)` `; } - -module.exports = Check; diff --git a/shared/components/Icons/CheckCircle.js b/shared/components/Icons/CheckCircle.js index 3131bfb..1247d7d 100644 --- a/shared/components/Icons/CheckCircle.js +++ b/shared/components/Icons/CheckCircle.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function CheckCircle(id = 'default') { +export default function CheckCircle(id = 'default') { return wire(CheckCircle, `:${id}`)` `; } - -module.exports = CheckCircle; diff --git a/shared/components/Icons/CloudDownload.js b/shared/components/Icons/CloudDownload.js index 6ec0419..f5ced3c 100644 --- a/shared/components/Icons/CloudDownload.js +++ b/shared/components/Icons/CloudDownload.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function CloudDownload(id = 'default') { +export default function CloudDownload(id = 'default') { return wire(CloudDownload, `:${id}`)` `; } - -module.exports = CloudDownload; diff --git a/shared/components/Icons/Control.js b/shared/components/Icons/Control.js index 9a9cb52..0fb2877 100644 --- a/shared/components/Icons/Control.js +++ b/shared/components/Icons/Control.js @@ -1,22 +1,22 @@ -const { Component } = require('hypermorphic'); +import { Component } from 'hypermorphic'; -const AlertCircle = require('./Icons/AlertCircle'); -const Check = require('./Icons/Check'); -const CheckCircle = require('./Icons/CheckCircle'); -const Floppy = require('./Icons/Floppy'); -const Forbidden = require('./Icons/Forbidden'); -const Info = require('./Icons/Info'); -const Link = require('./Icons/Link'); -const List = require('./Icons/List'); -const Loader = require('./Icons/Loader'); -const Pause = require('./Icons/Pause'); -const Play = require('./Icons/Play'); -const Scissors = require('./Icons/Scissors'); -const Settings = require('./Icons/Settings'); -const Share = require('./Icons/Share'); -const Start = require('./Icons/Start'); +import AlertCircle from './Icons/AlertCircle'; +import Check from './Icons/Check'; +import CheckCircle from './Icons/CheckCircle'; +import Floppy from './Icons/Floppy'; +import Forbidden from './Icons/Forbidden'; +import Info from './Icons/Info'; +import Link from './Icons/Link'; +import List from './Icons/List'; +import Loader from './Icons/Loader'; +import Pause from './Icons/Pause'; +import Play from './Icons/Play'; +import Scissors from './Icons/Scissors'; +import Settings from './Icons/Settings'; +import Share from './Icons/Share'; +import Start from './Icons/Start'; -class Control extends Component { +export default class Control extends Component { constructor(...args) { super(...args); } @@ -104,5 +104,3 @@ class Control extends Component { `; } } - -module.exports = Control; diff --git a/shared/components/Icons/Cross.js b/shared/components/Icons/Cross.js index 930b16c..4a39f90 100644 --- a/shared/components/Icons/Cross.js +++ b/shared/components/Icons/Cross.js @@ -1,4 +1,4 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; function getColor(theme) { let color; @@ -16,7 +16,7 @@ function getColor(theme) { return color; } -function Cross(theme = 'primary', id = 'default') { +export default function Cross(theme = 'primary', id = 'default') { const color = getColor(theme); return wire(Cross, `:${theme}-${id}`)` @@ -36,5 +36,3 @@ function Cross(theme = 'primary', id = 'default') { `; } - -module.exports = Cross; diff --git a/shared/components/Icons/Download.js b/shared/components/Icons/Download.js index 2a712a4..4220b0e 100644 --- a/shared/components/Icons/Download.js +++ b/shared/components/Icons/Download.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Download(id = 'default') { +export default function Download(id = 'default') { return wire(Download, `:${id}`)` `; } - -module.exports = Download; diff --git a/shared/components/Icons/Floppy.js b/shared/components/Icons/Floppy.js index aa4f112..bb00d5b 100644 --- a/shared/components/Icons/Floppy.js +++ b/shared/components/Icons/Floppy.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Floppy(id = 'default') { +export default function Floppy(id = 'default') { return wire(Floppy, `:${id}`)` `; } - -module.exports = Floppy; diff --git a/shared/components/Icons/Forbidden.js b/shared/components/Icons/Forbidden.js index ba6d35b..15b583c 100644 --- a/shared/components/Icons/Forbidden.js +++ b/shared/components/Icons/Forbidden.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Forbidden(id = 'default') { +export default function Forbidden(id = 'default') { return wire(Forbidden, `:${id}`)` `; } - -module.exports = Forbidden; diff --git a/shared/components/Icons/Headphones.js b/shared/components/Icons/Headphones.js index 823f643..c910db3 100644 --- a/shared/components/Icons/Headphones.js +++ b/shared/components/Icons/Headphones.js @@ -1,7 +1,7 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; // stroke = $color-green; -function Headphones(ref, id, stroke = '#37f0c2') { +export default function Headphones(ref, id, stroke = '#37f0c2') { return wire(ref, `:${id}`)` `; } - -module.exports = Headphones; diff --git a/shared/components/Icons/Info.js b/shared/components/Icons/Info.js index 08dbfb4..6771f02 100644 --- a/shared/components/Icons/Info.js +++ b/shared/components/Icons/Info.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function AlertCircle(id = 'default') { +export default function AlertCircle(id = 'default') { return wire(AlertCircle, `:${id}`)` `; } - -module.exports = AlertCircle; diff --git a/shared/components/Icons/Link.js b/shared/components/Icons/Link.js index 813436f..d009aff 100644 --- a/shared/components/Icons/Link.js +++ b/shared/components/Icons/Link.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Link(id = 'default') { +export default function Link(id = 'default') { return wire(Link, `:${id}`)` `; } - -module.exports = Link; diff --git a/shared/components/Icons/List.js b/shared/components/Icons/List.js index 76e9a63..9ac301c 100644 --- a/shared/components/Icons/List.js +++ b/shared/components/Icons/List.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Pause() { +export default function Pause() { return wire(Pause, 'svg')` `; } - -module.exports = Pause; diff --git a/shared/components/Icons/Loader.js b/shared/components/Icons/Loader.js index 7e2055a..c696bef 100644 --- a/shared/components/Icons/Loader.js +++ b/shared/components/Icons/Loader.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Loader() { +export default function Loader() { return wire(Loader)` `; } - -module.exports = Loader; diff --git a/shared/components/Icons/Pause.js b/shared/components/Icons/Pause.js index 3703625..7afedd6 100644 --- a/shared/components/Icons/Pause.js +++ b/shared/components/Icons/Pause.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Pause(id = 'default') { +export default function Pause(id = 'default') { return wire(Pause, `:${id}`)` `; } - -module.exports = Pause; diff --git a/shared/components/Icons/Play.js b/shared/components/Icons/Play.js index a3465ca..0d7291d 100644 --- a/shared/components/Icons/Play.js +++ b/shared/components/Icons/Play.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Play(id = 'default') { +export default function Play(id = 'default') { return wire(Play, `:${id}`)` `; } - -module.exports = Play; diff --git a/shared/components/Icons/Scissors.js b/shared/components/Icons/Scissors.js index 7b8845d..d6c13b6 100644 --- a/shared/components/Icons/Scissors.js +++ b/shared/components/Icons/Scissors.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Scissors(id = 'default') { +export default function Scissors(id = 'default') { return wire(Scissors, `:${id}`)` `; } - -module.exports = Scissors; diff --git a/shared/components/Icons/Settings.js b/shared/components/Icons/Settings.js index f36652f..716186f 100644 --- a/shared/components/Icons/Settings.js +++ b/shared/components/Icons/Settings.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Settings(id = 'default') { +export default function Settings(id = 'default') { return wire(Settings, `:${id}`)` `; } - -module.exports = Settings; diff --git a/shared/components/Icons/Share.js b/shared/components/Icons/Share.js index 962ce2e..a1cb651 100644 --- a/shared/components/Icons/Share.js +++ b/shared/components/Icons/Share.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Share(id = 'default') { +export default function Share(id = 'default') { return wire(Share, `:${id}`)` `; } - -module.exports = Share; diff --git a/shared/components/Icons/Start.js b/shared/components/Icons/Start.js index ef80dbe..4bd14ec 100644 --- a/shared/components/Icons/Start.js +++ b/shared/components/Icons/Start.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Start(id = 'default') { +export default function Start(id = 'default') { return wire(Start, `:${id}`)` `; } - -module.exports = Start; diff --git a/shared/components/Icons/Upload.js b/shared/components/Icons/Upload.js index a4c4bc0..8f97112 100644 --- a/shared/components/Icons/Upload.js +++ b/shared/components/Icons/Upload.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Upload(id = 'default') { +export default function Upload(id = 'default') { return wire(Upload, `:${id}`)` `; } - -module.exports = Upload; diff --git a/shared/components/Link/Form.js b/shared/components/Link/Form.js index ec59d17..f4dd57b 100644 --- a/shared/components/Link/Form.js +++ b/shared/components/Link/Form.js @@ -1,10 +1,10 @@ /* eslint-disable indent */ /* prettier-ignore-start */ -const { Component, wire } = require('hypermorphic'); +import { Component, wire } from 'hypermorphic'; -const ErrorMessage = require('../ErrorMessage'); -const Loader = require('../Loader'); -const CloudDownload = require('../Icons/CloudDownload'); +import ErrorMessage from '../ErrorMessage.js'; +import Loader from '../Loader.js'; +import CloudDownload from '../Icons/CloudDownload.js'; const linkPath = '/api/link'; @@ -15,7 +15,7 @@ const initialState = { file: undefined, }; -class LinkForm extends Component { +export default class LinkForm extends Component { constructor({ onFileValid, loadingCallback } = {}) { super(); this.onFileValid = onFileValid; @@ -172,5 +172,3 @@ class LinkForm extends Component { `); } } - -module.exports = LinkForm; diff --git a/shared/components/Link/index.js b/shared/components/Link/index.js index 3fc9c9b..c07687b 100644 --- a/shared/components/Link/index.js +++ b/shared/components/Link/index.js @@ -1,15 +1,15 @@ -const { Component } = require('hypermorphic'); -const { encode } = require('punycode'); +import { Component } from 'hypermorphic'; +import { encode } from 'punycode'; -const LinkForm = require('./Form'); -const Source = require('../Source'); -const getDisplayName = require('../../helpers/getDisplayName'); +import LinkForm from './Form.js'; +import Source from '../Source/index.js'; +import getDisplayName from '../../helpers/getDisplayName.js'; const initialState = { source: undefined, }; -class Link extends Component { +export default class Link extends Component { constructor() { super(); this.state = Object.assign({}, initialState); @@ -49,5 +49,3 @@ class Link extends Component { return this.decorateContent(this.link); } } - -module.exports = Link; diff --git a/shared/components/List/Item.js b/shared/components/List/Item.js index 2ab55ff..9d7ccd4 100644 --- a/shared/components/List/Item.js +++ b/shared/components/List/Item.js @@ -1,11 +1,11 @@ -const { wire } = require('hypermorphic'); -const Headphones = require('../Icons/Headphones'); -const humanizeFileSize = require('../../helpers/humanizeFileSize'); -const getDisplayName = require('../../helpers/getDisplayName'); -const formatTime = require('../../helpers/formatTime'); +import { wire } from 'hypermorphic'; +import Headphones from '../Icons/Headphones.js'; +import humanizeFileSize from '../../helpers/humanizeFileSize.js'; +import getDisplayName from '../../helpers/getDisplayName.js'; +import formatTime from '../../helpers/formatTime.js'; /* eslint-disable indent */ -function ListItem({ type, item }) { +export default function ListItem({ type, item }) { const url = type == 'shared' ? `/shared/${item.key}` : `/saved/${type}/${item.key}`; @@ -18,9 +18,11 @@ function ListItem({ type, item }) { ${getDisplayName(item.filename)} - ${typeof item.duration === 'undefined' - ? '' - : formatTime(item.duration)} + ${ + typeof item.duration === 'undefined' + ? '' + : formatTime(item.duration) + } ${humanizeFileSize(item.filesize)} ${Headphones(item, item.key)} @@ -29,5 +31,3 @@ function ListItem({ type, item }) { `; } - -module.exports = ListItem; diff --git a/shared/components/List/index.js b/shared/components/List/index.js index 8168ba9..3fa0311 100644 --- a/shared/components/List/index.js +++ b/shared/components/List/index.js @@ -1,6 +1,6 @@ -const { Component, wire } = require('hypermorphic'); -const ListItem = require('./Item'); -const { getAllItems } = require('../../helpers/indexedDB'); +import { Component, wire } from 'hypermorphic'; +import ListItem from './Item.js'; +import { getAllItems } from '../../helpers/indexedDB.js'; const initialState = { items: [], @@ -26,7 +26,7 @@ function getTitle(type) { return title; } -class List extends Component { +export default class List extends Component { constructor(type) { super(); this.type = type; @@ -65,5 +65,3 @@ class List extends Component { return this.decorateContent(title, items); } } - -module.exports = List; diff --git a/shared/components/Loader.js b/shared/components/Loader.js index b9427b7..7daa1cd 100644 --- a/shared/components/Loader.js +++ b/shared/components/Loader.js @@ -1,7 +1,7 @@ -const { wire } = require('hypermorphic'); -const LoaderIcon = require('./Icons/Loader'); +import { wire } from 'hypermorphic'; +import LoaderIcon from './Icons/Loader.js'; -function Loader(message = 'Loading... Please wait.') { +export default function Loader(message = 'Loading... Please wait.') { return wire()`

${message}

@@ -9,5 +9,3 @@ function Loader(message = 'Loading... Please wait.') {
`; } - -module.exports = Loader; diff --git a/shared/components/Saved.js b/shared/components/Saved.js index 833007a..d323b2c 100644 --- a/shared/components/Saved.js +++ b/shared/components/Saved.js @@ -1,9 +1,9 @@ -const { Component } = require('hypermorphic'); +import { Component } from 'hypermorphic'; -const Source = require('./Source'); -const ErrorMessage = require('./ErrorMessage'); -const getDisplayName = require('../helpers/getDisplayName'); -const { getItem } = require('../helpers/indexedDB'); +import Source from './Source/index.js'; +import ErrorMessage from './ErrorMessage.js'; +import getDisplayName from '../helpers/getDisplayName.js'; +import { getItem } from '../helpers/indexedDB.js'; const initialState = { source: undefined, @@ -11,7 +11,7 @@ const initialState = { item: undefined, }; -class Saved extends Component { +export default class Saved extends Component { constructor({ id, type }) { super(); this.id = id; @@ -58,5 +58,3 @@ class Saved extends Component { return this.decorateContent(this.state.source); } } - -module.exports = Saved; diff --git a/shared/components/SavedAlert.js b/shared/components/SavedAlert.js index 28b8b0d..9b1215a 100644 --- a/shared/components/SavedAlert.js +++ b/shared/components/SavedAlert.js @@ -1,7 +1,7 @@ -const { wire } = require('hypermorphic'); -const SuccessMessage = require('./SuccessMessage'); +import { wire } from 'hypermorphic'; +import SuccessMessage from './SuccessMessage.js'; -function SavedAlert({ hash, type }) { +export default function SavedAlert({ hash, type }) { const messages = [ wire( SavedAlert, @@ -19,5 +19,3 @@ function SavedAlert({ hash, type }) { return SuccessMessage(messages); } - -module.exports = SavedAlert; diff --git a/shared/components/Shared.js b/shared/components/Shared.js index b172aa5..3b5baea 100644 --- a/shared/components/Shared.js +++ b/shared/components/Shared.js @@ -1,11 +1,11 @@ /* eslint-disable indent */ /* prettier-ignore-start */ -const { Component } = require('hypermorphic'); +import { Component } from 'hypermorphic'; -const Source = require('./Source'); -const ErrorMessage = require('./ErrorMessage'); -const Loader = require('./Loader'); -const fetchSlice = require('../helpers/fetchSlice'); +import Source from './Source/index.js'; +import ErrorMessage from './ErrorMessage.js'; +import Loader from './Loader.js'; +import fetchSlice from '../helpers/fetchSlice.js'; const initialState = { error: false, @@ -14,7 +14,7 @@ const initialState = { owner: false, }; -class Shared extends Component { +export default class Shared extends Component { constructor(id) { super(); this.id = id; @@ -54,12 +54,12 @@ class Shared extends Component {
${state.error ? ErrorMessage() : ''} ${state.loading ? Loader() : ''} - ${file - ? new Source({ shared: this.id, file, owner, type: 'shared' }) - : ''} + ${ + file + ? new Source({ shared: this.id, file, owner, type: 'shared' }) + : '' + }
`; } } - -module.exports = Shared; diff --git a/shared/components/SharedAlert.js b/shared/components/SharedAlert.js index 3804131..7bc5e34 100644 --- a/shared/components/SharedAlert.js +++ b/shared/components/SharedAlert.js @@ -1,7 +1,7 @@ -const { wire } = require('hypermorphic'); -const SuccessMessage = require('./SuccessMessage'); +import { wire } from 'hypermorphic'; +import SuccessMessage from './SuccessMessage.js'; -function SharedAlert(id) { +export default function SharedAlert(id) { const url = `${window.location.origin}/shared/${id.slice(0, 10)}`; const messages = [ @@ -19,5 +19,3 @@ function SharedAlert(id) { return SuccessMessage(messages); } - -module.exports = SharedAlert; diff --git a/shared/components/Slice/Form.js b/shared/components/Slice/Form.js index 4bed54d..270e944 100644 --- a/shared/components/Slice/Form.js +++ b/shared/components/Slice/Form.js @@ -1,6 +1,6 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -function Form({ id, initialValue, onChange, onFocus, onBlur }) { +export default function Form({ id, initialValue, onChange, onFocus, onBlur }) { return wire(id)`

You can edit your slice's name before saving, downloading or sharing it. @@ -18,5 +18,3 @@ function Form({ id, initialValue, onChange, onFocus, onBlur }) { ${initialValue} `; } - -module.exports = Form; diff --git a/shared/components/Slice/PlayerActions.js b/shared/components/Slice/PlayerActions.js index fe8a8b1..470b66d 100644 --- a/shared/components/Slice/PlayerActions.js +++ b/shared/components/Slice/PlayerActions.js @@ -1,12 +1,12 @@ -const { wire } = require('hypermorphic'); +import { wire } from 'hypermorphic'; -const Play = require('../Icons/Play'); -const Pause = require('../Icons/Pause'); -const Check = require('../Icons/Check'); -const Cross = require('../Icons/Cross'); +import Play from '../Icons/Play.js'; +import Pause from '../Icons/Pause.js'; +import Check from '../Icons/Check.js'; +import Cross from '../Icons/Cross.js'; /* eslint-disable indent */ -function PlayerActions({ +export default function PlayerActions({ submitted, disabled, paused, @@ -31,8 +31,9 @@ function PlayerActions({ > ${Check('player-actions')} - ${submitted - ? wire(PlayerActions, ':dismiss')` + ${ + submitted + ? wire(PlayerActions, ':dismiss')`