Skip to content

Commit 94cd0cb

Browse files
authored
Merge pull request #158 from devforth/next
Next
2 parents 47e34ad + 1cac6b0 commit 94cd0cb

Some content is hidden

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

62 files changed

+2089
-559
lines changed

adminforth/commands/cli.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@ const command = args[0];
66
import bundle from "./bundle.js";
77
import createApp from "./createApp/main.js";
88
import generateModels from "./generateModels.js";
9-
9+
import createPlugin from "./createPlugin/main.js";
1010
switch (command) {
1111
case "create-app":
1212
createApp(args);
1313
break;
14+
case "create-plugin":
15+
createPlugin(args);
16+
break;
1417
case "generate-models":
1518
generateModels();
1619
break;
1720
case "bundle":
1821
bundle();
1922
break;
2023
default:
21-
console.log("Unknown command. Available commands: create-app, generate-models, bundle");
22-
}
24+
console.log(
25+
"Unknown command. Available commands: create-app, create-plugin, generate-models, bundle"
26+
);
27+
}

adminforth/commands/createApp/templates/adminuser.ts.hbs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import AdminForth, { AdminForthDataTypes, AdminForthResourceInput } from 'adminforth';
1+
import AdminForth, { AdminForthDataTypes, AdminForthResourceInput, AdminForthResource, AdminUser } from 'adminforth';
2+
23
import type { AdminUser } from 'adminforth';
34

45
async function canModifyUsers({ adminUser }: { adminUser: AdminUser }): Promise<boolean> {
@@ -86,18 +87,19 @@ export default {
8687
],
8788
hooks: {
8889
create: {
89-
beforeSave: async ({ record, adminUser, resource }) => {
90-
record.password_hash = await AdminForth.Utils.generatePasswordHash(record.password);
90+
beforeSave: async ({ record, adminUser, resource }: { record: any, adminUser: AdminUser, resource: AdminForthResource }) => {
91+
record.passwordHash = await AdminForth.Utils.generatePasswordHash(record.password);
9192
return { ok: true };
9293
}
9394
},
9495
edit: {
95-
beforeSave: async ({ record, adminUser, resource }) => {
96-
if (record.password) {
97-
record.password_hash = await AdminForth.Utils.generatePasswordHash(record.password);
96+
beforeSave: async ({ updates, adminUser, resource }: { updates: any, adminUser: AdminUser, resource: AdminForthResource }) => {
97+
console.log('Updating user', updates);
98+
if (updates.password) {
99+
updates.passwordHash = await AdminForth.Utils.generatePasswordHash(updates.password);
98100
}
99101
return { ok: true }
100102
},
101103
},
102-
}
104+
},
103105
} as AdminForthResourceInput;

adminforth/commands/createApp/templates/index.ts.hbs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ if (import.meta.url === `file://${process.argv[1]}`) {
7777
});
7878

7979
admin.express.listen(port, () => {
80-
console.log(`Example app listening at http://localhost:${port}`);
8180
console.log(`\n⚡ AdminForth is available at http://localhost:${port}${ADMIN_BASE_URL}\n`);
8281
});
8382
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import chalk from "chalk";
2+
3+
import {
4+
parseArgumentsIntoOptions,
5+
prepareWorkflow,
6+
promptForMissingOptions,
7+
} from "./utils.js";
8+
9+
export default async function createPlugin(args) {
10+
// Step 1: Parse CLI arguments with `arg`
11+
let options = parseArgumentsIntoOptions(args);
12+
13+
// Step 2: Ask for missing arguments via `inquirer`
14+
options = await promptForMissingOptions(options);
15+
16+
// Step 3: Prepare a Listr-based workflow
17+
const tasks = prepareWorkflow(options);
18+
19+
// Step 4: Run tasks
20+
try {
21+
await tasks.run();
22+
} catch (err) {
23+
console.error(chalk.red(`\n❌ ${err.message}\n`));
24+
process.exit(1);
25+
}
26+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
custom/node_modules
3+
dist
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".", // This should point to your project root
4+
"paths": {
5+
"@/*": [
6+
// "node_modules/adminforth/dist/spa/src/*"
7+
"../../../spa/src/*"
8+
],
9+
"*": [
10+
// "node_modules/adminforth/dist/spa/node_modules/*"
11+
"../../../spa/node_modules/*"
12+
],
13+
"@@/*": [
14+
// "node_modules/adminforth/dist/spa/src/*"
15+
"."
16+
]
17+
}
18+
}
19+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { AdminForthPlugin } from "adminforth";
2+
import type { IAdminForth, IHttpServer, AdminForthResourcePages, AdminForthResourceColumn, AdminForthDataTypes, AdminForthResource } from "adminforth";
3+
import type { PluginOptions } from './types.js';
4+
5+
6+
export default class ChatGptPlugin extends AdminForthPlugin {
7+
options: PluginOptions;
8+
9+
constructor(options: PluginOptions) {
10+
super(options, import.meta.url);
11+
this.options = options;
12+
}
13+
14+
async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
15+
super.modifyResourceConfig(adminforth, resourceConfig);
16+
17+
// simply modify resourceConfig or adminforth.config. You can get access to plugin options via this.options;
18+
}
19+
20+
validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
21+
// optional method where you can safely check field types after database discovery was performed
22+
}
23+
24+
instanceUniqueRepresentation(pluginOptions: any) : string {
25+
// optional method to return unique string representation of plugin instance.
26+
// Needed if plugin can have multiple instances on one resource
27+
return `single`;
28+
}
29+
30+
setupEndpoints(server: IHttpServer) {
31+
server.endpoint({
32+
method: 'POST',
33+
path: `/plugin/${this.pluginInstanceId}/example`,
34+
handler: async ({ body }) => {
35+
const { name } = body;
36+
return { hey: `Hello ${name}` };
37+
}
38+
});
39+
}
40+
41+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "{{pluginName}}",
3+
"version": "1.0.1",
4+
"main": "dist/index.js",
5+
"types": "dist/index.d.ts",
6+
"type": "module",
7+
"scripts": {
8+
"build": "tsc && rsync -av --exclude 'node_modules' custom dist/ && npm version patch"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"description": "",
14+
"devDependencies": {
15+
"@types/node": "latest",
16+
"typescript": "^5.7.3"
17+
},
18+
"dependencies": {
19+
"adminforth": "latest"
20+
}
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include*/
4+
"module": "node16", /* Specify what module code is generated. */
5+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
6+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. */
7+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
8+
"strict": false, /* Enable all strict type-checking options. */
9+
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
10+
},
11+
"exclude": ["node_modules", "dist", "custom"], /* Exclude files from compilation. */
12+
}
13+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface PluginOptions {
2+
3+
}

0 commit comments

Comments
 (0)