Skip to content

Commit ca5c389

Browse files
authored
Merge pull request #234 from devforth/next
Next
2 parents 03fcb88 + 5e69bab commit ca5c389

Some content is hidden

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

50 files changed

+809
-255
lines changed

adapters/install-adapters.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
ADAPTERS="adminforth-completion-adapter-open-ai-chat-gpt adminforth-email-adapter-aws-ses adminforth-google-oauth-adapter adminforth-github-oauth-adapter adminforth-facebook-oauth-adapter adminforth-keycloak-oauth-adapter adminforth-microsoft-oauth-adapter adminforth-image-generation-adapter-openai adminforth-storage-adapter-amazon-s3 adminforth-storage-adapter-local"
2+
ADAPTERS="adminforth-completion-adapter-open-ai-chat-gpt adminforth-email-adapter-aws-ses adminforth-email-adapter-mailgun adminforth-google-oauth-adapter adminforth-github-oauth-adapter adminforth-facebook-oauth-adapter adminforth-keycloak-oauth-adapter adminforth-microsoft-oauth-adapter adminforth-twitch-oauth-adapter adminforth-image-generation-adapter-openai adminforth-storage-adapter-amazon-s3 adminforth-storage-adapter-local"
33

44
# for each
55
install_adapter() {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import express from 'express';
22
import AdminForth from 'adminforth';
33
import usersResource from "./resources/adminuser.js";
4+
import { fileURLToPath } from 'url';
5+
import path from 'path';
46

57
const ADMIN_BASE_URL = '';
68

@@ -55,7 +57,7 @@ export const admin = new AdminForth({
5557
],
5658
});
5759

58-
if (import.meta.url === `file://${process.argv[1]}`) {
60+
if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
5961
const app = express();
6062
app.use(express.json());
6163

adminforth/commands/createApp/utils.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,22 @@ async function writeTemplateFiles(dirname, cwd, options) {
284284
}
285285

286286
async function installDependencies(ctx, cwd) {
287-
const nodeBinary = process.execPath; // Path to the Node.js binary running this script
288-
const npmPath = path.join(path.dirname(nodeBinary), 'npm'); // Path to the npm executable
287+
const isWindows = process.platform === 'win32';
289288

289+
const nodeBinary = process.execPath;
290+
const npmPath = path.join(path.dirname(nodeBinary), 'npm');
290291
const customDir = ctx.customDir;
291-
const res = await Promise.all([
292-
await execAsync(`${nodeBinary} ${npmPath} install`, { cwd, env: { PATH: process.env.PATH } }),
293-
await execAsync(`${nodeBinary} ${npmPath} install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
294-
]);
292+
if (isWindows) {
293+
const res = await Promise.all([
294+
await execAsync(`npm install`, { cwd, env: { PATH: process.env.PATH } }),
295+
await execAsync(`npm install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
296+
]);
297+
} else {
298+
const res = await Promise.all([
299+
await execAsync(`${nodeBinary} ${npmPath} install`, { cwd, env: { PATH: process.env.PATH } }),
300+
await execAsync(`${nodeBinary} ${npmPath} install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
301+
]);
302+
}
295303
// console.log(chalk.dim(`Dependencies installed in ${cwd} and ${customDir}: \n${res[0].stdout}${res[1].stdout}`));
296304
}
297305

adminforth/commands/createCustomComponent/configUpdater.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export async function updateResourceConfig(resourceId, columnName, fieldType, co
254254
}
255255

256256

257-
export async function injectLoginComponent(indexFilePath, componentPath) {
257+
export async function injectLoginComponent(indexFilePath, componentPath, injectionType) {
258258
console.log(chalk.dim(`Reading file: ${indexFilePath}`));
259259
const content = await fs.readFile(indexFilePath, 'utf-8');
260260
const ast = recast.parse(content, {
@@ -263,6 +263,7 @@ export async function injectLoginComponent(indexFilePath, componentPath) {
263263

264264
let updated = false;
265265
let injectionLine = null;
266+
let targetProperty = null;
266267

267268
recast.visit(ast, {
268269
visitNewExpression(path) {
@@ -293,20 +294,23 @@ export async function injectLoginComponent(indexFilePath, componentPath) {
293294
const loginPageInjections = getOrCreateProp(customization, 'loginPageInjections');
294295
if (!n.ObjectExpression.check(loginPageInjections)) return false;
295296

296-
let underInputsProp = loginPageInjections.properties.find(
297-
p => n.ObjectProperty.check(p) && n.Identifier.check(p.key) && p.key.name === 'underInputs'
297+
// Determine target property based on injection type
298+
targetProperty = injectionType === 'beforeLogin' ? 'panelHeader' : 'underInputs';
299+
300+
let targetProp = loginPageInjections.properties.find(
301+
p => n.ObjectProperty.check(p) && n.Identifier.check(p.key) && p.key.name === targetProperty
298302
);
299303

300-
if (underInputsProp) {
301-
const currentVal = underInputsProp.value;
302-
injectionLine = underInputsProp.loc?.start.line ?? null;
304+
if (targetProp) {
305+
const currentVal = targetProp.value;
306+
injectionLine = targetProp.loc?.start.line ?? null;
303307
if (n.StringLiteral.check(currentVal)) {
304308
if (currentVal.value !== componentPath) {
305-
underInputsProp.value = b.arrayExpression([
309+
targetProp.value = b.arrayExpression([
306310
b.stringLiteral(currentVal.value),
307311
b.stringLiteral(componentPath),
308312
]);
309-
console.log(chalk.dim(`Converted 'underInputs' to array with existing + new path.`));
313+
console.log(chalk.dim(`Converted '${targetProperty}' to array with existing + new path.`));
310314
} else {
311315
console.log(chalk.dim(`Component path already present as string. Skipping.`));
312316
}
@@ -316,26 +320,26 @@ export async function injectLoginComponent(indexFilePath, componentPath) {
316320
);
317321
if (!exists) {
318322
currentVal.elements.push(b.stringLiteral(componentPath));
319-
console.log(chalk.dim(`Appended new component path to existing 'underInputs' array.`));
323+
console.log(chalk.dim(`Appended new component path to existing '${targetProperty}' array.`));
320324
} else {
321325
console.log(chalk.dim(`Component path already present in array. Skipping.`));
322326
}
323327
} else {
324-
console.warn(chalk.yellow(`⚠️ 'underInputs' is not a string or array. Skipping.`));
328+
console.warn(chalk.yellow(`⚠️ '${targetProperty}' is not a string or array. Skipping.`));
325329
return false;
326330
}
327331
} else {
328332
const newProperty = b.objectProperty(
329-
b.identifier('underInputs'),
330-
b.stringLiteral(componentPath)
331-
);
332-
333-
if (newProperty.loc) {
334-
console.log(chalk.dim(`Adding 'underInputs' at line: ${newProperty.loc.start.line}`));
335-
}
336-
337-
loginPageInjections.properties.push(newProperty);
338-
console.log(chalk.dim(`Added 'underInputs': ${componentPath}`));
333+
b.identifier(targetProperty),
334+
b.stringLiteral(componentPath)
335+
);
336+
337+
if (newProperty.loc) {
338+
console.log(chalk.dim(`Adding '${targetProperty}' at line: ${newProperty.loc.start.line}`));
339+
}
340+
341+
loginPageInjections.properties.push(newProperty);
342+
console.log(chalk.dim(`Added '${targetProperty}': ${componentPath}`));
339343
}
340344

341345
updated = true;
@@ -353,7 +357,7 @@ export async function injectLoginComponent(indexFilePath, componentPath) {
353357
await fs.writeFile(indexFilePath, outputCode, 'utf-8');
354358
console.log(
355359
chalk.green(
356-
`✅ Successfully updated CRUD injection in resource file: ${indexFilePath}` +
360+
`✅ Successfully updated login ${targetProperty} injection in: ${indexFilePath}` +
357361
(injectionLine !== null ? `:${injectionLine}` : '')
358362
)
359363
);

adminforth/commands/createCustomComponent/fileGenerator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export async function generateLoginOrGlobalComponentFile(componentFileName, inje
129129
const __filename = fileURLToPath(import.meta.url);
130130
const __dirname = path.dirname(__filename);
131131
let templatePath;
132-
if (injectionType === 'afterLogin') {
132+
if (injectionType === 'afterLogin' || injectionType === 'beforeLogin') {
133133
templatePath = path.join(__dirname, 'templates', 'login', `${injectionType}.vue.hbs`);
134134
} else {
135135
templatePath = path.join(__dirname, 'templates', 'global', `${injectionType}.vue.hbs`);

adminforth/commands/createCustomComponent/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ async function handleFieldComponentCreation(config, resources) {
5050
{ name: '📃 show', value: 'show' },
5151
{ name: '✏️ edit', value: 'edit' },
5252
{ name: '➕ create', value: 'create' },
53+
{ name: '🔍 filter', value: 'filter'},
5354
new Separator(),
5455
{ name: '🔙 BACK', value: '__BACK__' },
5556
]
@@ -256,6 +257,7 @@ async function handleLoginPageInjectionCreation(config) {
256257
const injectionType = await select({
257258
message: 'Select injection type:',
258259
choices: [
260+
{ name: 'Before Login and password inputs', value: 'beforeLogin' },
259261
{ name: 'After Login and password inputs', value: 'afterLogin' },
260262
{ name: '🔙 BACK', value: '__BACK__' },
261263
],
@@ -286,7 +288,7 @@ async function handleLoginPageInjectionCreation(config) {
286288
console.log(chalk.dim(`Component generation successful: ${absoluteComponentPath}`));
287289
const configFilePath = path.resolve(process.cwd(), 'index.ts');
288290
console.log(chalk.dim(`Injecting component: ${configFilePath}, ${componentFileName}`));
289-
await injectLoginComponent(configFilePath, `@@/${componentFileName}`);
291+
await injectLoginComponent(configFilePath, `@@/${componentFileName}`, injectionType);
290292

291293
console.log(
292294
chalk.bold.greenBright('You can now open the component in your IDE:'),
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<input
3+
type="text"
4+
:value="localValue"
5+
@input="onInput"
6+
placeholder="Search"
7+
aria-describedby="helper-text-explanation"
8+
class="inline-flex bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-0 focus:ring-lightPrimary focus:border-lightPrimary dark:focus:ring-darkPrimary dark:focus:border-darkPrimary focus:border-blue-500 block w-20 p-2.5 dark:bg-gray-700 dark:border-gray-600 placeholder-gray-500 dark:placeholder-gray-400 dark:text-white translate-y-0 rounded-l-md rounded-r-md w-full"
9+
/>
10+
</template>
11+
12+
<script setup lang="ts">
13+
import { ref, watch } from 'vue';
14+
15+
const emit = defineEmits(['update:modelValue']);
16+
17+
const props = defineProps<{
18+
column: any;
19+
meta?: any;
20+
modelValue: Array<{ operator: string; value: string }> | null;
21+
}>();
22+
23+
const localValue = ref(props.modelValue?.[0]?.value || '');
24+
25+
watch(() => props.modelValue, (val) => {
26+
localValue.value = val?.[0]?.value || '';
27+
});
28+
29+
function onInput(event: Event) {
30+
const target = event.target as HTMLInputElement;
31+
localValue.value = target.value;
32+
emit('update:modelValue', [{ operator: 'ilike', value: target.value }]);
33+
}
34+
</script>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<div class="text-center text-gray-500 text-sm mt-4">
3+
Login Page Text
4+
</div>
5+
</template>
6+
7+
<script setup>
8+
import { onMounted } from 'vue';
9+
10+
const props = defineProps<{
11+
reason: String
12+
}>();
13+
14+
onMounted(() => {
15+
// Logic on mount if needed
16+
});
17+
</script>
18+

adminforth/commands/postinstall.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
import { execSync } from 'child_process';
5+
const spaPath = path.join(import.meta.dirname, 'dist', 'spa');
6+
7+
8+
if (fs.existsSync(spaPath)){
9+
console.log('Installing SPA dependencies...');
10+
execSync('npm ci', { cwd: spaPath, stdio: 'inherit' });
11+
console.log('Installed spa dependencies');
12+
} else {
13+
console.log('SPA dependencies not found');
14+
console.log('current directory', import.meta.dirname);
15+
}

adminforth/documentation/blog/2024-10-01-ai-blog/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ model ContentImage {
199199
Create a migration:
200200

201201
```bash
202-
npm run makemigration -- --name add-posts
202+
npm run makemigration -- --name add-posts && npm run migrate:local
203203
```
204204

205205

0 commit comments

Comments
 (0)