-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
base: main
Are you sure you want to change the base?
Changes from all commits
13619d7
dff0c21
f6e75a1
6a79f06
4fd7e0b
8817e63
9a02431
0b9de52
03d014d
11885b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
|
@@ -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; | ||
|
@@ -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"); | ||
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")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should keep typescript. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. invocation of |
||
.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")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to push changes to this branch, as needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}'")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The svelte module already depends on the prettier module, that setup a There was a problem hiding this comment. Choose a reason for hiding this commentThe 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\","; | ||
} | ||
|
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,6 @@ application: | |
|
||
jhlite-hidden-resources: | ||
slugs: | ||
- svelte-core | ||
- tikui | ||
|
||
jhlite-preset-file: | ||
|
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, | ||
}, | ||
}, | ||
}, | ||
]; |
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> |
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 /> |
This file was deleted.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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