diff --git a/.babelrc b/.babelrc index 1e78999..b89b7c3 100644 --- a/.babelrc +++ b/.babelrc @@ -1,13 +1,14 @@ { "presets": [ "env", - "react", "stage-0" ], "plugins": [ "transform-class-properties", "transform-decorators", - "transform-react-constant-elements", - "transform-react-inline-elements" + ["transform-runtime", { + "polyfill": false, + "regenerator": true + }] ] } diff --git a/.gitignore b/.gitignore index e96a533..f300417 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ *.db *.bak +tmp.* values.json /node_modules/ +/dist/ /package-lock.json diff --git a/package.json b/package.json index 855e0ee..070d3b6 100644 --- a/package.json +++ b/package.json @@ -3,16 +3,23 @@ "version": "1.0.0", "main": "server.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "build": "babel src -d dist", + "start": "node dist/server.js", + "download": "node dist/download.js", + "populate": "node dist/dbpopulate.js" }, "private": true, "dependencies": { - "babel-core": "^6.26.3", - "babel-env": "^2.4.1", "bluebird": "^3.5.2", "express": "^4.16.3", "express-async-errors": "^3.0.0", "fs-extra": "^7.0.0", - "sqlite": "^3.0.0" + "sqlite": "^3.0.0", + "babel-plugin-transform-runtime": "^6.23.0" + }, + "devDependencies": { + "babel-core": "^6.26.3", + "babel-env": "^2.4.1" } } diff --git a/common/async.js b/src/common/async.js similarity index 100% rename from common/async.js rename to src/common/async.js diff --git a/common/download.js b/src/common/download.js similarity index 97% rename from common/download.js rename to src/common/download.js index ff3965d..3b6c8fd 100644 --- a/common/download.js +++ b/src/common/download.js @@ -56,7 +56,7 @@ function getVideoInfo (arg) { function fetchVideo (data) { return new Promise((resolve, reject) => { if (data.acodec !== 'mp3' || data.vcodec !== 'none') { - let tempName = path.join(__dirname, `/tmp.yt.${data.id}.mp3`) + let tempName = path.join(process.cwd(), `/tmp.yt.${data.id}.mp3`) let ffmpeg = spawn('ffmpeg', ['-hide_banner', '-i', data.url, '-codec:a', 'libmp3lame', '-q:a', 2, '-joint_stereo', 1, '-y', tempName]) ffmpeg.stdout.pipe(process.stderr) diff --git a/dbpopulate.js b/src/dbpopulate.js old mode 100755 new mode 100644 similarity index 94% rename from dbpopulate.js rename to src/dbpopulate.js index d792a19..43b6bc4 --- a/dbpopulate.js +++ b/src/dbpopulate.js @@ -1,4 +1,3 @@ -#!/usr/bin/env babel-node import fs from 'fs-extra' import path from 'path' import sqlite from 'sqlite' @@ -8,11 +7,11 @@ import readline from 'readline' import asn from './common/async' import dl from './common/download' -const values = require(path.join(__dirname, 'values.json')) +const values = require(path.join(process.cwd(), 'values.json')) const musicdir = path.resolve(values.directory) const dbPromise = Promise.resolve() - .then(() => sqlite.open(path.join(__dirname, values.database), { Promise, cache: true })) + .then(() => sqlite.open(path.join(process.cwd(), values.database), { Promise, cache: true })) .then(db => db.migrate()) // ffprobe -i -show_entries format=duration -v quiet -of csv="p=0" diff --git a/download.js b/src/download.js old mode 100755 new mode 100644 similarity index 94% rename from download.js rename to src/download.js index e55f726..9735586 --- a/download.js +++ b/src/download.js @@ -1,4 +1,3 @@ -#!/usr/bin/env babel-node 'use strict' import fs from 'fs-extra' @@ -8,7 +7,7 @@ import path from 'path' import asn from './common/async' import dl from './common/download' -const values = require(path.join(__dirname, 'values.json')) +const values = require(path.join(process.cwd(), 'values.json')) const musicdir = path.resolve(values.directory) const rl = readline.createInterface({ diff --git a/server.js b/src/server.js old mode 100755 new mode 100644 similarity index 94% rename from server.js rename to src/server.js index 84623b3..3ffeac1 --- a/server.js +++ b/src/server.js @@ -1,4 +1,3 @@ -#!/usr/bin/env babel-node import path from 'path' import sqlite from 'sqlite' import Promise from 'bluebird' @@ -6,11 +5,11 @@ import express from 'express' require('express-async-errors') -const values = require(path.join(__dirname, 'values.json')) +const values = require(path.join(process.cwd(), 'values.json')) const tracksPerPage = 100 const dbPromise = Promise.resolve() - .then(() => sqlite.open(path.join(__dirname, values.database), { Promise, cache: true })) + .then(() => sqlite.open(path.join(process.cwd(), values.database), { Promise, cache: true })) .then(db => db.migrate()) const app = express() @@ -151,7 +150,7 @@ router.use((err, req, res, next) => { app.use('/api', router) app.use('/file/track', express.static(path.resolve(values.directory))) -app.use('/', express.static(path.join(__dirname, 'public'))) +app.use('/', express.static(path.join(process.cwd(), 'public'))) app.listen(port, '127.0.0.1', function () { console.log(`app running on port ${port}`)