From fd01385fe8013eaf4c10ab72f7cfad8a58314a56 Mon Sep 17 00:00:00 2001 From: Thomas Cole Date: Fri, 8 Apr 2022 14:19:00 -0400 Subject: [PATCH] First Code dump --- .gitignore | 4 + README.md | 2 +- apps/server/.env.sample | 2 + apps/server/api/debug/routes.js | 20 +++++ apps/server/api/routes.js | 15 ++++ apps/server/api/set/routes.js | 8 ++ apps/server/api/unset/routes.js | 8 ++ apps/server/index.js | 29 +++++++ apps/server/package.json | 20 +++++ apps/web/.gitignore | 4 + apps/web/README.md | 109 +++++++++++++++++++++++++ apps/web/package.json | 24 ++++++ apps/web/public/favicon.png | Bin 0 -> 3127 bytes apps/web/public/global.css | 63 +++++++++++++++ apps/web/public/index.html | 18 +++++ apps/web/rollup.config.js | 76 +++++++++++++++++ apps/web/scripts/setupTypeScript.js | 121 ++++++++++++++++++++++++++++ apps/web/src/App.svelte | 40 +++++++++ apps/web/src/main.js | 10 +++ package.json | 46 +++++++++++ 20 files changed, 618 insertions(+), 1 deletion(-) create mode 100644 apps/server/.env.sample create mode 100644 apps/server/api/debug/routes.js create mode 100644 apps/server/api/routes.js create mode 100644 apps/server/api/set/routes.js create mode 100644 apps/server/api/unset/routes.js create mode 100644 apps/server/index.js create mode 100644 apps/server/package.json create mode 100644 apps/web/.gitignore create mode 100644 apps/web/README.md create mode 100644 apps/web/package.json create mode 100644 apps/web/public/favicon.png create mode 100644 apps/web/public/global.css create mode 100644 apps/web/public/index.html create mode 100644 apps/web/rollup.config.js create mode 100644 apps/web/scripts/setupTypeScript.js create mode 100644 apps/web/src/App.svelte create mode 100644 apps/web/src/main.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index ceaea36..732b9da 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,7 @@ dist .yarn/install-state.gz .pnp.* +build/** +dist/** +.turbo +package-lock.json \ No newline at end of file diff --git a/README.md b/README.md index 7e5b452..55c0391 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # yasd -Yet another stream deck. \ No newline at end of file +Yet another stream deck. diff --git a/apps/server/.env.sample b/apps/server/.env.sample new file mode 100644 index 0000000..a942373 --- /dev/null +++ b/apps/server/.env.sample @@ -0,0 +1,2 @@ +#Port you want the server to run on. It is best to use something uncomon +PORT=8899 \ No newline at end of file diff --git a/apps/server/api/debug/routes.js b/apps/server/api/debug/routes.js new file mode 100644 index 0000000..fd3b11a --- /dev/null +++ b/apps/server/api/debug/routes.js @@ -0,0 +1,20 @@ +const express = require('express'); +const router = express.Router(); + +router.get('/', (req, res) => { + res.status(200).send("Debug"); +}); + +router.get('/showconfig', (req, res)=>{ + res.status(200).send('CONFIG DATA'); +}); + +router.post('/clearscreen', (req, res)=>{ + res.sendStatus(200); +}); + +router.post('/resetconfig', (req, res)=> { + res.status(200).send('CONFIG RESET'); +}); + +module.exports = router; \ No newline at end of file diff --git a/apps/server/api/routes.js b/apps/server/api/routes.js new file mode 100644 index 0000000..27c4910 --- /dev/null +++ b/apps/server/api/routes.js @@ -0,0 +1,15 @@ +const express = require('express') +const router = express.Router(); +const debugRoutes = require('./debug/routes'); +const setRoutes = require('./set/routes'); +const unsetRoutes = require('./unset/routes'); + +router.get('/', (req, res) => { + res.sendStatus(200); +}); + +router.use('/debug', debugRoutes); +router.use('/set', setRoutes); +router.use('/unset', unsetRoutes); + +module.exports = router; \ No newline at end of file diff --git a/apps/server/api/set/routes.js b/apps/server/api/set/routes.js new file mode 100644 index 0000000..4926b17 --- /dev/null +++ b/apps/server/api/set/routes.js @@ -0,0 +1,8 @@ +const express = require('express'); +const router = express.Router(); + +router.get('/', (req, res) => { + res.status(200).send("Set"); +}); + +module.exports = router; \ No newline at end of file diff --git a/apps/server/api/unset/routes.js b/apps/server/api/unset/routes.js new file mode 100644 index 0000000..b908ab2 --- /dev/null +++ b/apps/server/api/unset/routes.js @@ -0,0 +1,8 @@ +const express = require('express'); +const router = express.Router(); + +router.get('/', (req, res) => { + res.status(200).send("Unset"); +}); + +module.exports = router; \ No newline at end of file diff --git a/apps/server/index.js b/apps/server/index.js new file mode 100644 index 0000000..fe3582a --- /dev/null +++ b/apps/server/index.js @@ -0,0 +1,29 @@ +require('dotenv').config(); +const express = require('express'); +const cors = require('cors'); +const app = express(); +const port = process.env.PORT; +const apiRoutes = require('./api/routes'); +const { openStreamDeck } = require('@elgato-stream-deck/node'); + +const myStreamDeck = openStreamDeck(); + +myStreamDeck.on('down', (keyIndex) => { + console.log('key %d down', keyIndex) +}) + +myStreamDeck.on('up', (keyIndex) => { + console.log('key %d up', keyIndex) +}) + +app.use(cors()) + +app.get('/', (req, res) => { + res.status(200).send({some: 'json'}); +}); + +app.use('/api', apiRoutes); + +app.listen(port, () => { + console.log(`Stream deck server listening on port ${port}`); +}); \ No newline at end of file diff --git a/apps/server/package.json b/apps/server/package.json new file mode 100644 index 0000000..dbb05e2 --- /dev/null +++ b/apps/server/package.json @@ -0,0 +1,20 @@ +{ + "name": "server", + "version": "0.0.1", + "private": true, + "scripts": { + "dev": "nodemon index.js", + "start": "node index.js" + }, + "dependencies": { + "@elgato-stream-deck/node": "5.3.1", + "express": "^4.17.3", + "cors": "^2.8.5", + "open": "^8.4.0", + "robotjs": "^0.6.0", + "dotenv": "16.0.0" + }, + "devDependencies": { + "nodemon": "^2.0.15" + } + } \ No newline at end of file diff --git a/apps/web/.gitignore b/apps/web/.gitignore new file mode 100644 index 0000000..da93220 --- /dev/null +++ b/apps/web/.gitignore @@ -0,0 +1,4 @@ +/node_modules/ +/public/build/ + +.DS_Store diff --git a/apps/web/README.md b/apps/web/README.md new file mode 100644 index 0000000..8ca4fca --- /dev/null +++ b/apps/web/README.md @@ -0,0 +1,109 @@ +*Psst — looking for a more complete solution? Check out [SvelteKit](https://kit.svelte.dev), the official framework for building web applications of all sizes, with a beautiful development experience and flexible filesystem-based routing.* + +*Looking for a shareable component template instead? You can [use SvelteKit for that as well](https://kit.svelte.dev/docs#packaging) or the older [sveltejs/component-template](https://github.com/sveltejs/component-template)* + +--- + +# svelte app + +This is a project template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/sveltejs/template. + +To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit): + +```bash +npx degit sveltejs/template svelte-app +cd svelte-app +``` + +*Note that you will need to have [Node.js](https://nodejs.org) installed.* + + +## Get started + +Install the dependencies... + +```bash +cd svelte-app +npm install +``` + +...then start [Rollup](https://rollupjs.org): + +```bash +npm run dev +``` + +Navigate to [localhost:8080](http://localhost:8080). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes. + +By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the `sirv` commands in package.json to include the option `--host 0.0.0.0`. + +If you're using [Visual Studio Code](https://code.visualstudio.com/) we recommend installing the official extension [Svelte for VS Code](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). If you are using other editors you may need to install a plugin in order to get syntax highlighting and intellisense. + +## Building and running in production mode + +To create an optimised version of the app: + +```bash +npm run build +``` + +You can run the newly built app with `npm run start`. This uses [sirv](https://github.com/lukeed/sirv), which is included in your package.json's `dependencies` so that the app will work when you deploy to platforms like [Heroku](https://heroku.com). + + +## Single-page app mode + +By default, sirv will only respond to requests that match files in `public`. This is to maximise compatibility with static fileservers, allowing you to deploy your app anywhere. + +If you're building a single-page app (SPA) with multiple routes, sirv needs to be able to respond to requests for *any* path. You can make it so by editing the `"start"` command in package.json: + +```js +"start": "sirv public --single" +``` + +## Using TypeScript + +This template comes with a script to set up a TypeScript development environment, you can run it immediately after cloning the template with: + +```bash +node scripts/setupTypeScript.js +``` + +Or remove the script via: + +```bash +rm scripts/setupTypeScript.js +``` + +If you want to use `baseUrl` or `path` aliases within your `tsconfig`, you need to set up `@rollup/plugin-alias` to tell Rollup to resolve the aliases. For more info, see [this StackOverflow question](https://stackoverflow.com/questions/63427935/setup-tsconfig-path-in-svelte). + +## Deploying to the web + +### With [Vercel](https://vercel.com) + +Install `vercel` if you haven't already: + +```bash +npm install -g vercel +``` + +Then, from within your project folder: + +```bash +cd public +vercel deploy --name my-project +``` + +### With [surge](https://surge.sh/) + +Install `surge` if you haven't already: + +```bash +npm install -g surge +``` + +Then, from within your project folder: + +```bash +npm run build +surge public my-project.surge.sh +``` diff --git a/apps/web/package.json b/apps/web/package.json new file mode 100644 index 0000000..41d3ed1 --- /dev/null +++ b/apps/web/package.json @@ -0,0 +1,24 @@ +{ + "name": "web", + "version": "1.0.0", + "private": true, + "scripts": { + "build": "rollup -c", + "dev": "rollup -c -w", + "start": "sirv public --no-clear" + }, + "devDependencies": { + "@rollup/plugin-commonjs": "^17.0.0", + "@rollup/plugin-node-resolve": "^11.0.0", + "rollup": "^2.3.4", + "rollup-plugin-css-only": "^3.1.0", + "rollup-plugin-livereload": "^2.0.0", + "rollup-plugin-svelte": "^7.0.0", + "rollup-plugin-terser": "^7.0.0", + "svelte": "^3.0.0" + }, + "dependencies": { + "sirv-cli": "^2.0.0", + "svelte-spa-router":"^3.2.0" + } +} diff --git a/apps/web/public/favicon.png b/apps/web/public/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..7e6f5eb5a2f1f1c882d265cf479de25caa925645 GIT binary patch literal 3127 zcmV-749N3|P)i z7)}s4L53SJCkR}iVi00SFk;`MXX*#X*kkwKs@nFGS}c;=?XFjU|G$3t^5sjIVS2G+ zw)WGF83CpoGXhLGW(1gW%uV|X7>1P6VhCX=Ux)Lb!*DZ%@I3!{Gsf7d?gtIQ%nQiK z3%(LUSkBji;C5Rfgd6$VsF@H`Pk@xtY6t<>FNR-pD}=C~$?)9pdm3XZ36N5PNWYjb z$xd$yNQR9N!dfj-Vd@BwQo^FIIWPPmT&sZyQ$v81(sCBV=PGy{0wltEjB%~h157*t zvbe_!{=I_783x!0t1-r#-d{Y?ae$Q4N_Nd^Ui^@y(%)Gjou6y<3^XJdu{rmUf-Me?)zZ>9OR&6U5H*cK; z$gUlB{g0O4gN0sLSO|Of?hU(l?;h(jA3uH!Z{EBKuV23ouU@^Y6#%v+QG;>e*E}%?wlu-NT4DG zs)z)7WbLr)vGAu(ohr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ynL&D;p(!Nmx`Y zFkHex{4p!Ggm^@DlehW}iHHVi}~u=$&N? z(NEBLQ#UxxAkdW>X9LnqUr#t4Lu0=9L8&o>JsqTtT5|%gb3QA~hr0pED71+iFFr)dZ=Q=E6ng{NE{Z~0)C?deO#?Aj zSDQ$z#TeC2T^|=}6GBo-&$;E{HL3!q3Z-szuf)O=G#zDjin4SSP%o%6+2IT#sLjQa ziyxFFz~LMjWY+_a5H!U6%a<=b7QVP^ z*90a62;bVq{?@)P6^DWd^Yilq4|YTV2Nw!Yu;a1lPI-sxR)rf@Fe5DhDP7FH zZZ%4S*1C30P;|O+jB!1;m|rXT90Sm5*RBbQN`PKu+hDD*S^yE(CdtSfg=z>u$cIj> z + + + + + + Svelte app + + + + + + + + + + + diff --git a/apps/web/rollup.config.js b/apps/web/rollup.config.js new file mode 100644 index 0000000..e8965ec --- /dev/null +++ b/apps/web/rollup.config.js @@ -0,0 +1,76 @@ +import svelte from 'rollup-plugin-svelte'; +import commonjs from '@rollup/plugin-commonjs'; +import resolve from '@rollup/plugin-node-resolve'; +import livereload from 'rollup-plugin-livereload'; +import { terser } from 'rollup-plugin-terser'; +import css from 'rollup-plugin-css-only'; + +const production = !process.env.ROLLUP_WATCH; + +function serve() { + let server; + + function toExit() { + if (server) server.kill(0); + } + + return { + writeBundle() { + if (server) return; + server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], { + stdio: ['ignore', 'inherit', 'inherit'], + shell: true + }); + + process.on('SIGTERM', toExit); + process.on('exit', toExit); + } + }; +} + +export default { + input: 'src/main.js', + output: { + sourcemap: true, + format: 'iife', + name: 'app', + file: 'public/build/bundle.js' + }, + plugins: [ + svelte({ + compilerOptions: { + // enable run-time checks when not in production + dev: !production + } + }), + // we'll extract any component CSS out into + // a separate file - better for performance + css({ output: 'bundle.css' }), + + // If you have external dependencies installed from + // npm, you'll most likely need these plugins. In + // some cases you'll need additional configuration - + // consult the documentation for details: + // https://github.com/rollup/plugins/tree/master/packages/commonjs + resolve({ + browser: true, + dedupe: ['svelte'] + }), + commonjs(), + + // In dev mode, call `npm run start` once + // the bundle has been generated + !production && serve(), + + // Watch the `public` directory and refresh the + // browser on changes when not in production + !production && livereload('public'), + + // If we're building for production (npm run build + // instead of npm run dev), minify + production && terser() + ], + watch: { + clearScreen: false + } +}; diff --git a/apps/web/scripts/setupTypeScript.js b/apps/web/scripts/setupTypeScript.js new file mode 100644 index 0000000..133658a --- /dev/null +++ b/apps/web/scripts/setupTypeScript.js @@ -0,0 +1,121 @@ +// @ts-check + +/** This script modifies the project to support TS code in .svelte files like: + + + + As well as validating the code for CI. + */ + +/** To work on this script: + rm -rf test-template template && git clone sveltejs/template test-template && node scripts/setupTypeScript.js test-template +*/ + +const fs = require("fs") +const path = require("path") +const { argv } = require("process") + +const projectRoot = argv[2] || path.join(__dirname, "..") + +// Add deps to pkg.json +const packageJSON = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf8")) +packageJSON.devDependencies = Object.assign(packageJSON.devDependencies, { + "svelte-check": "^2.0.0", + "svelte-preprocess": "^4.0.0", + "@rollup/plugin-typescript": "^8.0.0", + "typescript": "^4.0.0", + "tslib": "^2.0.0", + "@tsconfig/svelte": "^2.0.0" +}) + +// Add script for checking +packageJSON.scripts = Object.assign(packageJSON.scripts, { + "check": "svelte-check --tsconfig ./tsconfig.json" +}) + +// Write the package JSON +fs.writeFileSync(path.join(projectRoot, "package.json"), JSON.stringify(packageJSON, null, " ")) + +// mv src/main.js to main.ts - note, we need to edit rollup.config.js for this too +const beforeMainJSPath = path.join(projectRoot, "src", "main.js") +const afterMainTSPath = path.join(projectRoot, "src", "main.ts") +fs.renameSync(beforeMainJSPath, afterMainTSPath) + +// Switch the app.svelte file to use TS +const appSveltePath = path.join(projectRoot, "src", "App.svelte") +let appFile = fs.readFileSync(appSveltePath, "utf8") +appFile = appFile.replace(" + +
+

Hello {name}!

+

Visit the Svelte tutorial to learn how to build Svelte apps.

+ +

{JSON.stringify(test)}

+
+ + \ No newline at end of file diff --git a/apps/web/src/main.js b/apps/web/src/main.js new file mode 100644 index 0000000..d6cacbb --- /dev/null +++ b/apps/web/src/main.js @@ -0,0 +1,10 @@ +import App from './App.svelte'; + +const app = new App({ + target: document.body, + props: { + name: 'world' + } +}); + +export default app; \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..075913e --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "yasd", + "version": "1.0.0", + "private": true, + "workspaces": [ + "apps/*", + "packages/*" + ], + "description": "Yet another stream deck.", + "scripts": { + "build": "turbo run build --force", + "dev": "turbo run dev --parallel", + "dev:web": "turbo run dev --scope=web", + "dev:server": "turbo run dev --scope=server", + "lint": "turbo run lint", + "format": "prettier --write \"**/*.{ts,tsx,md}\"" + }, + "repository": { + "type": "git", + "url": "https://git.thomaspcole.com/thomascole/yasd.git" + }, + "author": "Thomas Cole", + "license": "MIT", + "devDependencies": { + "turbo": "^1.2.1", + "prettier": "^2.5.1" + }, + "turbo": { + "pipeline": { + "build": { + "dependsOn": [ + "^build" + ], + "outputs": [ + "dist/**" + ] + }, + "lint": { + "outputs": [] + }, + "dev": { + "cache": false + } + } + } +}