diff --git a/package.json b/package.json index d0a1d14..9f8247e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "swaf", - "version": "0.24.3", + "version": "0.24.4", "description": "Structure Web Application Framework.", "repository": "https://eternae.ink/ashpie/swaf", "author": "Alice Gaudon ", @@ -52,7 +52,6 @@ "@typescript-eslint/eslint-plugin": "^5.3.0", "@typescript-eslint/parser": "^5.3.0", "chokidar": "^3.5.1", - "clear-module": "^4.1.1", "concurrently": "^6.0.0", "eslint": "^8.2.0", "eslint-plugin-import": "^2.22.1", @@ -66,7 +65,6 @@ "maildev": "^1.1.0", "node-fetch": "^3.0.0", "nodemon": "^2.0.6", - "normalize.css": "^8.0.1", "require-from-string": "^2.0.2", "rollup": "^2.42.3", "rollup-plugin-css-only": "^3.1.0", @@ -76,14 +74,13 @@ "rollup-plugin-terser": "^7.0.2", "sass": "^1.32.12", "supertest": "^6.0.0", - "svelte": "^3.35.0", "svelte-check": "^2.2.8", - "svelte-preprocess": "4.6.9", "ts-jest": "^27.0.7", "typescript": "^4.0.2" }, "dependencies": { "argon2": "^0.28.2", + "clear-module": "^4.1.1", "compression": "^1.7.4", "config": "^3.3.1", "connect-flash": "^0.1.1", @@ -97,9 +94,12 @@ "mysql": "^2.18.1", "nanoid": "^3.1.20", "nodemailer": "^6.4.6", + "normalize.css": "^8.0.1", "nunjucks": "^3.2.1", "on-finished": "^2.3.0", "redis": "^3.0.2", + "svelte": "^3.35.0", + "svelte-preprocess": "4.6.9", "ts-node": "^10.4.0", "tslog": "^3.0.1", "uuid": "^8.0.0", diff --git a/scripts/dist.js b/scripts/dist.js index bfbf891..a0ead2a 100644 --- a/scripts/dist.js +++ b/scripts/dist.js @@ -16,3 +16,7 @@ fs.mkdirSync('dist/types', {recursive: true}); fs.readdirSync('src/types').forEach(file => { copyRecursively(path.join('src/types', file), 'dist/types'); }); + +fs.readdirSync('src/assets').forEach(file => { + copyRecursively(path.join('src/assets', file), 'dist/assets'); +}); diff --git a/scripts/prepare-sources.js b/scripts/prepare-sources.js index 468c2d7..854d9c2 100644 --- a/scripts/prepare-sources.js +++ b/scripts/prepare-sources.js @@ -18,10 +18,5 @@ if (!fs.existsSync(symlink)) { fs.symlinkSync(path.resolve('dist/common'), symlink); } -// Copy assets -fs.readdirSync('src/assets').forEach(file => { - copyRecursively(path.join('src/assets', file), 'dist/assets'); -}); - // Copy package.json fs.copyFileSync('package.json', 'dist/package.json'); diff --git a/src/assets/views/auth/account/NamePanel.svelte b/src/assets/views/auth/account/NamePanel.svelte index 6948cf1..71c0c8b 100644 --- a/src/assets/views/auth/account/NamePanel.svelte +++ b/src/assets/views/auth/account/NamePanel.svelte @@ -3,16 +3,18 @@ import Message from "../../components/Message.svelte"; import Form from "../../utils/Form.svelte"; import Field from "../../utils/Field.svelte"; + import {hasRoute, route} from "../../../../common/Routing"; let newName = ''; +{#if hasRoute('change-name')}

Change name

{#if $locals.can_change_name} -
@@ -29,3 +31,4 @@ {/if}
+{/if} \ No newline at end of file diff --git a/src/assets/views/auth/account/PasswordPanel.svelte b/src/assets/views/auth/account/PasswordPanel.svelte index 2c0b75c..f25869b 100644 --- a/src/assets/views/auth/account/PasswordPanel.svelte +++ b/src/assets/views/auth/account/PasswordPanel.svelte @@ -2,21 +2,23 @@ import {locals} from "../../../ts/stores"; import Form from "../../utils/Form.svelte"; import Field from "../../utils/Field.svelte"; + import {hasRoute, route} from "../../../../common/Routing"; let removePasswordMode = false; +{#if hasRoute('remove-password', 'change-password')}

{$locals.has_password ? 'Change' : 'Set'} password

{#if removePasswordMode} - {:else} -
{#if $locals.has_password} @@ -28,3 +30,4 @@ {/if}
+{/if} diff --git a/src/assets/views/auth/account/account.svelte b/src/assets/views/auth/account/account.svelte index cb72f86..ad0035d 100644 --- a/src/assets/views/auth/account/account.svelte +++ b/src/assets/views/auth/account/account.svelte @@ -6,6 +6,7 @@ import PasswordPanel from "./PasswordPanel.svelte"; import Form from "../../utils/Form.svelte"; import Field from "../../utils/Field.svelte"; + import {route} from "../../../../common/Routing"; const mainEmail = $locals.main_email?.email; const personalInfoFields = $locals.user_personal_info_fields || []; @@ -68,13 +69,13 @@ Secondary {email.email} -
-
@@ -87,7 +88,7 @@ -

Add an email address:

diff --git a/src/assets/views/auth/auth.svelte b/src/assets/views/auth/auth.svelte index 3edc296..ad14119 100644 --- a/src/assets/views/auth/auth.svelte +++ b/src/assets/views/auth/auth.svelte @@ -4,6 +4,7 @@ import Form from "../utils/Form.svelte"; import Field from "../utils/Field.svelte"; import Icon from "../utils/Icon.svelte"; + import {hasRoute, route} from "../../../common/Routing"; let registerUsingMagicLink = $locals.previousFormData()?.['auth_method'] !== 'password'; let loginUsingMagicLink = true; @@ -22,10 +23,11 @@ h1="Authentication and registration">
+ {#if hasRoute('login')}

Log in

- + @@ -39,11 +41,13 @@
+ {/if} + {#if hasRoute('register')}

Register

-
+ {#if $locals.has_username} @@ -68,5 +72,6 @@
+ {/if}
diff --git a/src/assets/views/backend/accounts_approval.svelte b/src/assets/views/backend/accounts_approval.svelte index 982427b..9594dc9 100644 --- a/src/assets/views/backend/accounts_approval.svelte +++ b/src/assets/views/backend/accounts_approval.svelte @@ -5,7 +5,7 @@ import Form from "../utils/Form.svelte"; import Field from "../utils/Field.svelte"; import Breadcrumb from "../components/Breadcrumb.svelte"; - import {route} from "../../../common/Routing"; + import {hasRoute, route} from "../../../common/Routing"; const accounts = $locals.accounts || []; @@ -49,16 +49,20 @@
-
+ {/if} -
+ {/if}
diff --git a/src/assets/views/home.svelte b/src/assets/views/home.svelte index 64a1e35..b03826a 100644 --- a/src/assets/views/home.svelte +++ b/src/assets/views/home.svelte @@ -1,6 +1,6 @@ @@ -9,11 +9,17 @@

swaf - Svelte Web Application Framework

Welcome to {$locals.app.name}!

+ {#if hasAnyRoute('tests', 'design')} + {/if} diff --git a/src/assets/views/layouts/BaseLayout.svelte b/src/assets/views/layouts/BaseLayout.svelte index 59543ff..4d10962 100644 --- a/src/assets/views/layouts/BaseLayout.svelte +++ b/src/assets/views/layouts/BaseLayout.svelte @@ -1,9 +1,7 @@ + + + +
{$locals.app.name} v{$locals.app_version} - all rights reserved.
diff --git a/src/assets/views/layouts/base/BaseHeader.svelte b/src/assets/views/layouts/base/BaseHeader.svelte new file mode 100644 index 0000000..32e6c31 --- /dev/null +++ b/src/assets/views/layouts/base/BaseHeader.svelte @@ -0,0 +1,43 @@ + + + + +
+ + + + + +
diff --git a/src/assets/views/layouts/base/BaseHeaderLogo.svelte b/src/assets/views/layouts/base/BaseHeaderLogo.svelte new file mode 100644 index 0000000..b964873 --- /dev/null +++ b/src/assets/views/layouts/base/BaseHeaderLogo.svelte @@ -0,0 +1,26 @@ + + + + + diff --git a/src/assets/views/layouts/base/BaseNavMenuAuth.svelte b/src/assets/views/layouts/base/BaseNavMenuAuth.svelte new file mode 100644 index 0000000..052ea70 --- /dev/null +++ b/src/assets/views/layouts/base/BaseNavMenuAuth.svelte @@ -0,0 +1,18 @@ + + +{#if hasRoute('auth')} + {#if $locals.user} + {#if $locals.user.is_admin} + + {/if} + + + + {:else} + + {/if} +{/if} diff --git a/src/assets/views/layouts/base/BaseNavMenuLinks.svelte b/src/assets/views/layouts/base/BaseNavMenuLinks.svelte new file mode 100644 index 0000000..e69de29 diff --git a/src/common/Routing.ts b/src/common/Routing.ts index 090ba7b..d246adc 100644 --- a/src/common/Routing.ts +++ b/src/common/Routing.ts @@ -66,3 +66,19 @@ export function route( export function getRouteParamRegExp(key: string, flags?: string): RegExp { return new RegExp(`:${key}(\\(.+?\\))?\\??`, flags); } + +export function hasRoute(...routesToMatch: string[]): boolean { + for (const route of routesToMatch) { + if (!routes[route]) return false; + } + + return true; +} + +export function hasAnyRoute(...routesToMatch: string[]): boolean { + for (const route of routesToMatch) { + if (routes[route]) return true; + } + + return false; +} diff --git a/src/frontend/SvelteViewEngine.ts b/src/frontend/SvelteViewEngine.ts index 7da5d71..58bda91 100644 --- a/src/frontend/SvelteViewEngine.ts +++ b/src/frontend/SvelteViewEngine.ts @@ -295,7 +295,7 @@ export default class SvelteViewEngine extends ViewEngine { }); // Load locals into locals store - const localsModulePath = "../../intermediates/assets/ts/stores.js"; + const localsModulePath = path.resolve(this.targetDir, "../ts/stores.js"); const localsModule = await import(localsModulePath); const locals = this.getGlobals().get(); const localMap = this.compileBackendCalls(backendCalls, locals, true); diff --git a/src/assets/views/tests.svelte b/test/assets/views/tests.svelte similarity index 100% rename from src/assets/views/tests.svelte rename to test/assets/views/tests.svelte