From 2a184e4ff52dc974e3645d9877c645226f32198b Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Mon, 25 Jan 2021 12:37:41 +0100 Subject: [PATCH 1/4] Fix published npm package folder structure --- .gitignore | 2 ++ package.json | 9 +++++---- src/TestApp.ts | 30 +++++++++++++++--------------- src/main.ts | 4 ++-- tsconfig.json | 5 +---- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 5b5cd12..b3c8eff 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ node_modules dist yarn-error.log + +src/package.json diff --git a/package.json b/package.json index 75ef1c9..f88053e 100644 --- a/package.json +++ b/package.json @@ -10,16 +10,17 @@ "registry": "https://registry.npmjs.com", "access": "public" }, - "main": "dist/src/main.js", + "main": "dist/main.js", "types": "dist/index.d.ts", "scripts": { "test": "jest --verbose --runInBand", "clean": "(test ! -d dist || rm -r dist)", + "prepare": "cp package.json src/", "compile": "yarn clean && tsc", - "dev": "concurrently -k -n \"Typescript,Node,Webpack,Maildev\" -p \"[{name}]\" -c \"blue,green,red,yellow\" \"tsc --watch\" \"nodemon\" \"maildev\"", - "build": "yarn compile && cp -r package.json yarn.lock README.md config/ views/ dist/ && mkdir dist/types && cp src/types/* dist/types/", + "dev": "yarn prepare && concurrently -k -n \"Typescript,Node,Webpack,Maildev\" -p \"[{name}]\" -c \"blue,green,red,yellow\" \"tsc --watch\" \"nodemon\" \"maildev\"", + "build": "yarn prepare && yarn compile && cp -r yarn.lock README.md config/ views/ dist/ && mkdir dist/types && cp src/types/* dist/types/", "lint": "eslint . --ext .js,.jsx,.ts,.tsx", - "release": "yarn lint && yarn test && yarn build && cd dist && yarn publish" + "release": "yarn build && yarn lint && yarn test && cd dist && yarn publish" }, "devDependencies": { "@types/compression": "^1.7.0", diff --git a/src/TestApp.ts b/src/TestApp.ts index de24b16..ee5253c 100644 --- a/src/TestApp.ts +++ b/src/TestApp.ts @@ -1,18 +1,18 @@ -import Application from "../src/Application"; -import Migration, {MigrationType} from "../src/db/Migration"; -import ExpressAppComponent from "../src/components/ExpressAppComponent"; -import RedisComponent from "../src/components/RedisComponent"; -import MysqlComponent from "../src/components/MysqlComponent"; -import NunjucksComponent from "../src/components/NunjucksComponent"; -import LogRequestsComponent from "../src/components/LogRequestsComponent"; -import MailComponent from "../src/components/MailComponent"; -import SessionComponent from "../src/components/SessionComponent"; -import AuthComponent from "../src/auth/AuthComponent"; -import FormHelperComponent from "../src/components/FormHelperComponent"; -import ServeStaticDirectoryComponent from "../src/components/ServeStaticDirectoryComponent"; +import Application from "./Application"; +import Migration, {MigrationType} from "./db/Migration"; +import ExpressAppComponent from "./components/ExpressAppComponent"; +import RedisComponent from "./components/RedisComponent"; +import MysqlComponent from "./components/MysqlComponent"; +import NunjucksComponent from "./components/NunjucksComponent"; +import LogRequestsComponent from "./components/LogRequestsComponent"; +import MailComponent from "./components/MailComponent"; +import SessionComponent from "./components/SessionComponent"; +import AuthComponent from "./auth/AuthComponent"; +import FormHelperComponent from "./components/FormHelperComponent"; +import ServeStaticDirectoryComponent from "./components/ServeStaticDirectoryComponent"; import {Express} from "express"; -import MagicLinkAuthMethod from "../src/auth/magic_link/MagicLinkAuthMethod"; -import PasswordAuthMethod from "../src/auth/password/PasswordAuthMethod"; +import MagicLinkAuthMethod from "./auth/magic_link/MagicLinkAuthMethod"; +import PasswordAuthMethod from "./auth/password/PasswordAuthMethod"; import {MAGIC_LINK_MAIL} from "./Mails"; import CreateMigrationsTable from "./migrations/CreateMigrationsTable"; import CreateUsersAndUserEmailsTableMigration from "./auth/migrations/CreateUsersAndUserEmailsTableMigration"; @@ -29,7 +29,7 @@ import Controller from "./Controller"; import AccountController from "./auth/AccountController"; import MakeMagicLinksSessionNotUniqueMigration from "./auth/magic_link/MakeMagicLinksSessionNotUniqueMigration"; import AddUsedToMagicLinksMigration from "./auth/magic_link/AddUsedToMagicLinksMigration"; -import packageJson = require('../package.json'); +import packageJson = require('./package.json'); import PreviousUrlComponent from "./components/PreviousUrlComponent"; export const MIGRATIONS = [ diff --git a/src/main.ts b/src/main.ts index 0ea8124..640f431 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,9 +2,9 @@ import {delimiter} from "path"; // Load config from specified path or default + swaf/config (default defaults) process.env['NODE_CONFIG_DIR'] = - __dirname + '/../../node_modules/swaf/config/' + __dirname + '/../node_modules/swaf/config/' + delimiter - + (process.env['NODE_CONFIG_DIR'] || __dirname + '/../../config/'); + + (process.env['NODE_CONFIG_DIR'] || __dirname + '/../config/'); import {logger} from "./Logger"; import TestApp from "./TestApp"; diff --git a/tsconfig.json b/tsconfig.json index f34d0e9..867a3b0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,10 +11,7 @@ "moduleResolution": "Node", "esModuleInterop": true, "baseUrl": "dist", - "rootDirs": [ - "src", - "config" - ], + "rootDir": "src", "sourceRoot": "src", "inlineSourceMap": true, "inlineSources": true, From e7d66e7c045c60b69a89dd6db6d991461a3cad72 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Mon, 25 Jan 2021 12:37:55 +0100 Subject: [PATCH 2/4] .gitignore: add config/local.* --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b3c8eff..f18f616 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ dist yarn-error.log src/package.json +config/local.* From 359485170d179811208033e3706f0a1adc70b660 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Mon, 25 Jan 2021 12:47:10 +0100 Subject: [PATCH 3/4] UserNameComponent: ensure usage of user.name is optional Fixes #19 --- src/auth/magic_link/MagicLinkController.ts | 3 ++- src/helpers/BackendController.ts | 3 +++ test/views/layouts/base.njk | 2 +- views/backend/accounts_approval.njk | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/auth/magic_link/MagicLinkController.ts b/src/auth/magic_link/MagicLinkController.ts index 3df778c..e10163f 100644 --- a/src/auth/magic_link/MagicLinkController.ts +++ b/src/auth/magic_link/MagicLinkController.ts @@ -191,7 +191,8 @@ export default class MagicLinkController extends Controll if (!res.headersSent && user) { // Auth success - req.flash('success', `Authentication success. Welcome, ${user.name}!`); + const name = user.asOptional(UserNameComponent)?.name; + req.flash('success', `Authentication success. Welcome${name ? `, ${name}` : ''}`); res.redirect(req.getIntendedUrl() || Controller.route('home')); } break; diff --git a/src/helpers/BackendController.ts b/src/helpers/BackendController.ts index 66fc1c0..71a4d83 100644 --- a/src/helpers/BackendController.ts +++ b/src/helpers/BackendController.ts @@ -9,6 +9,8 @@ import UserEmail from "../auth/models/UserEmail"; import UserApprovedComponent from "../auth/models/UserApprovedComponent"; import {RequireAdminMiddleware, RequireAuthMiddleware} from "../auth/AuthComponent"; import NunjucksComponent from "../components/NunjucksComponent"; +import ModelFactory from "../db/ModelFactory"; +import UserNameComponent from "../auth/models/UserNameComponent"; export default class BackendController extends Controller { private static readonly menu: BackendMenuElement[] = []; @@ -65,6 +67,7 @@ export default class BackendController extends Controller { .get(); res.render('backend/accounts_approval', { accounts: accounts, + has_user_name_component: ModelFactory.get(User).hasComponent(UserNameComponent), }); } diff --git a/test/views/layouts/base.njk b/test/views/layouts/base.njk index a3b9693..a38ea56 100644 --- a/test/views/layouts/base.njk +++ b/test/views/layouts/base.njk @@ -23,7 +23,7 @@
  • - {{ user.name }} + {{ user.name | default('Account') }}
  • diff --git a/views/backend/accounts_approval.njk b/views/backend/accounts_approval.njk index cc0ae9f..961ce5b 100644 --- a/views/backend/accounts_approval.njk +++ b/views/backend/accounts_approval.njk @@ -10,7 +10,9 @@ # + {% if has_user_name_component %} Name + {% endif %} Main email Registered at Action @@ -20,7 +22,9 @@ {% for user in accounts %} {{ user.id }} + {% if has_user_name_component %} {{ user.name }} + {% endif %} {{ user.mainEmail.getOrFail().email | default('No email') }} {{ user.created_at.toISOString() }} From d32f57192598da48f487b6801c25d7ffed41f51f Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Mon, 25 Jan 2021 12:47:54 +0100 Subject: [PATCH 4/4] Version 0.23.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f88053e..850af94 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "swaf", - "version": "0.23.0", + "version": "0.23.1", "description": "Structure Web Application Framework.", "repository": "https://eternae.ink/arisu/swaf", "author": "Alice Gaudon ",