Skip to content

REPL downloads #1904

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

Merged
merged 3 commits into from
Dec 23, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ _actual*.*
/site/cypress/screenshots/
/site/__sapper__/
/site/.env
/site/.sessions
/site/.sessions
/site/static/svelte-app.json
/site/scripts/svelte-app
4 changes: 2 additions & 2 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"scripts": {
"dev": "sapper dev",
"sapper": "sapper build --legacy",
"export": "sapper export --legacy",
"update_template": "sh ./scripts/update_template.sh",
"start": "node __sapper__/build",
"cy:run": "cypress run",
"cy:open": "cypress open",
"test": "run-p --race dev cy:run",
"deploy": "npm run stage && now alias",
"prestage": "npm run sapper",
"prestage": "npm run update_template && npm run sapper",
"stage": "now"
},
"dependencies": {
Expand Down
11 changes: 11 additions & 0 deletions site/scripts/build-svelte-app-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require('fs');

const files = [];

for (const path of process.argv.slice(2)) {
if (!path.includes('/.')) {
files.push({ path: path.slice(19), data: fs.readFileSync(path).toString() });
}
}

fs.writeFileSync('static/svelte-app.json', JSON.stringify(files));
15 changes: 15 additions & 0 deletions site/scripts/update_template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cd `dirname $0`/..

# fetch svelte-app
rm -rf scripts/svelte-app
node_modules/.bin/degit sveltejs/template scripts/svelte-app

# update repl-viewer.css based on template
cp scripts/svelte-app/public/global.css static/repl-viewer.css

# remove src (will be recreated client-side) and node_modules
rm -rf scripts/svelte-app/src
rm -rf scripts/svelte-app/node_modules

# build svelte-app.json
node scripts/build-svelte-app-json.js `find scripts/svelte-app -type f`
11 changes: 11 additions & 0 deletions site/src/routes/guide/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@
overflow: hidden;
}

aside::after {
content: '';
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: var(--top-offset);
background: linear-gradient(to bottom, rgba(255,255,255,0) 0%, rgba(255,255,255,0.7) 50%, rgba(255,255,255,1) 100%);
pointer-events: none;
}

.sidebar {
padding: var(--top-offset) 3.2rem var(--top-offset) 0;
font-family: var(--font-ui);
Expand Down
8 changes: 5 additions & 3 deletions site/src/routes/repl/_components/AppControls/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,15 @@
async function download() {
downloading = true;

const { components, imports, values } = repl.toJSON();

const files = await (await fetch('/svelte-app.json')).json();

if (bundle.imports.length > 0) {
if (imports.length > 0) {
const idx = files.findIndex(({ path }) => path === 'package.json');
const pkg = JSON.parse(files[idx].data);
const deps = {};
bundle.imports.forEach(mod => {
imports.forEach(mod => {
const match = /^(@[^\/]+\/)?[^@\/]+/.exec(mod);
deps[match[0]] = 'latest';
});
Expand All @@ -191,7 +193,7 @@

var app = new App({
target: document.body,
props: ${JSON.stringify(data, null, '\t').replace(/\n/g, '\n\t')}
props: ${JSON.stringify(values, null, '\t').replace(/\n/g, '\n\t')}
});

export default app;` });
Expand Down
1 change: 1 addition & 0 deletions site/src/routes/repl/_components/Repl.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
version; // workaround

return {
imports: bundle.imports,
components: $component_store,
values: $values_store
};
Expand Down