Skip to content

Commit d8d47f3

Browse files
committed
Merge branch 'next' of github.com:devforth/adminforth into next
2 parents 9a7e327 + 463e62d commit d8d47f3

File tree

93 files changed

+1147
-327
lines changed

Some content is hidden

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

93 files changed

+1147
-327
lines changed

adminforth/commands/callTsProxy.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,28 @@ import { spawn } from "child_process";
33
import path from "path";
44
import fs from "fs";
55
import chalk from "chalk";
6+
import dotenv from "dotenv";
67

78
const currentFilePath = import.meta.url;
89
const currentFileFolder = path.dirname(currentFilePath).replace("file:", "");
910

1011
export function callTsProxy(tsCode, silent=false) {
1112

13+
const currentDirectory = process.cwd();
14+
const envPath = path.resolve(currentDirectory, ".env");
15+
const envLocalPath = path.resolve(currentDirectory, ".env.local");
16+
if (fs.existsSync(envLocalPath)) {
17+
dotenv.config({ path: envLocalPath, override: true });
18+
}
19+
if (fs.existsSync(envPath)) {
20+
dotenv.config({ path: envPath, override: true });
21+
}
22+
1223
process.env.HEAVY_DEBUG && console.log("🌐 Calling tsproxy with code:", path.join(currentFileFolder, "proxy.ts"));
1324
return new Promise((resolve, reject) => {
14-
const child = spawn("tsx", [
15-
path.join(currentFileFolder, "proxy.ts")
16-
]);
17-
25+
const child = spawn("tsx", [path.join(currentFileFolder, "proxy.ts")], {
26+
env: process.env,
27+
});
1828
let stdout = "";
1929
let stderr = "";
2030

adminforth/commands/cli.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import createResource from "./createResource/main.js";
1212
import chalk from "chalk";
1313
import path from "path";
1414
import fs from "fs";
15+
import { fileURLToPath } from 'url';
1516

1617
function showHelp() {
1718
console.log(
@@ -25,19 +26,25 @@ function showHelp() {
2526
);
2627
}
2728

28-
function currentFileDir(importMetaUrl) {
29-
const filePath = importMetaUrl.replace("file://", "");
29+
export function currentFileDir(importMetaUrl) {
30+
const filePath = fileURLToPath(importMetaUrl);
3031
const fileDir = path.dirname(filePath);
3132
return fileDir;
3233
}
3334

34-
function showVersion() {
35+
export function getVersion() {
3536
const ADMIN_FORTH_ABSOLUTE_PATH = path.join(currentFileDir(import.meta.url), '..');
3637

3738
const package_json = JSON.parse(fs.readFileSync(path.join(ADMIN_FORTH_ABSOLUTE_PATH, 'package.json'), 'utf8'));
3839

3940
const ADMINFORTH_VERSION = package_json.version;
4041

42+
return ADMINFORTH_VERSION;
43+
}
44+
45+
function showVersion() {
46+
const ADMINFORTH_VERSION = getVersion();
47+
4148
console.log(
4249
chalk.white('AdminForth CLI version: ') +
4350
chalk.cyan.bold(ADMINFORTH_VERSION)

adminforth/commands/createApp/templates/custom/tsconfig.json.hbs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
"compilerOptions": {
33
"baseUrl": ".",
44
"paths": {
5-
"@/": "../node_modules/adminforth/dist/spa/src/",
6-
"": "../node_modules/adminforth/dist/spa/node_modules/",
7-
"@@/*": "."
5+
"@/*": ["../node_modules/adminforth/dist/spa/src/*"],
6+
"@@/*": ["./*"]
87
}
98
}
109
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import AdminForth from 'adminforth';
33
import usersResource from "./resources/adminuser.js";
44
import { fileURLToPath } from 'url';
55
import path from 'path';
6-
6+
77
const ADMIN_BASE_URL = '';
88

99
export const admin = new AdminForth({

adminforth/commands/createApp/templates/package.json.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"dependencies": {
2424
"@dotenvx/dotenvx": "^1.34.0",
25-
"adminforth": "latest",
25+
"adminforth": "{{adminforthVersion}}",
2626
"express": "latest-4"
2727
},
2828
"devDependencies": {

adminforth/commands/createApp/utils.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,31 @@ import { exec } from 'child_process';
1111

1212
import Handlebars from 'handlebars';
1313
import { promisify } from 'util';
14+
import { getVersion } from '../cli.js';
1415

1516
const execAsync = promisify(exec);
1617

18+
function detectAdminforthVersion() {
19+
try {
20+
const version = getVersion();
21+
22+
if (typeof version !== 'string') {
23+
throw new Error('Invalid version format');
24+
}
25+
26+
if (version.includes('next')) {
27+
return 'next';
28+
}
29+
return 'latest';
30+
} catch (err) {
31+
console.warn('⚠️ Could not detect AdminForth version, defaulting to "latest".');
32+
return 'latest';
33+
}
34+
}
35+
36+
const adminforthVersion = detectAdminforthVersion();
37+
38+
1739
export function parseArgumentsIntoOptions(rawArgs) {
1840
const args = arg(
1941
{
@@ -203,7 +225,10 @@ async function writeTemplateFiles(dirname, cwd, options) {
203225
{
204226
src: 'package.json.hbs',
205227
dest: 'package.json',
206-
data: { appName },
228+
data: {
229+
appName,
230+
adminforthVersion: adminforthVersion,
231+
},
207232
},
208233
{
209234
src: 'index.ts.hbs',
@@ -287,7 +312,7 @@ async function installDependencies(ctx, cwd) {
287312
const isWindows = process.platform === 'win32';
288313

289314
const nodeBinary = process.execPath;
290-
const npmPath = path.join(path.dirname(nodeBinary), 'npm');
315+
const npmPath = path.join(path.dirname(nodeBinary), isWindows ? 'npm.cmd' : 'npm');
291316
const customDir = ctx.customDir;
292317
if (isWindows) {
293318
const res = await Promise.all([

adminforth/dataConnectors/mongo.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,8 @@ class MongoConnector extends AdminForthBaseConnector implements IAdminForthDataS
194194
if (!value) {
195195
return null;
196196
}
197-
if (field._underlineType == 'timestamp' || field._underlineType == 'int') {
198-
// value is iso string now, convert to unix timestamp
199-
return dayjs(value).unix();
200-
} else if (field._underlineType == 'varchar') {
201-
// value is iso string now, convert to unix timestamp
202-
return dayjs(value).toISOString();
203-
}
197+
return dayjs(value).toDate();
198+
204199
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
205200
return value === null ? null : (value ? true : false);
206201
} else if (field.type == AdminForthDataTypes.DECIMAL) {

adminforth/documentation/blog/2024-08-05-chatgpt/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Today LLM is already a must tool to speed-up writing, brainstorming, or generati
1111

1212
Here is how it looks in action:
1313

14-
![alt text](../../docs/tutorial/05-Plugins/demoChatGpt.gif)
14+
![alt text](../../docs/tutorial/07-Plugins/demoChatGpt.gif)
1515

1616
<!-- truncate -->
1717

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 && npm run migrate:local
202+
npm run makemigration -- --name add-posts ; npm run migrate:local
203203
```
204204

205205

adminforth/documentation/docs/tutorial/001-gettingStarted.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ This will create a migration file in `migrations` and apply it to the database.
8989
In future, when you need to add new resources, you need to modify `schema.prisma` (add models, change fields, etc.). After doing any modification you need to create a new migration using next command:
9090

9191
```bash
92-
npm run makemigration -- --name init && npm run migrate:local
92+
npm run makemigration -- --name init ; npm run migrate:local
9393
```
9494

9595
Other developers need to pull migration and run `npm run migrateLocal` to apply any unapplied migrations.
@@ -173,7 +173,7 @@ model apartments {
173173
Run the following command to create a new migration:
174174

175175
```bash
176-
npm run makemigration -- --name add-apartments && npm run migrate:local
176+
npm run makemigration -- --name add-apartments ; npm run migrate:local
177177
```
178178

179179
### Step3. Create the `apartments` resource
@@ -314,7 +314,7 @@ Open `index.ts` in your project root and import the new resource:
314314
```ts title="./index.ts"
315315
...
316316
//diff-add
317-
import apartmentsResource from "./resources/apartments";
317+
import apartmentsResource from "./resources/apartments.js";
318318

319319
...
320320
export const admin = new AdminForth({
@@ -409,7 +409,7 @@ async function seedDatabase() {
409409
//diff-add
410410
};
411411

412-
if (import.meta.url === `file://${process.argv[1]}`) {
412+
if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
413413

414414
...
415415

0 commit comments

Comments
 (0)