Skip to content

Commit 24a73ed

Browse files
committed
Merge branch 'main' of github.com:devforth/adminforth
2 parents b98b65f + 4eed671 commit 24a73ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+8495
-2417
lines changed

Changelog.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [v1.5.11] - next
89

9-
## [v1.5.9] - next
10+
11+
## [v1.5.10]
1012

1113
### Changed
1214

@@ -16,12 +18,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1618
- show hook is now called as it was when user edits the page
1719
- fixed showRow in ShowTable.vue
1820
- if not ab le to connect postgres, don't crash the app
21+
- fix LastPass and other passowrd managers who try make autocomplete on user creation form
1922

2023
### Improved
21-
- reduce stdout output from AdminForths
24+
- reduce stdout output from AdminForth itself
2225

2326
### Added
2427
- AFCL Chart components
28+
- add requestUrl param to hooks extra
29+
- `npx adminforth create-app --app-name myadmin --db sqlite://.db.sqlite`
2530

2631
## [v1.5.8]
2732

adminforth/commands/cli.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
const args = process.argv.slice(2);
44
const command = args[0];
55

6-
import generateModels from "./generateModels.js";
76
import bundle from "./bundle.js";
7+
import createApp from "./createApp/main.js";
8+
import generateModels from "./generateModels.js";
89

910
switch (command) {
11+
case "create-app":
12+
createApp(args);
13+
break;
1014
case "generate-models":
1115
generateModels();
1216
break;
1317
case "bundle":
1418
bundle();
1519
break;
1620
default:
17-
console.log("Unknown command. Available commands: generate-models, bundle");
18-
}
21+
console.log("Unknown command. Available commands: create-app, generate-models, bundle");
22+
}
2.48 KB
Loading
Lines changed: 19 additions & 0 deletions
Loading
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import chalk from 'chalk';
2+
3+
import {
4+
parseArgumentsIntoOptions,
5+
prepareWorkflow,
6+
promptForMissingOptions,
7+
} from './utils.js';
8+
9+
10+
export default async function createApp(args) {
11+
// Step 1: Parse CLI arguments with `arg`
12+
let options = parseArgumentsIntoOptions(args);
13+
14+
// Step 2: Ask for missing arguments via `inquirer`
15+
options = await promptForMissingOptions(options);
16+
17+
// Step 3: Prepare a Listr-based workflow
18+
const tasks = prepareWorkflow(options)
19+
20+
// Step 4: Run tasks
21+
try {
22+
await tasks.run();
23+
} catch (err) {
24+
console.error(chalk.red(`\n❌ ${err.message}\n`));
25+
process.exit(1);
26+
}
27+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ADMINFORTH_SECRET=123
2+
NODE_ENV=development
3+
DATABASE_URL={{dbUrl}}
4+
{{#if prismaDbUrl}}
5+
PRISMA_DATABASE_URL={{prismaDbUrl}}
6+
{{/if}}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Dependency directories
2+
node_modules/
3+
4+
# dotenv environment variable files
5+
.env
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "custom",
3+
"version": "1.0.0",
4+
"main": "index.ts",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1"
7+
},
8+
"keywords": [],
9+
"author": "",
10+
"license": "ISC",
11+
"description": ""
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"paths": {
5+
"@/": "../node_modules/adminforth/dist/spa/src/",
6+
"": "../node_modules/adminforth/dist/spa/node_modules/",
7+
"@@/*": "."
8+
}
9+
}
10+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import express from 'express';
2+
import AdminForth, { Filters } from 'adminforth';
3+
import usersResource from "./resources/users";
4+
5+
const ADMIN_BASE_URL = '';
6+
7+
export const admin = new AdminForth({
8+
baseUrl: ADMIN_BASE_URL,
9+
auth: {
10+
usersResourceId: 'users',
11+
usernameField: 'email',
12+
passwordHashField: 'password_hash',
13+
rememberMeDays: 30,
14+
loginBackgroundImage: 'https://images.unsplash.com/photo-1534239697798-120952b76f2b?q=80&w=3389&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
15+
loginBackgroundPosition: '1/2',
16+
demoCredentials: "adminforth:adminforth",
17+
loginPromptHTML: "Use email <b>adminforth</b> and password <b>adminforth</b> to login",
18+
},
19+
customization: {
20+
brandName: "{{appName}}",
21+
title: "{{appName}}",
22+
favicon: '@@/assets/favicon.png',
23+
brandLogo: '@@/assets/logo.svg',
24+
datesFormat: 'DD MMM',
25+
timeFormat: 'HH:mm a',
26+
showBrandNameInSidebar: true,
27+
styles: {
28+
colors: {
29+
light: {
30+
primary: '#B400B8',
31+
sidebar: { main:'#571E58', text:'white' },
32+
},
33+
dark: {
34+
primary: '#82ACFF',
35+
sidebar: { main:'#1f2937', text:'#9ca3af' },
36+
}
37+
}
38+
},
39+
},
40+
dataSources: [
41+
{
42+
id: 'maindb',
43+
url: `${process.env.DATABASE_URL}`
44+
},
45+
],
46+
resources: [
47+
usersResource
48+
],
49+
menu: [
50+
{ type: 'heading', label: 'SYSTEM' },
51+
{
52+
label: 'Users',
53+
icon: 'flowbite:user-solid',
54+
resourceId: 'users'
55+
}
56+
],
57+
});
58+
59+
if (import.meta.url === `file://${process.argv[1]}`) {
60+
const app = express();
61+
app.use(express.json());
62+
63+
const port = 3500;
64+
65+
await admin.bundleNow({ hotReload: process.env.NODE_ENV === 'development' });
66+
console.log('Bundling AdminForth done. For faster serving consider calling bundleNow() from a build script.');
67+
68+
admin.express.serve(app)
69+
70+
admin.discoverDatabases().then(async () => {
71+
if (!await admin.resource('users').get([Filters.EQ('email', 'adminforth')])) {
72+
await admin.resource('users').create({
73+
email: 'adminforth',
74+
password_hash: await AdminForth.Utils.generatePasswordHash('adminforth'),
75+
role: 'superadmin',
76+
});
77+
}
78+
});
79+
80+
admin.express.listen(port, () => {
81+
console.log(`Example app listening at http://localhost:${port}`);
82+
console.log(`\n⚡ AdminForth is available at http://localhost:${port}${ADMIN_BASE_URL}\n`);
83+
});
84+
}

0 commit comments

Comments
 (0)