Skip to content

Commit 1e91cf1

Browse files
committed
feat: Add getConfig script and replace commonjs to ESM for scripts
1 parent 708303b commit 1e91cf1

File tree

12 files changed

+324
-295
lines changed

12 files changed

+324
-295
lines changed

apps/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"init": "vitnode init",
8+
"test": "vitnode test",
89
"drizzle-kit": "drizzle-kit",
910
"db:push": "drizzle-kit push",
1011
"db:migrate": "drizzle-kit up && drizzle-kit generate && drizzle-kit migrate",

apps/web/src/app/[locale]/(main)/(plugins)/(blog)/blog/page.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { Link } from 'vitnode/lib/navigation';
2-
31
import { Test } from 'vitnode-blog/views/test';
42
import { TestClient } from 'vitnode-blog/views/test/client';
3+
import { Link } from 'vitnode/lib/navigation';
54

65
export default function Page() {
76
return (

apps/web/src/app/[locale]/(main)/(vitnode)/login/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Metadata } from 'next/dist/types';
22

33
import { getTranslations } from 'next-intl/server';
4-
54
import { SignInView } from 'vitnode/views/auth/sign-in/sign-in-view';
65

76
export const generateMetadata = async ({

apps/web/src/app/[locale]/(main)/(vitnode)/register/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Metadata } from 'next/dist/types';
22

33
import { getTranslations } from 'next-intl/server';
4-
54
import { SignUpView } from 'vitnode/views/auth/sign-up/sign-up-view';
65

76
export const generateMetadata = async ({

packages/eslint/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"strictBindCallApply": false,
1919
"allowSyntheticDefaultImports": true,
2020
"forceConsistentCasingInFileNames": true,
21-
"erasableSyntaxOnly": true
21+
"erasableSyntaxOnly": true,
22+
"verbatimModuleSyntax": true
2223
}
2324
}

packages/vitnode/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@
3636
"tailwindcss": "^4.1.5",
3737
"tsc-alias": "^1.8.15",
3838
"tsup": "^8.4.0",
39+
"tsx": "^4.19.4",
3940
"tw-animate-css": "^1.2.8",
4041
"typescript": "^5.8.3",
4142
"vite-tsconfig-paths": "^5.1.4",
4243
"vitest": "^3.1.2",
4344
"zod": "^3.24.3"
4445
},
4546
"bin": {
46-
"vitnode": "./dist/scripts/scripts.cjs"
47+
"vitnode": "./dist/scripts/scripts.js"
4748
},
4849
"exports": {
4950
"./api/config": {
@@ -60,9 +61,9 @@
6061
},
6162
"scripts": {
6263
"build:scripts": "tsup",
63-
"start:scripts": "node dist/scripts/scripts.cjs plugin --w",
64+
"start:scripts": "node dist/scripts/scripts.js plugin --w",
6465
"build": "tsc && swc src -d dist --config-file .swcrc && tsc-alias -p tsconfig.json",
65-
"dev": "concurrently \"tsc -w --preserveWatchOutput\" \"swc src -d dist --config-file .swcrc -w\" \"tsc-alias -w\" \"node dist/scripts/scripts.cjs plugin --w\"",
66+
"dev": "concurrently \"tsc -w --preserveWatchOutput\" \"swc src -d dist --config-file .swcrc -w\" \"tsc-alias -w\" \"node dist/scripts/scripts.js plugin --w\"",
6667
"dev:email": "email dev",
6768
"lint": "eslint .",
6869
"lint:fix": "eslint . --fix",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* eslint-disable no-console */
2+
import { join } from 'path';
3+
import { pathToFileURL } from 'url';
4+
5+
export const getConfig = async () => {
6+
const configPath = join(process.cwd(), 'src', 'vitnode.config.ts');
7+
try {
8+
const configUrl = pathToFileURL(configPath).href;
9+
const loaded = await import(configUrl);
10+
11+
const config = loaded.vitNodeConfig ?? loaded.default;
12+
console.log('Config metadata title:', config.metadata.title);
13+
} catch (error) {
14+
console.error('Failed to load config:', error);
15+
process.exit(1);
16+
}
17+
};

packages/vitnode/scripts/prepare-database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export const prepareDatabase = async ({
146146
await generateDatabaseMigrations();
147147
console.log(`${initMessage} [2/3] Run migrations...`);
148148
await runMigrations();
149-
console.log(`${initMessage} [3/3] Insert initial data...`);
149+
console.log(`\n${initMessage} [3/3] Insert initial data...`);
150150
await initialDataForDatabase();
151151
console.log(`${initMessage} \x1b[32mDatabase prepared successfully.\x1b[0m`);
152152
process.exit(0);

packages/vitnode/scripts/prepare-files.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
import { existsSync } from 'fs';
33
import { cp, mkdir } from 'fs/promises';
44
import { join } from 'path';
5+
import { dirname } from 'path';
6+
import { fileURLToPath } from 'url';
7+
8+
const __dirname = dirname(fileURLToPath(import.meta.url));
59

610
const copyDatabase = async (pluginsPath: string) => {
711
const databasePath = join(__dirname, '..', '..', 'src', 'database');

packages/vitnode/scripts/scripts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { existsSync } from 'fs';
44
import { join } from 'path';
55

6+
import { getConfig } from './get-config.js';
67
import { processPlugin } from './plugin.js';
78
import { prepareDatabase } from './prepare-database.js';
89
import { prepareFiles } from './prepare-files.js';
@@ -29,6 +30,8 @@ if (process.argv[2] === 'prepare') {
2930
(process.argv[3] === '--w' || process.argv[3] === '--watch')
3031
) {
3132
processPlugin({ initMessage });
33+
} else if (process.argv[2] === 'test') {
34+
void getConfig();
3235
} else {
3336
console.log(
3437
`${initMessage} \x1b[31mCommand not found: "${process.argv[2] ?? ''}"\x1b[0m`,

0 commit comments

Comments
 (0)