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

Add landing page for Svelte UI project [Do not merge until landing pages for all supported frameworks are complete] #385

Merged
merged 46 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3691524
feat: add custom svelte page to scaffold
Mar 27, 2023
697c150
chore: update eslint ignore patterns
Mar 27, 2023
b550fef
feat: add assets to lib folder
Mar 27, 2023
81a050d
feat: add landing page markup
Mar 27, 2023
dee563c
feat: add svelte layout component
Mar 27, 2023
b89f785
feat: add landing page scoped styles
Mar 27, 2023
7e4834b
feat: update get started file path
Mar 27, 2023
13ab6f8
refactor: move styles folder from lib folder
Mar 27, 2023
c5316e7
feat: handle ts and js vite config extensions
Mar 27, 2023
e7ddae2
feat: replace page svelte with custom page svelte
Mar 27, 2023
0c6c94c
feat: replace layout svelte with custom layout svelte
Mar 27, 2023
e9f7dec
feat: add styles directory and files to sveltkit project
Mar 27, 2023
65746bb
feat: add lib directory and files to sveltkit project
Mar 27, 2023
b0b381c
feat: add slot to layout component
Mar 27, 2023
f807601
feat: create lib and styles directories if none found
Mar 27, 2023
6f1fc8e
chore: update font file paths
Mar 27, 2023
b5f052f
chore: update example zkapp public key
Mar 27, 2023
2d09dbe
feat: remove sveltkit demo assets and components if found
Mar 27, 2023
bf3d626
feat: replace examples with deploy section
Mar 27, 2023
d511f36
feat: link mina logo to mina website onclick
Mar 28, 2023
2a541cf
chore: add hover state button asset
Mar 28, 2023
66bfbdd
feat: update button hover style
Mar 28, 2023
c4b01c7
feat: move button arrow to align with end of content window
Mar 29, 2023
2017aca
feat: update button hover color
Mar 29, 2023
d2d89e8
feat: increase card title letter spacing
Mar 29, 2023
fcfd82c
feat: increase card copy letter spacing
Mar 30, 2023
da37b50
feat: update card section letter spacing
Mar 30, 2023
61d14b3
feat: update hover state style
Apr 4, 2023
8a049bb
feat: add gradient background component
Apr 4, 2023
e66ae17
feat: add background animation to component
ymekuria Apr 4, 2023
9f4a1a7
feat: add animation component to ui scaffold
ymekuria Apr 4, 2023
c8b63e9
feat: update mina logo styles
ymekuria Apr 4, 2023
23b3f72
feat: clean up tagline and get started copy and style
ymekuria Apr 4, 2023
9db1fd6
refactor: remove logs and cleanup comments
ymekuria Apr 4, 2023
9f08599
feat: update mobile layout
ymekuria Apr 4, 2023
537f853
refactor: move bg animation styles to stylesheet
ymekuria Apr 5, 2023
3e16840
feat: adjust mobile background and copy position
ymekuria Apr 5, 2023
83152ef
refactor: rename background animation component
ymekuria Apr 5, 2023
ce55c86
feat: update tagline copy
ymekuria Apr 8, 2023
831b9ff
feat: tweak mobile and desktop styles
ymekuria Apr 10, 2023
9005897
feat: update example public key
ymekuria Apr 10, 2023
c1d2d7b
feat: add mina favicon
ymekuria Apr 10, 2023
45dae34
feat: edit taglines copy
ymekuria Apr 10, 2023
ecd5e4f
feat: iterate mobile style
ymekuria Apr 10, 2023
5c15367
refactor: rename page title
ymekuria Apr 12, 2023
c0cc4b4
Merge branch 'main' into feature/svelte-landing-page
ymekuria Apr 13, 2023
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
9 changes: 8 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@ module.exports = {
rules: {
'no-constant-condition': 'off',
},
ignorePatterns: ['*.md'],
ignorePatterns: [
'*.md',
'**/*.css',
'**/*.png',
'**/*.svg',
'**/*.woff',
'**/*.woff2',
],
};
99 changes: 51 additions & 48 deletions src/lib/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const { prompt, Select } = require('enquirer');
const { spawnSync } = require('child_process');
const { red, green, reset } = require('chalk');
const customNextIndex = require('../lib/ui/next/customNextIndex');
const customPageSvelte = require('../lib/ui/svelte/customPageSvelte');
const customLayoutSvelte = require('../lib/ui/svelte/customLayoutSvelte');
const gradientBackground = require('./ui/svelte/gradientBackground');

const shExec = util.promisify(sh.exec);

Expand Down Expand Up @@ -282,6 +285,7 @@ function scaffoldSvelte() {
stdio: 'inherit',
shell: true,
});

sh.cp(
path.join(__dirname, 'ui', 'svelte', 'hooks.server.js'),
path.join('ui', 'src')
Expand Down Expand Up @@ -314,79 +318,77 @@ function scaffoldSvelte() {
// from the referenced tsconfig.json - TypeScript does not merge them in
}
`;

let useTypescript = true;
try {
// Determine if generated project is a ts project by looking for a tsconfig file
fs.readFileSync(path.join('ui', 'tsconfig.json'));
fs.writeFileSync(path.join('ui', 'tsconfig.json'), customTsConfig);
} catch (err) {
if (err.code !== 'ENOENT') {
console.error(err);
}
useTypescript = false;
}

const vitConfig = fs.readFileSync(path.join('ui', 'vite.config.js'), 'utf8');
const viteConfigFileName = useTypescript
? 'vite.config.ts'
: 'vite.config.js';

const vitConfig = fs.readFileSync(
path.join('ui', viteConfigFileName),
'utf8'
);

const customViteConfig = vitConfig.replace(
/^}(.*?)$/gm, // Search for the last '}' in the file.
`,
optimizeDeps: { esbuildOptions: { target: 'es2020' } }
};`
});`
);

fs.writeFileSync(path.join('ui', 'vite.config.js'), customViteConfig);
fs.writeFileSync(path.join('ui', viteConfigFileName), customViteConfig);

const pageSvelte = fs.readFileSync(
// Remove Sveltekit demo pages and components if found
fs.emptyDirSync(path.join('ui', 'src', 'routes'));

fs.writeFileSync(
path.join('ui', 'src', 'routes', '+page.svelte'),
'utf8'
customPageSvelte
);

const contractImport = `
import { onMount } from "svelte";
import { isReady, Mina, PublicKey } from 'snarkyjs';
fs.writeFileSync(
path.join('ui', 'src', 'routes', '+layout.svelte'),
customLayoutSvelte
);

onMount(async () => {
await isReady;
fs.writeFileSync(
path.join('ui', 'src', 'routes', 'GradientBG.svelte'),
gradientBackground
);

const { Add } = await import('../../../contracts/build/src/')
// Update this to use the address (public key) for your zkApp account
// To try it out, you can try this address for an example "Add" smart contract that we've deployed to
// Berkeley Testnet B62qisn669bZqsh8yMWkNyCA7RvjrL6gfdr3TQxymDHNhTc97xE5kNV
const zkAppAddress = ''
// This should be removed once the zkAppAddress is updated.
if (!zkAppAddress) {
console.error(
'The following error is caused because the zkAppAddress has an empty string as the public key. Update the zkAppAddress with the public key for your zkApp account, or try this address for an example "Add" smart contract that we deployed to Berkeley Testnet: B62qqkb7hD1We6gEfrcqosKt9C398VLp1WXeTo1i9boPoqF7B1LxHg4',
);
}
const zkApp = new Add(PublicKey.fromBase58(zkAppAddress))
});
`;
fs.mkdirsSync(path.join('ui', 'src', 'styles'));

let customPageSvelte;
// A script tag will be added if a user generates a skelton project from the svelte prompt
if (!pageSvelte.includes('<script>')) {
customPageSvelte = pageSvelte.replace(
'<h1>',
`
<script>
${contractImport}
</script>
// Adds landing page styles directory and files to SvelteKit project.
fs.copySync(
path.join(__dirname, 'ui', 'svelte', 'styles'),
path.join('ui', 'src', 'styles')
);

<h1>
`
);
} else {
customPageSvelte = pageSvelte.replace(
'</script>',
`
${contractImport}
</script>`
);
}
// Remove Sveltkit demo lib and assets if found
fs.emptyDirSync(path.join('ui', 'src', 'lib'));

fs.writeFileSync(
path.join('ui', 'src', 'routes', '+page.svelte'),
customPageSvelte
// Adds landing page lib directory and files to SvelteKit project.
fs.copySync(
path.join(__dirname, 'ui', 'svelte', 'lib'),
path.join('ui', 'src', 'lib')
);

// Removes Sveltekit static assets
fs.emptydirSync(path.join('ui', 'static'));

fs.copySync(
path.join(__dirname, 'ui', 'svelte', 'favicon.png'),
path.join('ui', 'static', 'favicon.png')
);
}

Expand Down Expand Up @@ -498,6 +500,7 @@ async function scaffoldNext(projectName) {
path.join('ui', 'src/pages', '_app.tsx'),
path.join('ui', 'src/pages', '_app.page.tsx')
);

sh.mv(
path.join('ui', 'src/pages', 'index.tsx'),
path.join('ui', 'src/pages', 'index.page.tsx')
Expand Down
6 changes: 6 additions & 0 deletions src/lib/ui/svelte/customLayoutSvelte.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = `
<script>
import '../styles/globals.css'
</script>
<slot/>
`;
134 changes: 134 additions & 0 deletions src/lib/ui/svelte/customPageSvelte.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
module.exports = `
<script>
import heroMinaLogo from '$lib/assets/HeroMinaLogo.svg'
import arrowRightSmall from '$lib/assets/arrow-right-small.svg'
import GradientBG from './GradientBG.svelte'
import { onMount } from 'svelte'
import { isReady, Mina, PublicKey } from 'snarkyjs'

onMount(async () => {
const { Add } = await import('../../../contracts/build/src/')

await isReady
// Update this to use the address (public key) for your zkApp account.
// To try it out, you can try this address for an example "Add" smart contract that we've deployed to
// Berkeley Testnet B62qkwohsqTBPsvhYE8cPZSpzJMgoKn4i1LQRuBAtVXWpaT4dgH6WoA .
const zkAppAddress = ''
// This should be removed once the zkAppAddress is updated.
if (!zkAppAddress) {
console.error(
'The following error is caused because the zkAppAddress has an empty string as the public key. Update the zkAppAddress with the public key for your zkApp account, or try this address for an example "Add" smart contract that we deployed to Berkeley Testnet: B62qkwohsqTBPsvhYE8cPZSpzJMgoKn4i1LQRuBAtVXWpaT4dgH6WoA',
)
}
//const zkApp = new Add(PublicKey.fromBase58(zkAppAddress))
})
</script>

<style global>
@import '../styles/Home.module.css';
</style>

<svelte:head>
<title>Mina zkApp UI</title>
</svelte:head>
<GradientBG>
<main class="main">
<div class="center">
<a
href="https://minaprotocol.com/"
target="_blank"
rel="noopener noreferrer">
<img
class="logo"
src={heroMinaLogo}
alt="Mina Logo"
width="191"
height="174"
priority />
</a>
<p class="tagline">
built with
<code class="code">SnarkyJS</code>
</p>
</div>
<p class="start">
Get started by editing
<code class="code">src/routes/+page.svelte</code>
</p>
<div class="grid">
<a
href="https://docs.minaprotocol.com/zkapps"
class="card"
target="_blank"
rel="noopener noreferrer">
<h2>
<span>DOCS</span>
<div>
<img
src={arrowRightSmall}
alt="Mina Logo"
width={16}
height={16}
priority />
</div>
</h2>
<p>Explore zkApps, how to build one, and in-depth references</p>
</a>
<a
href="https://docs.minaprotocol.com/zkapps/tutorials/hello-world"
class="card"
target="_blank"
rel="noopener noreferrer">
<h2>
<span>TUTORIALS</span>
<div>
<img
src={arrowRightSmall}
alt="Mina Logo"
width={16}
height={16}
priority />
</div>
</h2>
<p>Learn with step-by-step SnarkyJS tutorials</p>
</a>
<a
href="https://discord.gg/minaprotocol"
class="card"
target="_blank"
rel="noopener noreferrer">
<h2>
<span>QUESTIONS</span>
<div>
<img
src={arrowRightSmall}
alt="Mina Logo"
width={16}
height={16}
priority />
</div>
</h2>
<p>Ask questions on our Discord server</p>
</a>
<a
href="https://docs.minaprotocol.com/zkapps/how-to-deploy-a-zkapp"
class="card"
target="_blank"
rel="noopener noreferrer">
<h2>
<span>DEPLOY</span>
<div>
<img
src={arrowRightSmall}
alt="Mina Logo"
width={16}
height={16}
priority />
</div>
</h2>
<p>Deploy a zkApp to Berkeley Testnet</p>
</a>
</div>
</main>
</GradientBG>
`;
Binary file added src/lib/ui/svelte/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading