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

Support for the Svelte 5 env. #701

Merged
merged 4 commits into from
Oct 23, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## Unreleased

## [0.21.8](https://github.com/o1-labs/zkapp-cli/compare/0.21.7...0.21.8) - 2024-10-23

### Changed

- Svelte project scaffold now uses latest `sv create` and sources migrated to `Svelte 5`. [#701](https://github.com/o1-labs/zkapp-cli/pull/701)

## [0.21.7](https://github.com/o1-labs/zkapp-cli/compare/0.21.6...0.21.7) - 2024-10-01

### Changed
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zkapp-cli",
"version": "0.21.7",
"version": "0.21.8",
"description": "CLI to create zkApps (zero-knowledge apps) for Mina Protocol",
"homepage": "https://github.com/o1-labs/zkapp-cli/",
"repository": {
Expand Down
5 changes: 2 additions & 3 deletions src/lib/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import url from 'node:url';
import util from 'node:util';
import ora from 'ora';
import shell from 'shelljs';
import customNextPage from '../lib/ui/next/customNextPage.js';
import customNextLayout from '../lib/ui/next/customNextLayout.js';
import customNextPage from '../lib/ui/next/customNextPage.js';
import customNuxtIndex from '../lib/ui/nuxt/customNuxtIndex.js';
import nuxtGradientBackground from '../lib/ui/nuxt/nuxtGradientBackground.js';
import customLayoutSvelte from '../lib/ui/svelte/customLayoutSvelte.js';
Expand Down Expand Up @@ -175,8 +175,7 @@ async function project({ name, ui }) {
}

function scaffoldSvelte() {
// `-y` installs the latest version of create-svelte without prompting.
spawnSync('npm', ['create', 'svelte@latest', '-y', 'ui'], {
spawnSync('npx', ['sv', 'create', 'ui'], {
stdio: 'inherit',
shell: true,
});
Expand Down
18 changes: 8 additions & 10 deletions src/lib/project.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,10 @@ describe('project.js', () => {

expect(shell.mkdir).toHaveBeenCalledWith('-p', 'test-project');
expect(shell.cd).toHaveBeenCalledWith('test-project');
expect(spawnSync).toHaveBeenCalledWith(
'npm',
['create', 'svelte@latest', '-y', 'ui'],
{ stdio: 'inherit', shell: true }
);
expect(spawnSync).toHaveBeenCalledWith('npx', ['sv', 'create', 'ui'], {
stdio: 'inherit',
shell: true,
});
expect(shell.cd).toHaveBeenCalledWith('contracts');
checkUiProjectSetup(shell.exec.mock.calls);
checkIfProjectSetupSuccessful();
Expand Down Expand Up @@ -678,11 +677,10 @@ describe('project.js', () => {

scaffoldSvelte();

expect(spawnSync).toHaveBeenCalledWith(
'npm',
['create', 'svelte@latest', '-y', 'ui'],
{ stdio: 'inherit', shell: true }
);
expect(spawnSync).toHaveBeenCalledWith('npx', ['sv', 'create', 'ui'], {
stdio: 'inherit',
shell: true,
});
expect(fs.writeFileSync).toHaveBeenCalled();
});
});
Expand Down
9 changes: 8 additions & 1 deletion src/lib/ui/svelte/customLayoutSvelte.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
export default `
<script>
import '../styles/globals.css'
/**
* @typedef {Object} Props
* @property {import('svelte').Snippet} [children]
*/

/** @type {Props} */
let { children } = $props();
</script>
<slot/>
{@render children?.()}
`;
11 changes: 9 additions & 2 deletions src/lib/ui/svelte/gradientBackground.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
export default `
<script>
import { onMount } from 'svelte'
/**
* @typedef {Object} Props
* @property {import('svelte').Snippet} [children]
*/

/** @type {Props} */
let { children } = $props();
let ctx
let pixels = []
let canvas
Expand Down Expand Up @@ -131,9 +138,9 @@ export default `
</style>

<div class="background">
<canvas class="background-gradients" width="6" height="6" />
<canvas class="background-gradients" width="6" height="6"></canvas>
</div>
<div class="container">
<slot />
{@render children?.()}
</div>
`;
9 changes: 6 additions & 3 deletions tests/utils/project-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export async function zkProject(
case 'svelte': {
interactiveDialog = {
...interactiveDialog,
'Which Svelte app template?': ['arrowDown', 'enter'],
'Add type checking with TypeScript?': ['arrowDown', 'enter'],
'Select additional options (use arrow keys/space bar)': [
'Which template would you like?': ['enter'],
'Add type checking with Typescript?': ['enter'],
'What would you like to add to your project?': [
'space',
'arrowDown',
'space',
Expand All @@ -59,6 +59,9 @@ export async function zkProject(
'space',
'enter',
],
'Which package manager do you want to install dependencies with?': [
'enter',
],
};
break;
}
Expand Down