Merge branch 'main' of https://git.odit.services/lfk/scanclient into main
# Conflicts: # .gitignore # README.md # main.js # package.json
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								public/favicon.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								public/favicon.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 70 KiB | 
							
								
								
									
										1
									
								
								public/global.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								public/global.css
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										20
									
								
								public/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								public/index.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| <!DOCTYPE html> | ||||
| <html lang="en"> | ||||
|  | ||||
| <head> | ||||
| 	<meta charset="utf-8"> | ||||
| 	<meta name="viewport" content="width=device-width,initial-scale=1"> | ||||
|  | ||||
| 	<title>LfK!Scan</title> | ||||
|  | ||||
| 	<link rel="icon" type="image/png" href="/favicon.png"> | ||||
| 	<link rel="stylesheet" href="/global.css"> | ||||
| 	<link rel="stylesheet" href="/build/bundle.css"> | ||||
|  | ||||
| 	<script defer src="/build/bundle.js"></script> | ||||
| </head> | ||||
|  | ||||
| <body> | ||||
| </body> | ||||
|  | ||||
| </html> | ||||
							
								
								
									
										
											BIN
										
									
								
								public/svelte.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								public/svelte.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 21 KiB | 
							
								
								
									
										75
									
								
								rollup.config.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								rollup.config.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,75 @@ | ||||
| import svelte from 'rollup-plugin-svelte'; | ||||
| import resolve from '@rollup/plugin-node-resolve'; | ||||
| import commonjs from '@rollup/plugin-commonjs'; | ||||
| import livereload from 'rollup-plugin-livereload'; | ||||
| import { terser } from 'rollup-plugin-terser'; | ||||
|  | ||||
| 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({ | ||||
| 			// 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: css => { | ||||
| 				css.write('public/build/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 | ||||
| 	} | ||||
| }; | ||||
							
								
								
									
										125
									
								
								scripts/setupTypeScript.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										125
									
								
								scripts/setupTypeScript.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,125 @@ | ||||
| // @ts-check | ||||
|  | ||||
| /** This script modifies the project to support TS code in .svelte files like: | ||||
|  | ||||
|   <script lang="ts"> | ||||
|   	export let name: string; | ||||
|   </script> | ||||
|   | ||||
|   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": "^1.0.0", | ||||
|   "svelte-preprocess": "^4.0.0", | ||||
|   "@rollup/plugin-typescript": "^4.0.0", | ||||
|   "typescript": "^3.9.3", | ||||
|   "tslib": "^2.0.0", | ||||
|   "@tsconfig/svelte": "^1.0.0" | ||||
| }) | ||||
|  | ||||
| // Add script for checking | ||||
| packageJSON.scripts = Object.assign(packageJSON.scripts, { | ||||
|   "validate": "svelte-check" | ||||
| }) | ||||
|  | ||||
| // 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("<script>", '<script lang="ts">') | ||||
| appFile = appFile.replace("export let name;", 'export let name: string;') | ||||
| fs.writeFileSync(appSveltePath, appFile) | ||||
|  | ||||
| // Edit rollup config | ||||
| const rollupConfigPath = path.join(projectRoot, "rollup.config.js") | ||||
| let rollupConfig = fs.readFileSync(rollupConfigPath, "utf8") | ||||
|  | ||||
| // Edit imports | ||||
| rollupConfig = rollupConfig.replace(`'rollup-plugin-terser';`, `'rollup-plugin-terser'; | ||||
| import sveltePreprocess from 'svelte-preprocess'; | ||||
| import typescript from '@rollup/plugin-typescript';`) | ||||
|  | ||||
| // Replace name of entry point | ||||
| rollupConfig = rollupConfig.replace(`'src/main.js'`, `'src/main.ts'`) | ||||
|  | ||||
| // Add preprocess to the svelte config, this is tricky because there's no easy signifier. | ||||
| // Instead we look for `css:` then the next `}` and add the preprocessor to that | ||||
| let foundCSS = false | ||||
| let match | ||||
|  | ||||
| // https://regex101.com/r/OtNjwo/1 | ||||
| const configEditor = new RegExp(/css:.|\n*}/gmi) | ||||
| while (( match = configEditor.exec(rollupConfig)) != null) { | ||||
|   if (foundCSS) { | ||||
|     const endOfCSSIndex = match.index + 1 | ||||
|     rollupConfig = rollupConfig.slice(0, endOfCSSIndex) + ",\n			preprocess: sveltePreprocess()," + rollupConfig.slice(endOfCSSIndex); | ||||
|     break | ||||
|   } | ||||
|   if (match[0].includes("css:")) foundCSS = true | ||||
| } | ||||
|  | ||||
|  | ||||
| // Add TypeScript | ||||
| rollupConfig = rollupConfig.replace("commonjs(),", 'commonjs(),\n\t\ttypescript({ sourceMap: !production }),') | ||||
| fs.writeFileSync(rollupConfigPath, rollupConfig) | ||||
|  | ||||
| // Add TSConfig | ||||
| const tsconfig = `{ | ||||
|   "extends": "@tsconfig/svelte/tsconfig.json", | ||||
|  | ||||
|   "include": ["src/**/*"], | ||||
|   "exclude": ["node_modules/*", "__sapper__/*", "public/*"], | ||||
| }` | ||||
| const tsconfigPath =  path.join(projectRoot, "tsconfig.json") | ||||
| fs.writeFileSync(tsconfigPath, tsconfig) | ||||
|  | ||||
| // Delete this script, but not during testing | ||||
| if (!argv[2]) { | ||||
|   // Remove the script | ||||
|   fs.unlinkSync(path.join(__filename)) | ||||
|  | ||||
|   // Check for Mac's DS_store file, and if it's the only one left remove it | ||||
|   const remainingFiles = fs.readdirSync(path.join(__dirname)) | ||||
|   if (remainingFiles.length === 1 && remainingFiles[0] === '.DS_store') { | ||||
|     fs.unlinkSync(path.join(__dirname, '.DS_store')) | ||||
|   } | ||||
|  | ||||
|   // Check if the scripts folder is empty | ||||
|   if (fs.readdirSync(path.join(__dirname)).length === 0) { | ||||
|     // Remove the scripts folder | ||||
|     fs.rmdirSync(path.join(__dirname)) | ||||
|   } | ||||
| } | ||||
|  | ||||
| // Adds the extension recommendation | ||||
| fs.mkdirSync(path.join(projectRoot, ".vscode")) | ||||
| fs.writeFileSync(path.join(projectRoot, ".vscode", "extensions.json"), `{ | ||||
|   "recommendations": ["svelte.svelte-vscode"] | ||||
| } | ||||
| `) | ||||
|  | ||||
| console.log("Converted to TypeScript.") | ||||
|  | ||||
| if (fs.existsSync(path.join(projectRoot, "node_modules"))) { | ||||
|   console.log("\nYou will need to re-run your dependency manager to get started.") | ||||
| } | ||||
							
								
								
									
										31
									
								
								src/App.svelte
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								src/App.svelte
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| <header class="navbar"> | ||||
| 	<section class="navbar-section"> | ||||
| 	  <a href="#" class="btn btn-link">Docs</a> | ||||
| 	  <a href="#" class="btn btn-link">Examples</a> | ||||
| 	</section> | ||||
| 	<div class="navbar-center"><img src="/favicon.png" style="height:4rem;" alt="Spectre.css"></div> | ||||
| 	<section class="navbar-section"> | ||||
| 	  <a href="#" class="btn btn-link">Twitter</a> | ||||
| 	  <a href="#" class="btn btn-link">GitHub</a> | ||||
| 	</section> | ||||
|   </header> | ||||
| <main> | ||||
| 	<div class="hero hero-sm bg-dark"> | ||||
| 		<div class="hero-body"> | ||||
| 			<h1><img src="/favicon.png" alt="Logo" style="height: 5rem;vertical-align: middle;"><span style="vertical-align: middle;">LfK!Scan</span></h1> | ||||
| 			<p>Lauf für Kaya! Scanstation</p> | ||||
| 		</div> | ||||
| 	</div> | ||||
| 	<div style="padding:1rem;"> | ||||
| 		<div class="column col-12"> | ||||
| 			<h3>Configure Scanstation <a target="_blank" href="https://docs.lauf-fuer-kaya.de/"><small class="label">📃 take a look at the configuration guide</small></a></h3> | ||||
| 		</div> | ||||
| 		<div class="column col-6 col-xs-12"> | ||||
| 		  <div class="form-group"> | ||||
| 			<label class="form-label" for="input-example-1">Token</label> | ||||
| 			<input class="form-input" id="input-example-1" type="text" placeholder="Token"> | ||||
| 		  </div> | ||||
| 		  <button class="btn btn-primary input-group-btn btn-lg">Submit</button> | ||||
| 		</div> | ||||
| 	  </div> | ||||
| </main> | ||||
							
								
								
									
										10
									
								
								src/main.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/main.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| import App from './App.svelte'; | ||||
|  | ||||
| const app = new App({ | ||||
| 	target: document.body, | ||||
| 	props: { | ||||
| 		appName: 'Electron-Svelte' | ||||
| 	} | ||||
| }); | ||||
|  | ||||
| export default app; | ||||
		Reference in New Issue
	
	Block a user