From 70de71ce7720a611c54a6439d5bfc02ef43e294e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 24 Aug 2024 15:20:01 -0400 Subject: [PATCH] rename demo -> sandbox --- playgrounds/demo/.gitignore | 4 - playgrounds/demo/package.json | 23 ---- playgrounds/demo/run.js | 98 ------------------ playgrounds/demo/tsconfig.json | 17 --- playgrounds/sandbox/.gitignore | 7 +- playgrounds/sandbox/.prettierignore | 2 - playgrounds/{demo => sandbox}/demo.css | 0 playgrounds/{demo => sandbox}/favicon.png | Bin playgrounds/{demo => sandbox}/index.html | 0 playgrounds/sandbox/input/.gitkeep | 0 playgrounds/sandbox/package.json | 24 +++-- playgrounds/sandbox/run.js | 8 +- .../scripts/create-app-svelte.js | 0 .../scripts/main.template.svelte | 0 playgrounds/{demo => sandbox}/ssr-dev.js | 0 playgrounds/{demo => sandbox}/ssr-prod.js | 0 playgrounds/sandbox/tsconfig.json | 2 +- playgrounds/{demo => sandbox}/vite.config.js | 0 18 files changed, 25 insertions(+), 160 deletions(-) delete mode 100644 playgrounds/demo/.gitignore delete mode 100644 playgrounds/demo/package.json delete mode 100644 playgrounds/demo/run.js delete mode 100644 playgrounds/demo/tsconfig.json delete mode 100644 playgrounds/sandbox/.prettierignore rename playgrounds/{demo => sandbox}/demo.css (100%) rename playgrounds/{demo => sandbox}/favicon.png (100%) rename playgrounds/{demo => sandbox}/index.html (100%) delete mode 100644 playgrounds/sandbox/input/.gitkeep rename playgrounds/{demo => sandbox}/scripts/create-app-svelte.js (100%) rename playgrounds/{demo => sandbox}/scripts/main.template.svelte (100%) rename playgrounds/{demo => sandbox}/ssr-dev.js (100%) rename playgrounds/{demo => sandbox}/ssr-prod.js (100%) rename playgrounds/{demo => sandbox}/vite.config.js (100%) diff --git a/playgrounds/demo/.gitignore b/playgrounds/demo/.gitignore deleted file mode 100644 index 5f15d95116..0000000000 --- a/playgrounds/demo/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/dist/client/* -/dist/server/* -/output -/src/* diff --git a/playgrounds/demo/package.json b/playgrounds/demo/package.json deleted file mode 100644 index 590ca1e85b..0000000000 --- a/playgrounds/demo/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "svelte-playgrounds-demo", - "private": true, - "version": "0.0.1", - "type": "module", - "scripts": { - "prepare": "node scripts/create-app-svelte.js", - "dev": "vite --host", - "ssr": "node ./ssr-dev.js", - "build": "vite build --outDir dist/client && vite build --outDir dist/server --ssr ssr-prod.js", - "prod": "npm run build && node dist/server/ssr-prod", - "preview": "vite preview" - }, - "devDependencies": { - "@sveltejs/vite-plugin-svelte": "^4.0.0-next.3", - "nodemon": "^3.0.3", - "polka": "^1.0.0-next.25", - "svelte": "workspace:*", - "tiny-glob": "^0.2.9", - "vite": "^5.0.13", - "vite-plugin-inspect": "^0.8.4" - } -} diff --git a/playgrounds/demo/run.js b/playgrounds/demo/run.js deleted file mode 100644 index 4531e7182d..0000000000 --- a/playgrounds/demo/run.js +++ /dev/null @@ -1,98 +0,0 @@ -import * as fs from 'node:fs'; -import * as path from 'node:path'; -import { fileURLToPath } from 'node:url'; -import { parseArgs } from 'node:util'; -import glob from 'tiny-glob/sync.js'; -import { compile, compileModule, parse, migrate } from 'svelte/compiler'; - -const argv = parseArgs({ options: { runes: { type: 'boolean' } }, args: process.argv.slice(2) }); - -const cwd = fileURLToPath(new URL('.', import.meta.url)).slice(0, -1); - -// empty output directory -if (fs.existsSync(`${cwd}/output`)) { - for (const file of fs.readdirSync(`${cwd}/output`)) { - if (file === '.gitkeep') continue; - try { - fs.rmSync(`${cwd}/output/${file}`, { recursive: true }); - } catch {} - } -} - -/** @param {string} dir */ -function mkdirp(dir) { - try { - fs.mkdirSync(dir, { recursive: true }); - } catch {} -} - -const svelte_modules = glob('**/*.svelte', { cwd: `${cwd}/src` }); -const js_modules = glob('**/*.js', { cwd: `${cwd}/src` }); - -for (const generate of /** @type {const} */ (['client', 'server'])) { - console.error(`\n--- generating ${generate} ---\n`); - for (const file of svelte_modules) { - const input = `${cwd}/src/${file}`; - const source = fs.readFileSync(input, 'utf-8'); - - const output_js = `${cwd}/output/${generate}/${file}.js`; - const output_map = `${cwd}/output/${generate}/${file}.js.map`; - const output_css = `${cwd}/output/${generate}/${file}.css`; - - mkdirp(path.dirname(output_js)); - - if (generate === 'client') { - const ast = parse(source, { - modern: true - }); - - fs.writeFileSync(`${cwd}/output/${file}.json`, JSON.stringify(ast, null, '\t')); - - try { - const migrated = migrate(source); - fs.writeFileSync(`${cwd}/output/${file}.migrated.svelte`, migrated.code); - } catch (e) { - console.warn(`Error migrating ${file}`, e); - } - } - - const compiled = compile(source, { - dev: true, - filename: input, - generate, - runes: argv.values.runes - }); - - for (const warning of compiled.warnings) { - console.warn(warning.code); - console.warn(warning.frame); - } - - fs.writeFileSync( - output_js, - compiled.js.code + '\n//# sourceMappingURL=' + path.basename(output_map) - ); - - fs.writeFileSync(output_map, compiled.js.map.toString()); - - if (compiled.css) { - fs.writeFileSync(output_css, compiled.css.code); - } - } - - for (const file of js_modules) { - const input = `${cwd}/src/${file}`; - const source = fs.readFileSync(input, 'utf-8'); - - const compiled = compileModule(source, { - dev: true, - filename: input, - generate - }); - - const output_js = `${cwd}/output/${generate}/${file}`; - - mkdirp(path.dirname(output_js)); - fs.writeFileSync(output_js, compiled.js.code); - } -} diff --git a/playgrounds/demo/tsconfig.json b/playgrounds/demo/tsconfig.json deleted file mode 100644 index a1566560bf..0000000000 --- a/playgrounds/demo/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "compilerOptions": { - "moduleResolution": "Bundler", - "target": "ESNext", - "module": "ESNext", - "verbatimModuleSyntax": true, - "isolatedModules": true, - "resolveJsonModule": true, - "sourceMap": true, - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "allowJs": true, - "checkJs": true - }, - "include": ["./src", "ssr-dev.js", "ssr-prod.js"] -} diff --git a/playgrounds/sandbox/.gitignore b/playgrounds/sandbox/.gitignore index f19dc155fd..5f15d95116 100644 --- a/playgrounds/sandbox/.gitignore +++ b/playgrounds/sandbox/.gitignore @@ -1,3 +1,4 @@ -input/* -output/* -!.gitkeep \ No newline at end of file +/dist/client/* +/dist/server/* +/output +/src/* diff --git a/playgrounds/sandbox/.prettierignore b/playgrounds/sandbox/.prettierignore deleted file mode 100644 index d26c5ef7f9..0000000000 --- a/playgrounds/sandbox/.prettierignore +++ /dev/null @@ -1,2 +0,0 @@ -input/**.svelte -output diff --git a/playgrounds/demo/demo.css b/playgrounds/sandbox/demo.css similarity index 100% rename from playgrounds/demo/demo.css rename to playgrounds/sandbox/demo.css diff --git a/playgrounds/demo/favicon.png b/playgrounds/sandbox/favicon.png similarity index 100% rename from playgrounds/demo/favicon.png rename to playgrounds/sandbox/favicon.png diff --git a/playgrounds/demo/index.html b/playgrounds/sandbox/index.html similarity index 100% rename from playgrounds/demo/index.html rename to playgrounds/sandbox/index.html diff --git a/playgrounds/sandbox/input/.gitkeep b/playgrounds/sandbox/input/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/playgrounds/sandbox/package.json b/playgrounds/sandbox/package.json index df9c58e530..590ca1e85b 100644 --- a/playgrounds/sandbox/package.json +++ b/playgrounds/sandbox/package.json @@ -1,15 +1,23 @@ { - "name": "svelte-playgrounds-sandbox", + "name": "svelte-playgrounds-demo", "private": true, - "type": "module", - "license": "MIT", "version": "0.0.1", + "type": "module", "scripts": { - "format": "prettier --check --write .", - "lint": "prettier --check . && eslint" + "prepare": "node scripts/create-app-svelte.js", + "dev": "vite --host", + "ssr": "node ./ssr-dev.js", + "build": "vite build --outDir dist/client && vite build --outDir dist/server --ssr ssr-prod.js", + "prod": "npm run build && node dist/server/ssr-prod", + "preview": "vite preview" }, - "dependencies": { - "svelte": "workspace:^", - "tiny-glob": "^0.2.9" + "devDependencies": { + "@sveltejs/vite-plugin-svelte": "^4.0.0-next.3", + "nodemon": "^3.0.3", + "polka": "^1.0.0-next.25", + "svelte": "workspace:*", + "tiny-glob": "^0.2.9", + "vite": "^5.0.13", + "vite-plugin-inspect": "^0.8.4" } } diff --git a/playgrounds/sandbox/run.js b/playgrounds/sandbox/run.js index 9c48a6c97b..4531e7182d 100644 --- a/playgrounds/sandbox/run.js +++ b/playgrounds/sandbox/run.js @@ -26,13 +26,13 @@ function mkdirp(dir) { } catch {} } -const svelte_modules = glob('**/*.svelte', { cwd: `${cwd}/input` }); -const js_modules = glob('**/*.js', { cwd: `${cwd}/input` }); +const svelte_modules = glob('**/*.svelte', { cwd: `${cwd}/src` }); +const js_modules = glob('**/*.js', { cwd: `${cwd}/src` }); for (const generate of /** @type {const} */ (['client', 'server'])) { console.error(`\n--- generating ${generate} ---\n`); for (const file of svelte_modules) { - const input = `${cwd}/input/${file}`; + const input = `${cwd}/src/${file}`; const source = fs.readFileSync(input, 'utf-8'); const output_js = `${cwd}/output/${generate}/${file}.js`; @@ -81,7 +81,7 @@ for (const generate of /** @type {const} */ (['client', 'server'])) { } for (const file of js_modules) { - const input = `${cwd}/input/${file}`; + const input = `${cwd}/src/${file}`; const source = fs.readFileSync(input, 'utf-8'); const compiled = compileModule(source, { diff --git a/playgrounds/demo/scripts/create-app-svelte.js b/playgrounds/sandbox/scripts/create-app-svelte.js similarity index 100% rename from playgrounds/demo/scripts/create-app-svelte.js rename to playgrounds/sandbox/scripts/create-app-svelte.js diff --git a/playgrounds/demo/scripts/main.template.svelte b/playgrounds/sandbox/scripts/main.template.svelte similarity index 100% rename from playgrounds/demo/scripts/main.template.svelte rename to playgrounds/sandbox/scripts/main.template.svelte diff --git a/playgrounds/demo/ssr-dev.js b/playgrounds/sandbox/ssr-dev.js similarity index 100% rename from playgrounds/demo/ssr-dev.js rename to playgrounds/sandbox/ssr-dev.js diff --git a/playgrounds/demo/ssr-prod.js b/playgrounds/sandbox/ssr-prod.js similarity index 100% rename from playgrounds/demo/ssr-prod.js rename to playgrounds/sandbox/ssr-prod.js diff --git a/playgrounds/sandbox/tsconfig.json b/playgrounds/sandbox/tsconfig.json index 8aa4b6f1e9..a1566560bf 100644 --- a/playgrounds/sandbox/tsconfig.json +++ b/playgrounds/sandbox/tsconfig.json @@ -13,5 +13,5 @@ "allowJs": true, "checkJs": true }, - "include": ["./run.js", "./input"] + "include": ["./src", "ssr-dev.js", "ssr-prod.js"] } diff --git a/playgrounds/demo/vite.config.js b/playgrounds/sandbox/vite.config.js similarity index 100% rename from playgrounds/demo/vite.config.js rename to playgrounds/sandbox/vite.config.js