From 9e8ea43d5bb1fb89cea8e788d799b8f1af4fb2f5 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 19 Sep 2021 19:52:08 -0500 Subject: [PATCH] Update readme for running on local. Add command line arg parser. --- client/package.json | 2 +- package-lock.json | 34 ++++++++++++++++++++++++++++++++++ package.json | 5 +++-- prod.js | 22 ++++++++++++++++++---- readme.md | 15 +++++++++++++++ 5 files changed, 71 insertions(+), 7 deletions(-) diff --git a/client/package.json b/client/package.json index 3247ff46..9c5a7ce9 100644 --- a/client/package.json +++ b/client/package.json @@ -25,4 +25,4 @@ "@nuxtjs/tailwindcss": "^4.2.1", "postcss": "^8.3.6" } -} \ No newline at end of file +} diff --git a/package-lock.json b/package-lock.json index 097d9d74..fdebb9a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -138,6 +138,11 @@ "is-primitive": "^3.0.1" } }, + "array-back": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/array-back/-/array-back-3.1.0.tgz", + "integrity": "sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q==" + }, "array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", @@ -288,6 +293,17 @@ "mimic-response": "^1.0.0" } }, + "command-line-args": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.2.0.tgz", + "integrity": "sha512-4zqtU1hYsSJzcJBOcNZIbW5Fbk9BkjCp1pZVhQKoRaWL5J7N4XphDLwo8aWwdQpTugxwu+jf9u2ZhkXiqp5Z6A==", + "requires": { + "array-back": "^3.1.0", + "find-replace": "^3.0.0", + "lodash.camelcase": "^4.3.0", + "typical": "^4.0.0" + } + }, "component-emitter": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", @@ -566,6 +582,14 @@ "unpipe": "~1.0.0" } }, + "find-replace": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-replace/-/find-replace-3.0.0.tgz", + "integrity": "sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==", + "requires": { + "array-back": "^3.0.1" + } + }, "fluent-ffmpeg": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/fluent-ffmpeg/-/fluent-ffmpeg-2.1.2.tgz", @@ -830,6 +854,11 @@ "got": "11.3.x" } }, + "lodash.camelcase": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", + "integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY=" + }, "lodash.defaults": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz", @@ -1339,6 +1368,11 @@ "mime-types": "~2.1.24" } }, + "typical": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/typical/-/typical-4.0.0.tgz", + "integrity": "sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==" + }, "universalify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", diff --git a/package.json b/package.json index 8d3e54b7..f7586478 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "main": "index.js", "scripts": { "dev": "node index.js", - "start": "node index.js", "client": "cd client && npm install --production && npm run generate", - "prod": "npm run client && npm install && node prod.js" + "prod": "npm run client && npm install --production && node prod.js", + "start": "node prod.js" }, "author": "advplyr", "license": "ISC", @@ -15,6 +15,7 @@ "archiver": "^5.3.0", "axios": "^0.21.1", "bcryptjs": "^2.4.3", + "command-line-args": "^5.2.0", "cookie-parser": "^1.4.5", "express": "^4.17.1", "express-fileupload": "^1.2.1", diff --git a/prod.js b/prod.js index 0fd3a918..628f1e2f 100644 --- a/prod.js +++ b/prod.js @@ -1,3 +1,13 @@ +const optionDefinitions = [ + { name: 'config', alias: 'c', type: String }, + { name: 'audiobooks', alias: 'a', type: String }, + { name: 'metadata', alias: 'm', type: String }, + { name: 'port', alias: 'p', type: String } +] + +const commandLineArgs = require('command-line-args') +const options = commandLineArgs(optionDefinitions) + const Path = require('path') process.env.TOKEN_SECRET = '09f26e402586e2faa8da4c98a35f1b20d6b033c6097befa8be3486a829587fe2f90a832bd3ff9d42710a4da095a2ce285b009f0c3730cd9b8e1af3eb84df6611' process.env.NODE_ENV = 'production' @@ -5,10 +15,14 @@ process.env.NODE_ENV = 'production' const server = require('./server/Server') global.appRoot = __dirname -const PORT = process.env.PORT || 3333 -const CONFIG_PATH = process.env.CONFIG_PATH || Path.resolve('config') -const AUDIOBOOK_PATH = process.env.AUDIOBOOK_PATH || Path.resolve('audiobooks') -const METADATA_PATH = process.env.METADATA_PATH || Path.resolve('metadata') +var inputConfig = options.config ? Path.resolve(options.config) : null +var inputAudiobook = options.audiobooks ? Path.resolve(options.audiobooks) : null +var inputMetadata = options.metadata ? Path.resolve(options.metadata) : null + +const PORT = options.port || process.env.PORT || 3333 +const CONFIG_PATH = inputConfig || process.env.CONFIG_PATH || Path.resolve('config') +const AUDIOBOOK_PATH = inputAudiobook || process.env.AUDIOBOOK_PATH || Path.resolve('audiobooks') +const METADATA_PATH = inputMetadata || process.env.METADATA_PATH || Path.resolve('metadata') console.log('Config', CONFIG_PATH, METADATA_PATH, AUDIOBOOK_PATH) diff --git a/readme.md b/readme.md index 491374bc..7363e9ce 100644 --- a/readme.md +++ b/readme.md @@ -72,6 +72,21 @@ Built to run in Docker for now (also on Unraid server Community Apps) docker run -d -p 1337:80 -v /audiobooks:/audiobooks -v /config:/config -v /metadata:/metadata --name audiobookshelf --rm advplyr/audiobookshelf ``` +## Running on your local + +```bash +git clone https://github.com/advplyr/audiobookshelf.git +cd audiobookshelf + +# All paths default to root directory. Config path is the database. +# Directories will be created if they don't exist +# Paths are relative to the root directory, so "../Audiobooks" would be a valid path +npm run prod -- -p [PORT] --audiobooks [AUDIOBOOKS_PATH] --config [CONFIG_PATH] --metadata [METADATA_PATH] + +# You only need to use `npm run prod` the first time, after that use `npm run start` +npm run start -- -p [PORT] --audiobooks [AUDIOBOOKS_PATH] --config [CONFIG_PATH] --metadata [METADATA_PATH] +``` + ## Contributing Feel free to help out \ No newline at end of file