diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 5811c34..0000000 --- a/.dockerignore +++ /dev/null @@ -1,9 +0,0 @@ -node_modules - -gui/node_modules -gui/src - -server/node_modules -server/db -server/src -server/typings diff --git a/.gitignore b/.gitignore index eb03e3e..7826a59 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules +npm *.log diff --git a/.travis.yml b/.travis.yml index 02f135c..c1eeef9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,6 @@ cache: - node_modules - gui/node_modules - server/node_modules -#sudo: required -#services: -#- docker addons: apt: packages: @@ -20,9 +17,3 @@ script: - npm run test:ci - npm run build - npm run fixme -#- docker build --tag phjardas/tabidisco . -#deploy: -# provider: script -# script: bash docker_push.sh -# on: -# branch: master diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index d77c72a..0000000 --- a/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -FROM node:8 - -ENV DEBIAN_FRONTEND noninteractive -RUN apt-get -yq update \ - && apt-get install -yq --no-install-suggests --no-install-recommends \ - libasound2-dev \ - && rm -rf /var/lib/apt/lists/* -RUN npm i -g npm@5.7.1 - -ENV \ - NODE_ENV=production \ - PORT=3000 \ - TABIDISCO_GUI_DIR=/opt/tabidisco/gui \ - TABIDISCO_DB_DIR=/data -EXPOSE 3000 -VOLUME ["/data"] -CMD ["npm", "start"] - -RUN mkdir -p /opt/tabidisco /data -WORKDIR /opt/tabidisco - -COPY server/package* ./ -RUN npm ci --production - -COPY server/ ./ -COPY gui/dist/ ./gui/ diff --git a/bin/tabidisco b/bin/tabidisco new file mode 100755 index 0000000..0fd9fc4 --- /dev/null +++ b/bin/tabidisco @@ -0,0 +1,10 @@ +#!/usr/bin/env node +'use strict'; + +const path = require('path'); + +process.title = 'tabidisco'; +process.env.TABIDISCO_GUI_DIR = path.resolve(__dirname, '..', 'gui'); +process.env.TABIDISCO_DB_DIR = process.env.TABIDISCO_DB_DIR || '/var/lib/tabidisco'; + +require('..'); diff --git a/bundle.js b/bundle.js new file mode 100644 index 0000000..08c62e2 --- /dev/null +++ b/bundle.js @@ -0,0 +1,60 @@ +const fs = require('fs-extra'); +const path = require('path'); +const pkg = require('./package.json'); + +const root = __dirname; +const server = path.resolve(root, 'server'); +const gui = path.resolve(root, 'gui'); +const target = path.resolve(root, 'npm'); + +function copyFile(src, targetDir) { + const target = path.resolve(targetDir, path.parse(src).base); + return fs.copy(src, target); +} + +async function writePackageJson() { + const pkg = { ...require(path.resolve(server, 'package.json')) }; + ['private', 'scripts', 'devDependencies', 'jest', 'main', 'typings'].forEach(f => delete pkg[f]); + pkg.scripts = { start: 'node index.js' }; + + const mainPkg = require('./package.json'); + ['name', 'version', 'description', 'homepage', 'bugs', 'license', 'author', 'contributors', 'repository', 'bin'].forEach( + f => (pkg[f] = mainPkg[f]) + ); + + await fs.writeFile(path.resolve(target, 'package.json'), JSON.stringify(pkg, null, 2), 'utf-8'); +} + +async function main() { + await fs.emptyDir(target); + await fs.ensureDir(target); + + // write package.json + await writePackageJson(); + + // write README.md + await fs.writeFile( + path.resolve(target, 'README.md'), + '# Tabidisco: Jukebox for kids powered by Raspberry Pi\n\nThis is the GUI for [Tabidisco](https://github.com/phjardas/tabidisco).\n', + 'utf-8' + ); + + // copy server files + await fs.copy(path.resolve(server, 'dist'), target, { + filter: f => !f.endsWith('.ts') && !f.endsWith('.map'), + }); + + // copy GUI files + await fs.ensureDir(path.resolve(target, 'gui')); + await fs.copy(path.resolve(gui, 'dist'), path.resolve(target, 'gui')); + + // copy bin files + await fs.copy(path.resolve(root, 'bin'), path.resolve(target, 'bin')); +} + +main() + .then(() => console.log('DONE')) + .catch(err => { + process.exitCode = 1; + console.error('ERROR:', err); + }); diff --git a/docker_push.sh b/docker_push.sh deleted file mode 100755 index 33e02f1..0000000 --- a/docker_push.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"; -docker push phjardas/tabidisco diff --git a/docs/INSTALLING.md b/docs/INSTALLING.md index 8309a62..18bcbdf 100644 --- a/docs/INSTALLING.md +++ b/docs/INSTALLING.md @@ -52,16 +52,10 @@ npm install -g npm@latest ## Initial setup -Clone the tabidisco repository on your Pi into `/home/pi/tabidisco`: +Install Tabidisco globally: -``` -git clone https://github.com/phjardas/tabidisco.git ~/tabidisco -``` - -Create a directory to store persistent data (eg. MP3 files): - -``` -mkdir -p ~/tabidisco-data +```bash +npm install --global tabidisco ``` Create a startup script at `/home/pi/tabidisco.sh`: @@ -70,20 +64,13 @@ Create a startup script at `/home/pi/tabidisco.sh`: #!/bin/bash source ~/.nvm/nvm.sh nvm use 8 -npm start + +export NODE_ENV=production +tabidisco ``` and make it executable: `chmod +x ~/tabidisco.sh`. -Create the file `/etc/default/tabidisco` with the following content: - -``` -NODE_ENV=production -PORT=3000 -TABIDISCO_GUI_DIR=/home/pi/tabidisco/gui/dist -TABIDISCO_DB_DIR=/home/pi/tabidisco-data -``` - Create the file `/etc/systemd/system/tabidisco.service` with the following content: ``` @@ -94,13 +81,11 @@ After=network.target [Service] ExecStart=/home/pi/tabidisco.sh -WorkingDirectory=/home/pi/tabidisco/server Restart=always RestartSec=10 StandardOutput=syslog StandardError=syslog SyslogIdentifier=tabidisco -EnvironmentFile=/etc/default/tabidisco [Install] WantedBy=multi-user.target @@ -112,15 +97,13 @@ Now enable the service to start on boot: sudo systemctl enable tabidisco.service ``` -## Deployment +You can now access tabidisco on your Pi's IP address at port 3000. -Everytime you want to deploy the newest version (including the first time) run the following commands: +## Updating + +When you want to update your installation of Tabidisco to the latest version, run the following script: ```bash -cd ~/tabidisco -(cd gui && npm ci && npm run build) -(cd server && npm ci && npm run build) +npm install --global tabidisco@latest sudo service tabidisco restart ``` - -You can now access tabidisco on your Pi's IP address at port 3000. diff --git a/gui/package.json b/gui/package.json index fe13374..e18cc2c 100644 --- a/gui/package.json +++ b/gui/package.json @@ -48,17 +48,27 @@ "env", { "targets": { - "browsers": ["last 2 versions"] + "browsers": [ + "last 2 versions" + ] }, "modules": false } ], "react" ], - "plugins": ["transform-object-rest-spread", "transform-class-properties"], + "plugins": [ + "transform-object-rest-spread", + "transform-class-properties" + ], "env": { "test": { - "presets": [["env"], "react"] + "presets": [ + [ + "env" + ], + "react" + ] } } } diff --git a/package-lock.json b/package-lock.json index 17577a7..55d3f97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1130,6 +1130,28 @@ "integrity": "sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=", "dev": true }, + "fs-extra": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz", + "integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==", + "dev": true, + "requires": { + "graceful-fs": "4.1.11", + "jsonfile": "4.0.0", + "universalify": "0.1.1" + }, + "dependencies": { + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "dev": true, + "requires": { + "graceful-fs": "4.1.11" + } + } + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -4224,6 +4246,12 @@ } } }, + "universalify": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.1.tgz", + "integrity": "sha1-+nG63UQ3r0wUiEHjs7Fl+enlkLc=", + "dev": true + }, "unset-value": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unset-value/-/unset-value-1.0.0.tgz", diff --git a/package.json b/package.json index 240bcf9..6f4ae44 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,25 @@ { "name": "tabidisco", - "version": "0.1.0", "private": true, + "version": "0.1.0", + "description": "Jukebox for kids powered by Raspberry Pi", + "homepage": "https://github.com/phjardas/tabidisco", + "repository": { + "type": "git", + "url": "https://github.com/phjardas/tabidisco" + }, + "bugs": { + "url": "https://github.com/phjardas/tabidisco/issues" + }, + "license": "MIT", + "author": { + "name": "Philipp Jardas", + "email": "philipp@jardas.de", + "url": "https://github.com/phjardas" + }, "scripts": { "postinstall": "check-engine && (cd gui && npm install) && (cd server && npm install)", - "build": "(cd gui && npm run build) && (cd server && npm run build)", + "build": "check-engine && (cd gui && npm run build) && (cd server && npm run build)", "start": "check-engine && concurrently --kill-others 'npm run start:server' 'npm run start:gui'", "start:server": "(cd server && npm run dev)", "start:gui": "(cd gui && npm start)", @@ -19,11 +34,18 @@ "check-engine": "^1.7.0", "concurrently": "^3.5.1", "fixme": "^0.4.5", + "fs-extra": "^5.0.0", "husky": "^0.14.3", "lint-staged": "^7.0.0", "prettier": "^1.11.1" }, + "bin": { + "tabidisco": "./bin/tabidisco" + }, "lint-staged": { - "{server,gui}/src/**/*.{ts,tsx,js,jsx,json,css}": ["prettier --write", "git add"] + "{server,gui}/src/**/*.{ts,tsx,js,jsx,json,css}": [ + "prettier --write", + "git add" + ] } } diff --git a/publish.sh b/publish.sh new file mode 100755 index 0000000..56d6b15 --- /dev/null +++ b/publish.sh @@ -0,0 +1,5 @@ +#!/bin/bash -e +npm install +npm run build +node bundle.js +(cd npm && npm publish)