From f51cb15da74e598848dd1f6a0d8b3ee0de78c72b Mon Sep 17 00:00:00 2001 From: szbk Date: Sat, 23 Mar 2024 14:56:45 +0300 Subject: [PATCH] Svelte UI Update --- .env.development | 1 + .env.production | 1 + .gitignore | 26 +++++++++- Dockerfile | 17 ------- README.md | 47 +++++++++++++++++++ .dockerignore => api/.dockerignore | 0 api/.gitignore | 22 +++++++++ app.js => api/app.js | 0 {configs => api/configs}/index.js | 0 .../controller}/device.get.controller.js | 0 .../controller}/device.log.controller.js | 0 .../controller}/device.set.controller.js | 0 .../controller}/save.controller.js | 0 docker-compose.yml => api/docker-compose.yml | 0 {library => api/library}/index.js | 0 {models => api/models}/device.model.js | 0 api/package.json | 25 ++++++++++ {route => api/route}/device.get.route.js | 0 {route => api/route}/device.log.route.js | 0 {route => api/route}/device.set.route.js | 0 {route => api/route}/save.route.js | 0 index.html | 13 +++++ jsconfig.json | 32 +++++++++++++ package.json | 37 +++++++-------- public/vite.svg | 1 + src/App.svelte | 33 +++++++++++++ src/app.css | 17 +++++++ src/assets/svelte.svg | 1 + src/components/DeviceDetails.svelte | 31 ++++++++++++ src/components/Header.svelte | 14 ++++++ src/components/Item.svelte | 0 src/main.js | 8 ++++ src/vite-env.d.ts | 2 + svelte.config.js | 7 +++ vite.config.js | 18 +++++++ 35 files changed, 314 insertions(+), 39 deletions(-) create mode 100644 .env.development create mode 100644 .env.production delete mode 100644 Dockerfile create mode 100644 README.md rename .dockerignore => api/.dockerignore (100%) create mode 100644 api/.gitignore rename app.js => api/app.js (100%) rename {configs => api/configs}/index.js (100%) rename {controller => api/controller}/device.get.controller.js (100%) rename {controller => api/controller}/device.log.controller.js (100%) rename {controller => api/controller}/device.set.controller.js (100%) rename {controller => api/controller}/save.controller.js (100%) rename docker-compose.yml => api/docker-compose.yml (100%) rename {library => api/library}/index.js (100%) rename {models => api/models}/device.model.js (100%) create mode 100644 api/package.json rename {route => api/route}/device.get.route.js (100%) rename {route => api/route}/device.log.route.js (100%) rename {route => api/route}/device.set.route.js (100%) rename {route => api/route}/save.route.js (100%) create mode 100644 index.html create mode 100644 jsconfig.json create mode 100644 public/vite.svg create mode 100644 src/App.svelte create mode 100644 src/app.css create mode 100644 src/assets/svelte.svg create mode 100644 src/components/DeviceDetails.svelte create mode 100644 src/components/Header.svelte create mode 100644 src/components/Item.svelte create mode 100644 src/main.js create mode 100644 src/vite-env.d.ts create mode 100644 svelte.config.js create mode 100644 vite.config.js diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..3d9f576 --- /dev/null +++ b/.env.development @@ -0,0 +1 @@ +VITE_API_URL=http://localhost:9095/api/get/R8Re9mMYDTMbPa2kkgueZtoSg \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..ea8e3f7 --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +VITE_API_URL=/api/get/R8Re9mMYDTMbPa2kkgueZtoSg \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7650795..b7c6c3e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,27 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? node_modules/ public/src/thumbs public/avatars/ @@ -19,4 +43,4 @@ Procfile dump.rdb error.log output.log -Dockerfile \ No newline at end of file +Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 177bd53..0000000 --- a/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM node:21.5.0 - -RUN mkdir /smarthome -WORKDIR /smarthome - -# RUN npm install -g forever -RUN npm install -g nodemon - -COPY package.json /smarthome -RUN npm install - -COPY . /smarthome - -EXPOSE 9095 - -# CMD ["forever","app.js", "9095"] -CMD ["nodemon","app.js", "9095"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..382941e --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# Svelte + Vite + +This template should help get you started developing with Svelte in Vite. + +## Recommended IDE Setup + +[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). + +## Need an official Svelte framework? + +Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more. + +## Technical considerations + +**Why use this over SvelteKit?** + +- It brings its own routing solution which might not be preferable for some users. +- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app. + +This template contains as little as possible to get started with Vite + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project. + +Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate. + +**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?** + +Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information. + +**Why include `.vscode/extensions.json`?** + +Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project. + +**Why enable `checkJs` in the JS template?** + +It is likely that most cases of changing variable types in runtime are likely to be accidental, rather than deliberate. This provides advanced typechecking out of the box. Should you like to take advantage of the dynamically-typed nature of JavaScript, it is trivial to change the configuration. + +**Why is HMR not preserving my local component state?** + +HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/sveltejs/svelte-hmr/tree/master/packages/svelte-hmr#preservation-of-local-state). + +If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR. + +```js +// store.js +// An extremely simple external store +import { writable } from 'svelte/store' +export default writable(0) +``` diff --git a/.dockerignore b/api/.dockerignore similarity index 100% rename from .dockerignore rename to api/.dockerignore diff --git a/api/.gitignore b/api/.gitignore new file mode 100644 index 0000000..7650795 --- /dev/null +++ b/api/.gitignore @@ -0,0 +1,22 @@ +node_modules/ +public/src/thumbs +public/avatars/ +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db +package-lock.json +.env +.env-mongo +.vscode/ +settings.json +Procfile +dump.rdb +error.log +output.log +Dockerfile \ No newline at end of file diff --git a/app.js b/api/app.js similarity index 100% rename from app.js rename to api/app.js diff --git a/configs/index.js b/api/configs/index.js similarity index 100% rename from configs/index.js rename to api/configs/index.js diff --git a/controller/device.get.controller.js b/api/controller/device.get.controller.js similarity index 100% rename from controller/device.get.controller.js rename to api/controller/device.get.controller.js diff --git a/controller/device.log.controller.js b/api/controller/device.log.controller.js similarity index 100% rename from controller/device.log.controller.js rename to api/controller/device.log.controller.js diff --git a/controller/device.set.controller.js b/api/controller/device.set.controller.js similarity index 100% rename from controller/device.set.controller.js rename to api/controller/device.set.controller.js diff --git a/controller/save.controller.js b/api/controller/save.controller.js similarity index 100% rename from controller/save.controller.js rename to api/controller/save.controller.js diff --git a/docker-compose.yml b/api/docker-compose.yml similarity index 100% rename from docker-compose.yml rename to api/docker-compose.yml diff --git a/library/index.js b/api/library/index.js similarity index 100% rename from library/index.js rename to api/library/index.js diff --git a/models/device.model.js b/api/models/device.model.js similarity index 100% rename from models/device.model.js rename to api/models/device.model.js diff --git a/api/package.json b/api/package.json new file mode 100644 index 0000000..9b1abf0 --- /dev/null +++ b/api/package.json @@ -0,0 +1,25 @@ +{ + "dependencies": { + "chalk": "^4.0.0", + "cors": "^2.8.5", + "create-react-app": "^5.0.1", + "dotenv": "^16.4.5", + "express": "^4.18.2", + "helmet": "^7.1.0", + "mongoose": "^8.2.0", + "morgan": "^1.10.0", + "node-fetch": "^2.7.0", + "nodemon": "^3.1.0", + "socket.io": "^4.7.4" + }, + "name": "wisecolt-mancmini", + "version": "1.0.0", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "keywords": [], + "description": "" +} diff --git a/route/device.get.route.js b/api/route/device.get.route.js similarity index 100% rename from route/device.get.route.js rename to api/route/device.get.route.js diff --git a/route/device.log.route.js b/api/route/device.log.route.js similarity index 100% rename from route/device.log.route.js rename to api/route/device.log.route.js diff --git a/route/device.set.route.js b/api/route/device.set.route.js similarity index 100% rename from route/device.set.route.js rename to api/route/device.set.route.js diff --git a/route/save.route.js b/api/route/save.route.js similarity index 100% rename from route/save.route.js rename to api/route/save.route.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..feaf27c --- /dev/null +++ b/index.html @@ -0,0 +1,13 @@ + + + + + + + Vite + Svelte + + +
+ + + diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 0000000..5696a2d --- /dev/null +++ b/jsconfig.json @@ -0,0 +1,32 @@ +{ + "compilerOptions": { + "moduleResolution": "bundler", + "target": "ESNext", + "module": "ESNext", + /** + * svelte-preprocess cannot figure out whether you have + * a value or a type, so tell TypeScript to enforce using + * `import type` instead of `import` for Types. + */ + "verbatimModuleSyntax": true, + "isolatedModules": true, + "resolveJsonModule": true, + /** + * To have warnings / errors of the Svelte compiler at the + * correct position, enable source maps by default. + */ + "sourceMap": true, + "esModuleInterop": true, + "skipLibCheck": true, + /** + * Typecheck JS in `.svelte` and `.js` files by default. + * Disable this if you'd like to use dynamic types. + */ + "checkJs": true + }, + /** + * Use global.d.ts instead of compilerOptions.types + * to avoid limiting type declarations. + */ + "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"] +} diff --git a/package.json b/package.json index 9b1abf0..ce12ba1 100644 --- a/package.json +++ b/package.json @@ -1,25 +1,20 @@ { - "dependencies": { - "chalk": "^4.0.0", - "cors": "^2.8.5", - "create-react-app": "^5.0.1", - "dotenv": "^16.4.5", - "express": "^4.18.2", - "helmet": "^7.1.0", - "mongoose": "^8.2.0", - "morgan": "^1.10.0", - "node-fetch": "^2.7.0", - "nodemon": "^3.1.0", - "socket.io": "^4.7.4" - }, - "name": "wisecolt-mancmini", - "version": "1.0.0", - "main": "app.js", + "name": "smarthome-web", + "proxy": "http://localhost:9095", + "private": true, + "version": "0.0.0", + "type": "module", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "dev": "vite", + "build": "rm -rf api/build && vite build --out-dir api/build && rm -rf dist", + "preview": "vite preview" }, - "author": "", - "license": "ISC", - "keywords": [], - "description": "" + "devDependencies": { + "@sveltejs/vite-plugin-svelte": "^3.0.2", + "svelte": "^4.2.12", + "vite": "^5.2.3" + }, + "dependencies": { + "svelte-routing": "^2.12.0" + } } diff --git a/public/vite.svg b/public/vite.svg new file mode 100644 index 0000000..e7b8dfb --- /dev/null +++ b/public/vite.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/App.svelte b/src/App.svelte new file mode 100644 index 0000000..973283d --- /dev/null +++ b/src/App.svelte @@ -0,0 +1,33 @@ + + +
+ + + + diff --git a/src/app.css b/src/app.css new file mode 100644 index 0000000..8775980 --- /dev/null +++ b/src/app.css @@ -0,0 +1,17 @@ +:root { + font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; + line-height: 1.5; + font-weight: 400; + + color-scheme: light dark; + + font-synthesis: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +body { + margin: 0; + padding: 0; +} \ No newline at end of file diff --git a/src/assets/svelte.svg b/src/assets/svelte.svg new file mode 100644 index 0000000..c5e0848 --- /dev/null +++ b/src/assets/svelte.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/DeviceDetails.svelte b/src/components/DeviceDetails.svelte new file mode 100644 index 0000000..f348e0b --- /dev/null +++ b/src/components/DeviceDetails.svelte @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + {#each $devices as device} + + + + + + + + + + {/each} + +
NameTypeManifactorSerial NumberModelFirmware VersionDevice IP Address
{device.device_name}{device.device_type}{device.manifactor}{device.serial_number}{device.model}{device.firmware_version}{device.device_ip_address}
diff --git a/src/components/Header.svelte b/src/components/Header.svelte new file mode 100644 index 0000000..1a7aeaf --- /dev/null +++ b/src/components/Header.svelte @@ -0,0 +1,14 @@ + +
SMART HOME
+ + diff --git a/src/components/Item.svelte b/src/components/Item.svelte new file mode 100644 index 0000000..e69de29 diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..8a909a1 --- /dev/null +++ b/src/main.js @@ -0,0 +1,8 @@ +import './app.css' +import App from './App.svelte' + +const app = new App({ + target: document.getElementById('app'), +}) + +export default app diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts new file mode 100644 index 0000000..4078e74 --- /dev/null +++ b/src/vite-env.d.ts @@ -0,0 +1,2 @@ +/// +/// diff --git a/svelte.config.js b/svelte.config.js new file mode 100644 index 0000000..b0683fd --- /dev/null +++ b/svelte.config.js @@ -0,0 +1,7 @@ +import { vitePreprocess } from '@sveltejs/vite-plugin-svelte' + +export default { + // Consult https://svelte.dev/docs#compile-time-svelte-preprocess + // for more information about preprocessors + preprocess: vitePreprocess(), +} diff --git a/vite.config.js b/vite.config.js new file mode 100644 index 0000000..7dc70e0 --- /dev/null +++ b/vite.config.js @@ -0,0 +1,18 @@ +import { defineConfig } from 'vite' +import { svelte } from '@sveltejs/vite-plugin-svelte' + +export default defineConfig({ + plugins: [svelte()], + server: { + env: { + // Geliştirme ortamında .env.dev dosyasını kullan + VITE_API_URL: process.env.VITE_API_URL + } + }, + build: { + env: { + // Üretim ortamında .env.prod dosyasını kullan + VITE_API_URL: process.env.VITE_API_URL + } + } +})