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

feat: Upgrade and enable svelte-core module #10958

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ jobs:
- customjhlite
- typescriptapp
- thymeleafapp
- svelteapp
include:
- java-build-tool: maven
- spring-config-format: yaml
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.jhipster.lite.generator.client.svelte.core.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.append;
import static tech.jhipster.lite.module.domain.JHipsterModule.from;
import static tech.jhipster.lite.module.domain.JHipsterModule.lineBeforeText;
import static tech.jhipster.lite.module.domain.JHipsterModule.moduleBuilder;
Expand All @@ -13,8 +14,10 @@
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.COMMON;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.SVELTE;

import java.util.function.Consumer;
import tech.jhipster.lite.module.domain.Indentation;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.JHipsterModule.JHipsterModuleBuilder;
import tech.jhipster.lite.module.domain.file.JHipsterDestination;
import tech.jhipster.lite.module.domain.file.JHipsterSource;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
Expand All @@ -26,96 +29,106 @@ public class SvelteModuleFactory {

private static final String ENGINES_NEEDLE = " \"engines\":";

private static final JHipsterSource PRIMARY_MAIN_SOURCE = SOURCE.append("src/main/webapp/app/common/primary/app");
private static final JHipsterDestination PRIMARY_MAIN_DESTINATION = to("src/main/webapp/app/common/primary/app");
private static final JHipsterSource PRIMARY_MAIN_SOURCE = SOURCE.append("src/main/webapp/lib/common/primary/app");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep things in the app folder: other modules (e.g. ts-pagination-domainà that generates additional content will generate content in the app folder.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically it's internal lib containing app specific components. feel free to update, if needed

private static final JHipsterDestination PRIMARY_MAIN_DESTINATION = to("src/main/webapp/lib/common/primary/app");
private static final JHipsterSource CLIENT_COMMON = from("client/common");

private static final JHipsterSource PRIMARY_TEST_SOURCE = SOURCE.append("src/test/unit/common/primary/app");
private static final JHipsterDestination PRIMARY_TEST_DESTINATION = to("src/test/webapp/unit/common/primary/app");

public JHipsterModule buildSvelteModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);

//@formatter:off
return moduleBuilder(properties)
.preCommitActions(stagedFilesFilter("{src/**/,}*.ts"), preCommitCommands("eslint --fix", "prettier --write"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep typescript.
Enforcing a strongly typed language, that allows Type Driven Development, is one of the opinionated view of jhipster-lite.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel free to push changes, as needed

.preCommitActions(stagedFilesFilter("{src/**/,}*.{js,svelte}"), preCommitCommands("eslint --fix", "prettier --write", "npm run check"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On other client in jhipster-lite, the pre-commit action doesn't check, it just fixes/reformat.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invocation of eslint --fix implicitly checks for lint errors and resolves whatever it can. If you still have lint errors, then, I believe it print those on console and aborts the commit. Inclusion of svelte check is to avoid commit of erroneous svelte code.

.gitIgnore()
.comment("Svelte")
.pattern(".svelte-kit/")
.and()
.comment("Vite")
.pattern("vite.config.js.timestamp-*")
.comment("Env")
.pattern(".env")
.pattern(".env.*")
.pattern("!.env.test")
.and()
.packageJson()
.addDependency(packageName("svelte-navigator"), SVELTE)
.addDevDependency(packageName("@babel/preset-env"), SVELTE)
.addDevDependency(packageName("@sveltejs/adapter-static"), SVELTE)
.addDevDependency(packageName("@sveltejs/kit"), SVELTE)
.addDevDependency(packageName("@sveltejs/vite-plugin-svelte"), SVELTE)
.addDevDependency(packageName("@testing-library/jest-dom"), SVELTE)
.addDevDependency(packageName("@testing-library/svelte"), SVELTE)
.addDevDependency(packageName("@typescript-eslint/eslint-plugin"), SVELTE)
.addDevDependency(packageName("@typescript-eslint/parser"), SVELTE)
.addDevDependency(packageName("@vitest/coverage-istanbul"), SVELTE)
.addDevDependency(packageName("babel-plugin-transform-vite-meta-env"), SVELTE)
.addDevDependency(packageName("eslint"), SVELTE)
.addDevDependency(packageName("@testing-library/user-event"), SVELTE)
.addDevDependency(packageName("@vitest/coverage-v8"), SVELTE)
.addDevDependency(packageName("@vitest/ui"), SVELTE)
.addDevDependency(packageName("@types/eslint"), SVELTE)
.addDevDependency(packageName("eslint"), COMMON)
.addDevDependency(packageName("eslint-config-prettier"), COMMON)
.addDevDependency(packageName("eslint-plugin-svelte3"), SVELTE)
.addDevDependency(packageName("jsdom"), SVELTE)
.addDevDependency(packageName("prettier"), SVELTE)
.addDevDependency(packageName("eslint-plugin-svelte"), SVELTE)
.addDevDependency(packageName("globals"), COMMON)
.addDevDependency(packageName("jsdom"), COMMON)
.addDevDependency(packageName("prettier-plugin-svelte"), SVELTE)
.addDevDependency(packageName("svelte"), SVELTE)
.addDevDependency(packageName("svelte-check"), SVELTE)
.addDevDependency(packageName("svelte-preprocess"), SVELTE)
.addDevDependency(packageName("tslib"), SVELTE)
.addDevDependency(packageName("typescript"), SVELTE)
.addDevDependency(packageName("vite"), SVELTE)
.addDevDependency(packageName("vitest"), SVELTE)
.addDevDependency(packageName("vitest-sonar-reporter"), SVELTE)
.addScript(scriptKey("dev"), scriptCommand("vite dev --port 9000"))
.addScript(scriptKey("start"), scriptCommand("vite dev --port 9000"))
.addDevDependency(packageName("typescript"), COMMON)
.addDevDependency(packageName("vite"), COMMON)
.addDevDependency(packageName("vitest"), COMMON)
.addDevDependency(packageName("vitest-sonar-reporter"), COMMON)
.addScript(scriptKey("start"), scriptCommand("vite dev --port 9000 --open"))
.addScript(scriptKey("build"), scriptCommand("vite build"))
.addScript(scriptKey("package"), scriptCommand("vite package"))
.addScript(scriptKey("preview"), scriptCommand("vite preview"))
.addScript(scriptKey("check"), scriptCommand("svelte-check --tsconfig ./tsconfig.json"))
.addScript(scriptKey("check:watch"), scriptCommand("svelte-check --tsconfig ./tsconfig.json --watch"))
.addScript(
scriptKey("lint"),
scriptCommand("prettier --ignore-path .gitignore --check && eslint --ignore-path .gitignore .")
)
.addScript(scriptKey("format"), scriptCommand("prettier --ignore-path .gitignore --write"))
.addScript(scriptKey("test"), scriptCommand("npm run test:watch"))
.addScript(scriptKey("test:coverage"), scriptCommand("vitest run --coverage"))
.addScript(scriptKey("test:watch"), scriptCommand("vitest --"))
.addScript(scriptKey("check"), scriptCommand("svelte-kit sync && svelte-check --tsconfig ./jsconfig.json"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the script structure from angular/react/vue modules (to be able to use TikUi)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to push changes to this branch, as needed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't :). Those scripts needs to be updated otherwise it will break the current work on frontend modules and we won't be able to integrate styles in svelte and svelte module will be broken, again.

I don't care about svelte integration so I won't contribute on that but I do care about frontend modules moving forward :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DamnClin : Don't worry, I'll take the charge of harmonizing the svelte client with other clients :) @vishal423 is helping us here to bring back the svelte client to life ;)

.addScript(scriptKey("lint"), scriptCommand("prettier --check . && eslint ."))
.addScript(scriptKey("format"), scriptCommand("prettier --write '{,src/**/,cypress/**/}*.{md,json,js,cjs,svelte,css,html,yml}'"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The svelte module already depends on the prettier module, that setup a prettier:format script, so there's no need to add a new script for formatting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we use a different pattern in pre-commit hook, this script allows reuse of same for explicit invocation

.addScript(scriptKey("test"), scriptCommand("vitest run --coverage"))
.addScript(scriptKey("test:ui"), scriptCommand("vitest --ui --coverage"))
.addScript(scriptKey("test:watch"), scriptCommand("vitest"))
.and()
.optionalReplacements()
.in(path("package.json"))
.add(lineBeforeText(ENGINES_NEEDLE), type(properties.indentation()))
.and()
.and()
.files()
.add(SOURCE.file(".eslintrc.cjs"), to(".eslintrc.cjs"))
.add(SOURCE.file("tsconfig.json"), to("tsconfig.json"))
.add(SOURCE.file("vite.config.js"), to("vite.config.js"))
.add(SOURCE.append("src/main/webapp/routes").template("+page.svelte"), to("src/main/webapp/routes/+page.svelte"))
.add(PRIMARY_MAIN_SOURCE.template("App.svelte"), PRIMARY_MAIN_DESTINATION.append("App.svelte"))
.add(PRIMARY_TEST_SOURCE.template("App.spec.ts"), PRIMARY_TEST_DESTINATION.append("App.spec.ts"))
.add(PRIMARY_MAIN_SOURCE.template("App.spec.js"), PRIMARY_MAIN_DESTINATION.append("App.spec.js"))
.batch(CLIENT_COMMON, to("."))
.addFile(".eslintignore")
.addFile(".npmrc")
.and()
.batch(SOURCE, to("."))
.addTemplate("svelte.config.js")
.addTemplate("vitest.config.ts")
.addTemplate("eslint.config.js")
.addTemplate("vite.config.js")
.addFile("vitest-setup.js")
.addTemplate("jsconfig.json")
.and()
.batch(SOURCE.file("src/main/webapp"), to("src/main/webapp"))
.addTemplate("app.html")
.addTemplate("app.d.ts")
.and()
.batch(SOURCE.file("src/main/webapp/assets"), to("src/main/webapp/assets"))
.addFile("JHipster-Lite-neon-orange.png")
.addFile("favicon.png")
.and()
.batch(SOURCE.file("src/main/webapp/assets/img"), to("src/main/webapp/assets/img"))
.addFile("jhipster-lite-neon-orange.png")
.addFile("svelte-logo.png")
.and()
.and()
.apply(patchPrettierConfig(properties))
.build();
//@formatter:on
}

private Consumer<JHipsterModuleBuilder> patchPrettierConfig(JHipsterModuleProperties properties) {
//@formatter:off
return moduleBuilder -> moduleBuilder
.mandatoryReplacements()
.in(path(".prettierrc"))
.add(lineBeforeText("plugins:"), properties.indentation().times(1) + "- prettier-plugin-svelte")
.add(append(), "\n# Svelte rules:")
.add(append(), "semi: false")
.add(append(), "svelteSortOrder: options-scripts-styles-markup")
.add(append(), "svelteStrictMode: true")
.and()
.and();
//@formatter:on
}

private static String type(Indentation indentation) {
return indentation.spaces() + "\"type\": \"module\",";
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/config/application-svelte.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
jhlite-hidden-resources.slugs:
- spring-boot-kafka-sample-producer-consumer
- angular-core
- react-core
- vue-core
1 change: 0 additions & 1 deletion src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ application:

jhlite-hidden-resources:
slugs:
- svelte-core
- tikui

jhlite-preset-file:
Expand Down
19 changes: 0 additions & 19 deletions src/main/resources/generator/client/svelte/.eslintrc.cjs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import js from '@eslint/js'
import svelte from 'eslint-plugin-svelte'
import prettier from 'eslint-config-prettier';
import globals from 'globals'

/** @type {import('eslint').Linter.Config[]} */
export default [
js.configs.recommended,
...svelte.configs['flat/recommended'],
prettier,
...svelte.configs['flat/prettier'],
{
ignores: [
'{{projectBuildDirectory}}/',
'dist/',
],
},
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
},
},
];
15 changes: 15 additions & 0 deletions src/main/resources/generator/client/svelte/jsconfig.json.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./{{projectBuildDirectory}}/svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"moduleResolution": "bundler"
},
"include": ["src/main/webapp/**/*.js", "src/main/webapp/**/*.svelte"]
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>svelteapp</title>
<title>{{ projectName }}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="description" content="JHipster Lite project" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/ico" href="%sveltekit.assets%/favicon.png" />
<link rel="apple-touch-icon" href="%sveltekit.assets%/favicon.png" />
%sveltekit.head%
</head>
<body>
<div>%sveltekit.body%</div>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from 'vitest';
import App from '@/common/primary/app/App.svelte';
import App from '$lib/common/primary/app/App.svelte';
import { render } from '@testing-library/svelte';

test('Welcome the user', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@

<div class="app-container">
<h1>Svelte Application: JHipster + SvelteKit</h1>
<div>
<img alt="Svelte logo" src="svelte-logo.png" class="svelte-logo"/>
<img alt="Svelte logo" src="img/svelte-logo.png" class="svelte-logo"/>
</div>
<div>
<img alt="JHipster logo" src="JHipster-Lite-neon-orange.png"/>
<img alt="JHipster logo" src="img/jhipster-lite-neon-orange.png"/>
</div>
<h1>svelteapp: SvelteKit + Typescript</h1>
<p>Recommend IDE setup: <a href="https://code.visualstudio.com/" target="_blank" rel="noreferrer">VSCode</a></p>
<p class="link-container">
<a href="https://kit.svelte.dev" target="_blank" rel="noreferrer">Visit kit.svelte.dev</a>
Visit <a href="https://kit.svelte.dev" target="_blank" rel="noreferrer">kit.svelte.dev</a> to read SvelteKit documentation
|
<a href="https://github.com/jhipster/jhipster-lite" target="_blank" rel="noreferrer">Visit jhipster-lite</a>
Visit <a href="https://github.com/jhipster/jhipster-lite" target="_blank" rel="noreferrer">jhipster-lite</a> to read JHipster Lite documentation
</p>
<p>
Edit
<code> src/main/webapp/app/common/primary/app/App.svelte </code> to test hot module replacement.
<code> src/main/webapp/lib/common/primary/app/App.svelte </code> to test hot module replacement.
</p>
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<script>
import { Router, Route } from "svelte-navigator";
import App from '../app/common/primary/app/App.svelte';

export let url = '';
import App from '$lib/common/primary/app/App.svelte';
</script>

<Router {url}>
<div>
<Route primary={false} path="/"><App /></Route>
</div>
</Router>
<App />
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import adapter from '@sveltejs/adapter-static';
import preprocess from 'svelte-preprocess';
import adapter from '@sveltejs/adapter-static'
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'

/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: preprocess(),

preprocess: vitePreprocess(),
kit: {
adapter: adapter({
pages: '{{projectBuildDirectory}}/classes/static/',
Expand All @@ -15,13 +15,15 @@ const config = {
routes: 'src/main/webapp/routes',
appTemplate: 'src/main/webapp/app.html',
assets: 'src/main/webapp/assets',
hooks: {
server: 'src/main/webapp/hooks',
},
lib: 'src/main/webapp/lib',
serviceWorker: 'src/main/webapp/service-worker',
},
alias: {
$lib: 'src/main/webapp/lib',
'$lib/*': 'src/main/webapp/lib/*',
},
outDir: '{{projectBuildDirectory}}/svelte-kit',
},
};
}

export default config;
25 changes: 0 additions & 25 deletions src/main/resources/generator/client/svelte/tsconfig.json

This file was deleted.

Loading
Loading