Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: add SvelteKit example #5181

Merged
merged 8 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ node_modules/
*.cjs
*.mjs
!private/js2ts/*
!examples/svelte-example/*
*.lock
CHANGELOG.md
15 changes: 10 additions & 5 deletions examples/svelte-example/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/node_modules/
/uploads/
/public/build/

.DS_Store
package-lock.json
node_modules
/build
/uploads/
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
/.svelte-kit
/package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
2 changes: 1 addition & 1 deletion examples/svelte-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ corepack yarn build
Then, again in the **repository root**, start this example by doing:

```sh
corepack yarn workspace @uppy-example/svelte-app start
corepack yarn workspace @uppy-example/svelte-app dev
```
44 changes: 18 additions & 26 deletions examples/svelte-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,33 @@
"name": "@uppy-example/svelte-app",
"version": "0.0.0",
"scripts": {
"build": "rollup -c",
"serve": "sirv public",
"start:client": "rollup -c -w",
"start:server": "node ./server.mjs",
"start": "npm-run-all --parallel start:client start:server",
"validate": "svelte-check"
"dev": "npm-run-all --parallel dev:frontend dev:backend",
"dev:frontend": "vite dev",
"dev:backend": "node --watch ./server.js",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-typescript": "^8.0.0",
"@tsconfig/svelte": "^1.0.0",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/formidable": "^3",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.31",
"postcss-import": "^13.0.0",
"postcss-load-config": "^3.0.0",
"rollup": "^2.60.2",
"rollup-plugin-css-only": "^3.0.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-svelte": "^7.0.0",
"rollup-plugin-terser": "^7.0.0",
"svelte": ">=3.24.0",
"svelte-check": "^1.6.0",
"svelte-preprocess": "^5.0.0",
"tslib": "^2.0.0",
"typescript": "~5.4"
"svelte": "^4.2.7",
"svelte-check": "^3.6.0",
"tslib": "^2.4.1",
"typescript": "~5.4",
"vite": "^5.0.0"
},
"dependencies": {
"@uppy/core": "workspace:*",
"@uppy/svelte": "workspace:*",
"@uppy/webcam": "workspace:*",
"@uppy/xhr-upload": "workspace:*",
"formidable": "^2.0.1",
"sirv-cli": "^1.0.0"
"formidable": "^3.5.1"
},
"type": "module",
"private": true
}
6 changes: 0 additions & 6 deletions examples/svelte-example/postcss.config.js

This file was deleted.

68 changes: 0 additions & 68 deletions examples/svelte-example/public/global.css

This file was deleted.

16 changes: 0 additions & 16 deletions examples/svelte-example/public/index.html

This file was deleted.

86 changes: 0 additions & 86 deletions examples/svelte-example/rollup.config.js

This file was deleted.

64 changes: 64 additions & 0 deletions examples/svelte-example/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env node

/* eslint-disable no-console */

import http from 'node:http'
import { fileURLToPath } from 'node:url'
import { mkdir } from 'node:fs/promises'

import formidable from 'formidable'

const UPLOAD_DIR = new URL('./uploads/', import.meta.url)

await mkdir(UPLOAD_DIR, { recursive: true })

http
.createServer((req, res) => {
const headers = {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'OPTIONS, POST, GET',
'Access-Control-Max-Age': 2592000, // 30 days
/** add other headers as per requirement */
}

if (req.method === 'OPTIONS') {
res.writeHead(204, headers)
res.end()
return
}
if (req.url === '/upload' && req.method.toLowerCase() === 'post') {
// parse a file upload
const form = formidable({
keepExtensions: true,
uploadDir: fileURLToPath(UPLOAD_DIR),
})

form.parse(req, (err, fields, files) => {
res.writeHead(200, headers)
if (err) {
console.log('some error', err)
res.write(JSON.stringify(err))
} else {
for (const {
filepath,
originalFilename,
mimetype,
size,
} of files.files) {
console.log('saved file', {
filepath,
originalFilename,
mimetype,
size,
})
}
res.write(JSON.stringify({ fields, files }))
}
res.end()
})
}
})
.listen(9967, () => {
console.log('server started')
})
52 changes: 0 additions & 52 deletions examples/svelte-example/server.mjs

This file was deleted.

Loading
Loading