@geekmidas/cli 0.28.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{config-BhryDQEq.cjs → config-BAE9LFC1.cjs} +2 -2
- package/dist/{config-BhryDQEq.cjs.map → config-BAE9LFC1.cjs.map} +1 -1
- package/dist/{config-C9bdq0l-.mjs → config-BC5n1a2D.mjs} +2 -2
- package/dist/{config-C9bdq0l-.mjs.map → config-BC5n1a2D.mjs.map} +1 -1
- package/dist/config.cjs +2 -2
- package/dist/config.d.cts +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +2 -2
- package/dist/{index-CWN-bgrO.d.mts → index-C7TkoYmt.d.mts} +5 -1
- package/dist/index-C7TkoYmt.d.mts.map +1 -0
- package/dist/{index-DEWYvYvg.d.cts → index-CpchsC9w.d.cts} +5 -1
- package/dist/index-CpchsC9w.d.cts.map +1 -0
- package/dist/index.cjs +139 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +139 -46
- package/dist/index.mjs.map +1 -1
- package/dist/{openapi-BCEFhkLh.mjs → openapi-CjYeF-Tg.mjs} +2 -2
- package/dist/{openapi-BCEFhkLh.mjs.map → openapi-CjYeF-Tg.mjs.map} +1 -1
- package/dist/{openapi-D82bBqG7.cjs → openapi-a-e3Y8WA.cjs} +2 -2
- package/dist/{openapi-D82bBqG7.cjs.map → openapi-a-e3Y8WA.cjs.map} +1 -1
- package/dist/openapi.cjs +3 -3
- package/dist/openapi.mjs +3 -3
- package/dist/workspace/index.cjs +1 -1
- package/dist/workspace/index.d.cts +1 -1
- package/dist/workspace/index.d.mts +1 -1
- package/dist/workspace/index.mjs +1 -1
- package/dist/{workspace-DQjmv9lk.mjs → workspace-DFJ3sWfY.mjs} +19 -3
- package/dist/{workspace-DQjmv9lk.mjs.map → workspace-DFJ3sWfY.mjs.map} +1 -1
- package/dist/{workspace-CiZBOjf9.cjs → workspace-My0A4IRO.cjs} +19 -3
- package/dist/{workspace-CiZBOjf9.cjs.map → workspace-My0A4IRO.cjs.map} +1 -1
- package/package.json +3 -3
- package/src/dev/__tests__/index.spec.ts +223 -0
- package/src/dev/index.ts +83 -4
- package/src/init/__tests__/generators.spec.ts +17 -9
- package/src/init/generators/web.ts +86 -37
- package/src/workspace/__tests__/schema.spec.ts +114 -0
- package/src/workspace/schema.ts +23 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/index-CWN-bgrO.d.mts.map +0 -1
- package/dist/index-DEWYvYvg.d.cts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "CLI tools for building Lambda handlers, server applications, and generating OpenAPI specs",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
"lodash.kebabcase": "^4.1.1",
|
|
49
49
|
"openapi-typescript": "^7.4.2",
|
|
50
50
|
"prompts": "~2.4.2",
|
|
51
|
-
"@geekmidas/logger": "~0.4.0",
|
|
52
51
|
"@geekmidas/errors": "~0.1.0",
|
|
53
|
-
"@geekmidas/
|
|
52
|
+
"@geekmidas/logger": "~0.4.0",
|
|
54
53
|
"@geekmidas/constructs": "~0.6.0",
|
|
54
|
+
"@geekmidas/envkit": "~0.5.0",
|
|
55
55
|
"@geekmidas/schema": "~0.1.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
findAvailablePort,
|
|
14
14
|
generateAllDependencyEnvVars,
|
|
15
15
|
isPortAvailable,
|
|
16
|
+
loadSecretsForApp,
|
|
16
17
|
normalizeHooksConfig,
|
|
17
18
|
normalizeProductionConfig,
|
|
18
19
|
normalizeStudioConfig,
|
|
@@ -967,3 +968,225 @@ describe('Workspace Dev Server', () => {
|
|
|
967
968
|
});
|
|
968
969
|
});
|
|
969
970
|
});
|
|
971
|
+
|
|
972
|
+
describe('loadSecretsForApp', () => {
|
|
973
|
+
let testDir: string;
|
|
974
|
+
|
|
975
|
+
beforeEach(() => {
|
|
976
|
+
testDir = join(
|
|
977
|
+
tmpdir(),
|
|
978
|
+
`gkm-secrets-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
979
|
+
);
|
|
980
|
+
mkdirSync(testDir, { recursive: true });
|
|
981
|
+
});
|
|
982
|
+
|
|
983
|
+
afterEach(() => {
|
|
984
|
+
if (existsSync(testDir)) {
|
|
985
|
+
rmSync(testDir, { recursive: true, force: true });
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
|
|
989
|
+
/**
|
|
990
|
+
* Helper to create a secrets file in legacy (unencrypted) format.
|
|
991
|
+
* This matches the StageSecrets structure.
|
|
992
|
+
*/
|
|
993
|
+
function createSecretsFile(
|
|
994
|
+
stage: string,
|
|
995
|
+
secrets: Record<string, string>,
|
|
996
|
+
root = testDir,
|
|
997
|
+
) {
|
|
998
|
+
const secretsDir = join(root, '.gkm', 'secrets');
|
|
999
|
+
mkdirSync(secretsDir, { recursive: true });
|
|
1000
|
+
const stageSecrets = {
|
|
1001
|
+
stage,
|
|
1002
|
+
createdAt: new Date().toISOString(),
|
|
1003
|
+
updatedAt: new Date().toISOString(),
|
|
1004
|
+
services: {},
|
|
1005
|
+
urls: {},
|
|
1006
|
+
custom: secrets,
|
|
1007
|
+
};
|
|
1008
|
+
writeFileSync(
|
|
1009
|
+
join(secretsDir, `${stage}.json`),
|
|
1010
|
+
JSON.stringify(stageSecrets, null, 2),
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
describe('single app mode (no appName)', () => {
|
|
1015
|
+
it('should return secrets as-is without mapping', async () => {
|
|
1016
|
+
createSecretsFile('development', {
|
|
1017
|
+
DATABASE_URL: 'postgresql://localhost/mydb',
|
|
1018
|
+
JWT_SECRET: 'super-secret',
|
|
1019
|
+
NODE_ENV: 'development',
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
const secrets = await loadSecretsForApp(testDir);
|
|
1023
|
+
|
|
1024
|
+
expect(secrets).toEqual({
|
|
1025
|
+
DATABASE_URL: 'postgresql://localhost/mydb',
|
|
1026
|
+
JWT_SECRET: 'super-secret',
|
|
1027
|
+
NODE_ENV: 'development',
|
|
1028
|
+
});
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
it('should try dev stage first, then development', async () => {
|
|
1032
|
+
createSecretsFile('dev', {
|
|
1033
|
+
DATABASE_URL: 'postgresql://localhost/devdb',
|
|
1034
|
+
});
|
|
1035
|
+
createSecretsFile('development', {
|
|
1036
|
+
DATABASE_URL: 'postgresql://localhost/developmentdb',
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
const secrets = await loadSecretsForApp(testDir);
|
|
1040
|
+
|
|
1041
|
+
// Should use 'dev' stage since it's checked first
|
|
1042
|
+
expect(secrets.DATABASE_URL).toBe('postgresql://localhost/devdb');
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
it('should fallback to development if dev does not exist', async () => {
|
|
1046
|
+
createSecretsFile('development', {
|
|
1047
|
+
DATABASE_URL: 'postgresql://localhost/developmentdb',
|
|
1048
|
+
});
|
|
1049
|
+
|
|
1050
|
+
const secrets = await loadSecretsForApp(testDir);
|
|
1051
|
+
|
|
1052
|
+
expect(secrets.DATABASE_URL).toBe(
|
|
1053
|
+
'postgresql://localhost/developmentdb',
|
|
1054
|
+
);
|
|
1055
|
+
});
|
|
1056
|
+
|
|
1057
|
+
it('should return empty object if no secrets exist', async () => {
|
|
1058
|
+
const secrets = await loadSecretsForApp(testDir);
|
|
1059
|
+
|
|
1060
|
+
expect(secrets).toEqual({});
|
|
1061
|
+
});
|
|
1062
|
+
});
|
|
1063
|
+
|
|
1064
|
+
describe('workspace app mode (with appName)', () => {
|
|
1065
|
+
it('should map {APP}_DATABASE_URL to DATABASE_URL', async () => {
|
|
1066
|
+
createSecretsFile('development', {
|
|
1067
|
+
AUTH_DATABASE_URL: 'postgresql://auth_user:pass@localhost/authdb',
|
|
1068
|
+
API_DATABASE_URL: 'postgresql://api_user:pass@localhost/apidb',
|
|
1069
|
+
JWT_SECRET: 'shared-secret',
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
const authSecrets = await loadSecretsForApp(testDir, 'auth');
|
|
1073
|
+
|
|
1074
|
+
expect(authSecrets.DATABASE_URL).toBe(
|
|
1075
|
+
'postgresql://auth_user:pass@localhost/authdb',
|
|
1076
|
+
);
|
|
1077
|
+
// Original prefixed secrets are also available
|
|
1078
|
+
expect(authSecrets.AUTH_DATABASE_URL).toBe(
|
|
1079
|
+
'postgresql://auth_user:pass@localhost/authdb',
|
|
1080
|
+
);
|
|
1081
|
+
expect(authSecrets.JWT_SECRET).toBe('shared-secret');
|
|
1082
|
+
});
|
|
1083
|
+
|
|
1084
|
+
it('should map API secrets correctly', async () => {
|
|
1085
|
+
createSecretsFile('development', {
|
|
1086
|
+
AUTH_DATABASE_URL: 'postgresql://auth_user:pass@localhost/authdb',
|
|
1087
|
+
API_DATABASE_URL: 'postgresql://api_user:pass@localhost/apidb',
|
|
1088
|
+
});
|
|
1089
|
+
|
|
1090
|
+
const apiSecrets = await loadSecretsForApp(testDir, 'api');
|
|
1091
|
+
|
|
1092
|
+
expect(apiSecrets.DATABASE_URL).toBe(
|
|
1093
|
+
'postgresql://api_user:pass@localhost/apidb',
|
|
1094
|
+
);
|
|
1095
|
+
});
|
|
1096
|
+
|
|
1097
|
+
it('should not override DATABASE_URL if no prefixed version exists', async () => {
|
|
1098
|
+
createSecretsFile('development', {
|
|
1099
|
+
DATABASE_URL: 'postgresql://localhost/maindb',
|
|
1100
|
+
JWT_SECRET: 'secret',
|
|
1101
|
+
});
|
|
1102
|
+
|
|
1103
|
+
// Asking for 'auth' app but AUTH_DATABASE_URL doesn't exist
|
|
1104
|
+
const authSecrets = await loadSecretsForApp(testDir, 'auth');
|
|
1105
|
+
|
|
1106
|
+
// Should keep the original DATABASE_URL since there's no AUTH_DATABASE_URL
|
|
1107
|
+
expect(authSecrets.DATABASE_URL).toBe('postgresql://localhost/maindb');
|
|
1108
|
+
});
|
|
1109
|
+
|
|
1110
|
+
it('should handle uppercase app names in secrets', async () => {
|
|
1111
|
+
createSecretsFile('development', {
|
|
1112
|
+
MYSERVICE_DATABASE_URL: 'postgresql://localhost/myservicedb',
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
// App name is lowercase but secrets are uppercase prefixed
|
|
1116
|
+
const secrets = await loadSecretsForApp(testDir, 'myservice');
|
|
1117
|
+
|
|
1118
|
+
expect(secrets.DATABASE_URL).toBe('postgresql://localhost/myservicedb');
|
|
1119
|
+
});
|
|
1120
|
+
|
|
1121
|
+
it('should return empty object if no secrets exist for app', async () => {
|
|
1122
|
+
const secrets = await loadSecretsForApp(testDir, 'api');
|
|
1123
|
+
|
|
1124
|
+
expect(secrets).toEqual({});
|
|
1125
|
+
});
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1128
|
+
describe('service credentials mapping', () => {
|
|
1129
|
+
it('should include postgres service credentials', async () => {
|
|
1130
|
+
const secretsDir = join(testDir, '.gkm', 'secrets');
|
|
1131
|
+
mkdirSync(secretsDir, { recursive: true });
|
|
1132
|
+
const stageSecrets = {
|
|
1133
|
+
stage: 'development',
|
|
1134
|
+
createdAt: new Date().toISOString(),
|
|
1135
|
+
updatedAt: new Date().toISOString(),
|
|
1136
|
+
services: {
|
|
1137
|
+
postgres: {
|
|
1138
|
+
username: 'postgres',
|
|
1139
|
+
password: 'postgres123',
|
|
1140
|
+
database: 'myapp',
|
|
1141
|
+
host: 'localhost',
|
|
1142
|
+
port: 5432,
|
|
1143
|
+
},
|
|
1144
|
+
},
|
|
1145
|
+
urls: {},
|
|
1146
|
+
custom: { NODE_ENV: 'development' },
|
|
1147
|
+
};
|
|
1148
|
+
writeFileSync(
|
|
1149
|
+
join(secretsDir, 'development.json'),
|
|
1150
|
+
JSON.stringify(stageSecrets, null, 2),
|
|
1151
|
+
);
|
|
1152
|
+
|
|
1153
|
+
const secrets = await loadSecretsForApp(testDir);
|
|
1154
|
+
|
|
1155
|
+
expect(secrets.POSTGRES_USER).toBe('postgres');
|
|
1156
|
+
expect(secrets.POSTGRES_PASSWORD).toBe('postgres123');
|
|
1157
|
+
expect(secrets.POSTGRES_DB).toBe('myapp');
|
|
1158
|
+
expect(secrets.POSTGRES_HOST).toBe('localhost');
|
|
1159
|
+
expect(secrets.POSTGRES_PORT).toBe('5432');
|
|
1160
|
+
expect(secrets.NODE_ENV).toBe('development');
|
|
1161
|
+
});
|
|
1162
|
+
|
|
1163
|
+
it('should include redis service credentials', async () => {
|
|
1164
|
+
const secretsDir = join(testDir, '.gkm', 'secrets');
|
|
1165
|
+
mkdirSync(secretsDir, { recursive: true });
|
|
1166
|
+
const stageSecrets = {
|
|
1167
|
+
stage: 'development',
|
|
1168
|
+
createdAt: new Date().toISOString(),
|
|
1169
|
+
updatedAt: new Date().toISOString(),
|
|
1170
|
+
services: {
|
|
1171
|
+
redis: {
|
|
1172
|
+
password: 'redis123',
|
|
1173
|
+
host: 'localhost',
|
|
1174
|
+
port: 6379,
|
|
1175
|
+
},
|
|
1176
|
+
},
|
|
1177
|
+
urls: {},
|
|
1178
|
+
custom: {},
|
|
1179
|
+
};
|
|
1180
|
+
writeFileSync(
|
|
1181
|
+
join(secretsDir, 'development.json'),
|
|
1182
|
+
JSON.stringify(stageSecrets, null, 2),
|
|
1183
|
+
);
|
|
1184
|
+
|
|
1185
|
+
const secrets = await loadSecretsForApp(testDir);
|
|
1186
|
+
|
|
1187
|
+
expect(secrets.REDIS_PASSWORD).toBe('redis123');
|
|
1188
|
+
expect(secrets.REDIS_HOST).toBe('localhost');
|
|
1189
|
+
expect(secrets.REDIS_PORT).toBe('6379');
|
|
1190
|
+
});
|
|
1191
|
+
});
|
|
1192
|
+
});
|
package/src/dev/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ChildProcess, execSync, spawn } from 'node:child_process';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
|
-
import { mkdir } from 'node:fs/promises';
|
|
3
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { createServer } from 'node:net';
|
|
5
5
|
import { join, resolve } from 'node:path';
|
|
6
6
|
import chokidar from 'chokidar';
|
|
@@ -318,6 +318,8 @@ export async function devCommand(options: DevOptions): Promise<void> {
|
|
|
318
318
|
const appName = getAppNameFromCwd();
|
|
319
319
|
let config: GkmConfig;
|
|
320
320
|
let appRoot: string = process.cwd();
|
|
321
|
+
let secretsRoot: string = process.cwd(); // Where .gkm/secrets/ lives
|
|
322
|
+
let workspaceAppName: string | undefined; // Set if in workspace mode
|
|
321
323
|
|
|
322
324
|
if (appName) {
|
|
323
325
|
// Try to load app-specific config from workspace
|
|
@@ -325,6 +327,8 @@ export async function devCommand(options: DevOptions): Promise<void> {
|
|
|
325
327
|
const appConfig = await loadAppConfig();
|
|
326
328
|
config = appConfig.gkmConfig;
|
|
327
329
|
appRoot = appConfig.appRoot;
|
|
330
|
+
secretsRoot = appConfig.workspaceRoot;
|
|
331
|
+
workspaceAppName = appConfig.appName;
|
|
328
332
|
logger.log(`📦 Running app: ${appConfig.appName}`);
|
|
329
333
|
} catch {
|
|
330
334
|
// Not in a workspace or app not found in workspace - fall back to regular loading
|
|
@@ -438,6 +442,17 @@ export async function devCommand(options: DevOptions): Promise<void> {
|
|
|
438
442
|
// Determine runtime (default to node)
|
|
439
443
|
const runtime: Runtime = config.runtime ?? 'node';
|
|
440
444
|
|
|
445
|
+
// Load secrets for dev mode and write to JSON file
|
|
446
|
+
let secretsJsonPath: string | undefined;
|
|
447
|
+
const appSecrets = await loadSecretsForApp(secretsRoot, workspaceAppName);
|
|
448
|
+
if (Object.keys(appSecrets).length > 0) {
|
|
449
|
+
const secretsDir = join(secretsRoot, '.gkm');
|
|
450
|
+
await mkdir(secretsDir, { recursive: true });
|
|
451
|
+
secretsJsonPath = join(secretsDir, 'dev-secrets.json');
|
|
452
|
+
await writeFile(secretsJsonPath, JSON.stringify(appSecrets, null, 2));
|
|
453
|
+
logger.log(`🔐 Loaded ${Object.keys(appSecrets).length} secret(s)`);
|
|
454
|
+
}
|
|
455
|
+
|
|
441
456
|
// Start the dev server
|
|
442
457
|
const devServer = new DevServer(
|
|
443
458
|
resolved.providers[0] as LegacyProvider,
|
|
@@ -448,6 +463,7 @@ export async function devCommand(options: DevOptions): Promise<void> {
|
|
|
448
463
|
studio,
|
|
449
464
|
runtime,
|
|
450
465
|
appRoot,
|
|
466
|
+
secretsJsonPath,
|
|
451
467
|
);
|
|
452
468
|
|
|
453
469
|
await devServer.start();
|
|
@@ -754,6 +770,54 @@ export async function loadDevSecrets(
|
|
|
754
770
|
return {};
|
|
755
771
|
}
|
|
756
772
|
|
|
773
|
+
/**
|
|
774
|
+
* Load secrets from a path for dev mode.
|
|
775
|
+
* For single app: returns secrets as-is.
|
|
776
|
+
* For workspace app: maps {APP}_DATABASE_URL → DATABASE_URL.
|
|
777
|
+
* @internal Exported for testing
|
|
778
|
+
*/
|
|
779
|
+
export async function loadSecretsForApp(
|
|
780
|
+
secretsRoot: string,
|
|
781
|
+
appName?: string,
|
|
782
|
+
): Promise<Record<string, string>> {
|
|
783
|
+
// Try 'dev' stage first, then 'development'
|
|
784
|
+
const stages = ['dev', 'development'];
|
|
785
|
+
|
|
786
|
+
let secrets: Record<string, string> = {};
|
|
787
|
+
|
|
788
|
+
for (const stage of stages) {
|
|
789
|
+
if (secretsExist(stage, secretsRoot)) {
|
|
790
|
+
const stageSecrets = await readStageSecrets(stage, secretsRoot);
|
|
791
|
+
if (stageSecrets) {
|
|
792
|
+
logger.log(`🔐 Loading secrets from stage: ${stage}`);
|
|
793
|
+
secrets = toEmbeddableSecrets(stageSecrets);
|
|
794
|
+
break;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
if (Object.keys(secrets).length === 0) {
|
|
800
|
+
return {};
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// Single app mode - no mapping needed
|
|
804
|
+
if (!appName) {
|
|
805
|
+
return secrets;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// Workspace app mode - map {APP}_* to generic names
|
|
809
|
+
const prefix = appName.toUpperCase();
|
|
810
|
+
const mapped = { ...secrets };
|
|
811
|
+
|
|
812
|
+
// Map {APP}_DATABASE_URL → DATABASE_URL
|
|
813
|
+
const appDbUrl = secrets[`${prefix}_DATABASE_URL`];
|
|
814
|
+
if (appDbUrl) {
|
|
815
|
+
mapped.DATABASE_URL = appDbUrl;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
return mapped;
|
|
819
|
+
}
|
|
820
|
+
|
|
757
821
|
/**
|
|
758
822
|
* Start docker-compose services for the workspace.
|
|
759
823
|
* @internal Exported for testing
|
|
@@ -1192,6 +1256,7 @@ class DevServer {
|
|
|
1192
1256
|
private studio: NormalizedStudioConfig | undefined,
|
|
1193
1257
|
private runtime: Runtime = 'node',
|
|
1194
1258
|
private appRoot: string = process.cwd(),
|
|
1259
|
+
private secretsJsonPath?: string,
|
|
1195
1260
|
) {
|
|
1196
1261
|
this.actualPort = requestedPort;
|
|
1197
1262
|
}
|
|
@@ -1341,7 +1406,7 @@ class DevServer {
|
|
|
1341
1406
|
}
|
|
1342
1407
|
|
|
1343
1408
|
private async createServerEntry(): Promise<void> {
|
|
1344
|
-
const { writeFile } = await import('node:fs/promises');
|
|
1409
|
+
const { writeFile: fsWriteFile } = await import('node:fs/promises');
|
|
1345
1410
|
const { relative, dirname } = await import('node:path');
|
|
1346
1411
|
|
|
1347
1412
|
const serverPath = join(this.appRoot, '.gkm', this.provider, 'server.ts');
|
|
@@ -1351,6 +1416,20 @@ class DevServer {
|
|
|
1351
1416
|
join(dirname(serverPath), 'app.js'),
|
|
1352
1417
|
);
|
|
1353
1418
|
|
|
1419
|
+
// Generate credentials injection code if secrets are available
|
|
1420
|
+
const credentialsInjection = this.secretsJsonPath
|
|
1421
|
+
? `import { Credentials } from '@geekmidas/envkit/credentials';
|
|
1422
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
1423
|
+
|
|
1424
|
+
// Inject dev secrets into Credentials (must happen before app import)
|
|
1425
|
+
const secretsPath = '${this.secretsJsonPath}';
|
|
1426
|
+
if (existsSync(secretsPath)) {
|
|
1427
|
+
Object.assign(Credentials, JSON.parse(readFileSync(secretsPath, 'utf-8')));
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
`
|
|
1431
|
+
: '';
|
|
1432
|
+
|
|
1354
1433
|
const serveCode =
|
|
1355
1434
|
this.runtime === 'bun'
|
|
1356
1435
|
? `Bun.serve({
|
|
@@ -1374,7 +1453,7 @@ class DevServer {
|
|
|
1374
1453
|
* Development server entry point
|
|
1375
1454
|
* This file is auto-generated by 'gkm dev'
|
|
1376
1455
|
*/
|
|
1377
|
-
import { createApp } from './${relativeAppPath.startsWith('.') ? relativeAppPath : `./${relativeAppPath}`}';
|
|
1456
|
+
${credentialsInjection}import { createApp } from './${relativeAppPath.startsWith('.') ? relativeAppPath : `./${relativeAppPath}`}';
|
|
1378
1457
|
|
|
1379
1458
|
const port = process.argv.includes('--port')
|
|
1380
1459
|
? Number.parseInt(process.argv[process.argv.indexOf('--port') + 1])
|
|
@@ -1395,6 +1474,6 @@ start({
|
|
|
1395
1474
|
});
|
|
1396
1475
|
`;
|
|
1397
1476
|
|
|
1398
|
-
await
|
|
1477
|
+
await fsWriteFile(serverPath, content);
|
|
1399
1478
|
}
|
|
1400
1479
|
}
|
|
@@ -15,9 +15,14 @@ const baseOptions: TemplateOptions = {
|
|
|
15
15
|
template: 'minimal',
|
|
16
16
|
telescope: true,
|
|
17
17
|
database: true,
|
|
18
|
-
|
|
18
|
+
studio: true,
|
|
19
|
+
loggerType: 'pino',
|
|
20
|
+
routesStructure: 'centralized-endpoints',
|
|
19
21
|
monorepo: false,
|
|
20
22
|
apiPath: '',
|
|
23
|
+
packageManager: 'pnpm',
|
|
24
|
+
deployTarget: 'dokploy',
|
|
25
|
+
services: { db: true, cache: true, mail: false },
|
|
21
26
|
};
|
|
22
27
|
|
|
23
28
|
describe('generatePackageJson', () => {
|
|
@@ -161,7 +166,8 @@ describe('generateConfigFiles', () => {
|
|
|
161
166
|
};
|
|
162
167
|
const files = generateConfigFiles(options, minimalTemplate);
|
|
163
168
|
const tsConfig = files.find((f) => f.path === 'tsconfig.json');
|
|
164
|
-
|
|
169
|
+
expect(tsConfig).toBeDefined();
|
|
170
|
+
const config = JSON.parse(tsConfig!.content);
|
|
165
171
|
expect(config.extends).toBe('../../tsconfig.json');
|
|
166
172
|
expect(config.compilerOptions.paths).toBeDefined();
|
|
167
173
|
expect(config.compilerOptions.paths['@test-project/*']).toBeDefined();
|
|
@@ -274,7 +280,8 @@ describe('generateMonorepoFiles', () => {
|
|
|
274
280
|
};
|
|
275
281
|
const files = generateMonorepoFiles(options, minimalTemplate);
|
|
276
282
|
const pkgJson = files.find((f) => f.path === 'package.json');
|
|
277
|
-
|
|
283
|
+
expect(pkgJson).toBeDefined();
|
|
284
|
+
const pkg = JSON.parse(pkgJson!.content);
|
|
278
285
|
expect(pkg.scripts.dev).toBe('turbo dev');
|
|
279
286
|
expect(pkg.scripts.build).toBe('turbo build');
|
|
280
287
|
expect(pkg.scripts.lint).toBe('biome lint .');
|
|
@@ -311,7 +318,8 @@ describe('generateModelsPackage', () => {
|
|
|
311
318
|
const pkgJson = files.find(
|
|
312
319
|
(f) => f.path === 'packages/models/package.json',
|
|
313
320
|
);
|
|
314
|
-
|
|
321
|
+
expect(pkgJson).toBeDefined();
|
|
322
|
+
const pkg = JSON.parse(pkgJson!.content);
|
|
315
323
|
expect(pkg.name).toBe('@test-project/models');
|
|
316
324
|
});
|
|
317
325
|
|
|
@@ -325,7 +333,8 @@ describe('generateModelsPackage', () => {
|
|
|
325
333
|
const pkgJson = files.find(
|
|
326
334
|
(f) => f.path === 'packages/models/package.json',
|
|
327
335
|
);
|
|
328
|
-
|
|
336
|
+
expect(pkgJson).toBeDefined();
|
|
337
|
+
const pkg = JSON.parse(pkgJson!.content);
|
|
329
338
|
expect(pkg.dependencies.zod).toBeDefined();
|
|
330
339
|
});
|
|
331
340
|
|
|
@@ -336,9 +345,7 @@ describe('generateModelsPackage', () => {
|
|
|
336
345
|
apiPath: 'apps/api',
|
|
337
346
|
};
|
|
338
347
|
const files = generateModelsPackage(options);
|
|
339
|
-
const userTs = files.find(
|
|
340
|
-
(f) => f.path === 'packages/models/src/user.ts',
|
|
341
|
-
);
|
|
348
|
+
const userTs = files.find((f) => f.path === 'packages/models/src/user.ts');
|
|
342
349
|
const commonTs = files.find(
|
|
343
350
|
(f) => f.path === 'packages/models/src/common.ts',
|
|
344
351
|
);
|
|
@@ -359,7 +366,8 @@ describe('generateModelsPackage', () => {
|
|
|
359
366
|
const tsConfig = files.find(
|
|
360
367
|
(f) => f.path === 'packages/models/tsconfig.json',
|
|
361
368
|
);
|
|
362
|
-
|
|
369
|
+
expect(tsConfig).toBeDefined();
|
|
370
|
+
const config = JSON.parse(tsConfig!.content);
|
|
363
371
|
expect(config.extends).toBe('../../tsconfig.json');
|
|
364
372
|
});
|
|
365
373
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GeneratedFile, TemplateOptions } from '../templates/index.js';
|
|
2
|
+
import { GEEKMIDAS_VERSIONS } from '../versions.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Generate Next.js web app files for fullstack template
|
|
@@ -25,6 +26,8 @@ export function generateWebAppFiles(options: TemplateOptions): GeneratedFile[] {
|
|
|
25
26
|
},
|
|
26
27
|
dependencies: {
|
|
27
28
|
[modelsPackage]: 'workspace:*',
|
|
29
|
+
'@geekmidas/client': GEEKMIDAS_VERSIONS['@geekmidas/client'],
|
|
30
|
+
'@tanstack/react-query': '~5.80.0',
|
|
28
31
|
next: '~16.1.0',
|
|
29
32
|
react: '~19.2.0',
|
|
30
33
|
'react-dom': '~19.2.0',
|
|
@@ -82,8 +85,73 @@ export default nextConfig;
|
|
|
82
85
|
exclude: ['node_modules'],
|
|
83
86
|
};
|
|
84
87
|
|
|
88
|
+
// Providers with QueryClient
|
|
89
|
+
const providersTsx = `'use client';
|
|
90
|
+
|
|
91
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
92
|
+
import { useState } from 'react';
|
|
93
|
+
|
|
94
|
+
export function Providers({ children }: { children: React.ReactNode }) {
|
|
95
|
+
const [queryClient] = useState(
|
|
96
|
+
() =>
|
|
97
|
+
new QueryClient({
|
|
98
|
+
defaultOptions: {
|
|
99
|
+
queries: {
|
|
100
|
+
staleTime: 60 * 1000,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
}),
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
`;
|
|
111
|
+
|
|
112
|
+
// API client setup
|
|
113
|
+
const apiIndexTs = `import { TypedFetcher } from '@geekmidas/client/fetcher';
|
|
114
|
+
import { createEndpointHooks } from '@geekmidas/client/endpoint-hooks';
|
|
115
|
+
|
|
116
|
+
// TODO: Run 'gkm openapi' to generate typed paths from your API
|
|
117
|
+
// This is a placeholder that will be replaced by the generated openapi.ts
|
|
118
|
+
interface paths {
|
|
119
|
+
'/health': {
|
|
120
|
+
get: {
|
|
121
|
+
responses: {
|
|
122
|
+
200: {
|
|
123
|
+
content: {
|
|
124
|
+
'application/json': { status: string; timestamp: string };
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
'/users': {
|
|
131
|
+
get: {
|
|
132
|
+
responses: {
|
|
133
|
+
200: {
|
|
134
|
+
content: {
|
|
135
|
+
'application/json': { users: Array<{ id: string; name: string }> };
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const baseURL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000';
|
|
144
|
+
|
|
145
|
+
const fetcher = new TypedFetcher<paths>({ baseURL });
|
|
146
|
+
|
|
147
|
+
const hooks = createEndpointHooks<paths>(fetcher.request.bind(fetcher));
|
|
148
|
+
|
|
149
|
+
export const api = Object.assign(fetcher.request.bind(fetcher), hooks);
|
|
150
|
+
`;
|
|
151
|
+
|
|
85
152
|
// App layout
|
|
86
153
|
const layoutTsx = `import type { Metadata } from 'next';
|
|
154
|
+
import { Providers } from './providers';
|
|
87
155
|
|
|
88
156
|
export const metadata: Metadata = {
|
|
89
157
|
title: '${options.name}',
|
|
@@ -97,37 +165,20 @@ export default function RootLayout({
|
|
|
97
165
|
}) {
|
|
98
166
|
return (
|
|
99
167
|
<html lang="en">
|
|
100
|
-
<body>
|
|
168
|
+
<body>
|
|
169
|
+
<Providers>{children}</Providers>
|
|
170
|
+
</body>
|
|
101
171
|
</html>
|
|
102
172
|
);
|
|
103
173
|
}
|
|
104
174
|
`;
|
|
105
175
|
|
|
106
176
|
// Home page with API example
|
|
107
|
-
const pageTsx = `import
|
|
177
|
+
const pageTsx = `import { api } from '@/api';
|
|
108
178
|
|
|
109
179
|
export default async function Home() {
|
|
110
|
-
//
|
|
111
|
-
const
|
|
112
|
-
let health = null;
|
|
113
|
-
|
|
114
|
-
try {
|
|
115
|
-
const response = await fetch(\`\${apiUrl}/health\`, {
|
|
116
|
-
cache: 'no-store',
|
|
117
|
-
});
|
|
118
|
-
health = await response.json();
|
|
119
|
-
} catch (error) {
|
|
120
|
-
console.error('Failed to fetch health:', error);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Example: Type-safe model usage
|
|
124
|
-
const exampleUser: User = {
|
|
125
|
-
id: '123e4567-e89b-12d3-a456-426614174000',
|
|
126
|
-
email: 'user@example.com',
|
|
127
|
-
name: 'Example User',
|
|
128
|
-
createdAt: new Date(),
|
|
129
|
-
updatedAt: new Date(),
|
|
130
|
-
};
|
|
180
|
+
// Type-safe API call using the generated client
|
|
181
|
+
const health = await api('GET /health').catch(() => null);
|
|
131
182
|
|
|
132
183
|
return (
|
|
133
184
|
<main style={{ padding: '2rem', fontFamily: 'system-ui' }}>
|
|
@@ -140,21 +191,14 @@ export default async function Home() {
|
|
|
140
191
|
{JSON.stringify(health, null, 2)}
|
|
141
192
|
</pre>
|
|
142
193
|
) : (
|
|
143
|
-
<p>Unable to connect to API
|
|
194
|
+
<p>Unable to connect to API</p>
|
|
144
195
|
)}
|
|
145
196
|
</section>
|
|
146
197
|
|
|
147
|
-
<section style={{ marginTop: '2rem' }}>
|
|
148
|
-
<h2>Shared Models</h2>
|
|
149
|
-
<p>This user object is typed from @${options.name}/models:</p>
|
|
150
|
-
<pre style={{ background: '#f0f0f0', padding: '1rem', borderRadius: '8px' }}>
|
|
151
|
-
{JSON.stringify(exampleUser, null, 2)}
|
|
152
|
-
</pre>
|
|
153
|
-
</section>
|
|
154
|
-
|
|
155
198
|
<section style={{ marginTop: '2rem' }}>
|
|
156
199
|
<h2>Next Steps</h2>
|
|
157
200
|
<ul>
|
|
201
|
+
<li>Run <code>gkm openapi</code> to generate typed API client</li>
|
|
158
202
|
<li>Edit <code>apps/web/src/app/page.tsx</code> to customize this page</li>
|
|
159
203
|
<li>Add API routes in <code>apps/api/src/endpoints/</code></li>
|
|
160
204
|
<li>Define shared schemas in <code>packages/models/src/</code></li>
|
|
@@ -166,11 +210,8 @@ export default async function Home() {
|
|
|
166
210
|
`;
|
|
167
211
|
|
|
168
212
|
// Environment file for web app
|
|
169
|
-
const envLocal = `# API URL
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
# Other environment variables
|
|
173
|
-
# NEXT_PUBLIC_API_URL=http://localhost:3000
|
|
213
|
+
const envLocal = `# API URL for client-side requests
|
|
214
|
+
NEXT_PUBLIC_API_URL=http://localhost:3000
|
|
174
215
|
`;
|
|
175
216
|
|
|
176
217
|
// .gitignore for Next.js
|
|
@@ -197,10 +238,18 @@ node_modules/
|
|
|
197
238
|
path: 'apps/web/src/app/layout.tsx',
|
|
198
239
|
content: layoutTsx,
|
|
199
240
|
},
|
|
241
|
+
{
|
|
242
|
+
path: 'apps/web/src/app/providers.tsx',
|
|
243
|
+
content: providersTsx,
|
|
244
|
+
},
|
|
200
245
|
{
|
|
201
246
|
path: 'apps/web/src/app/page.tsx',
|
|
202
247
|
content: pageTsx,
|
|
203
248
|
},
|
|
249
|
+
{
|
|
250
|
+
path: 'apps/web/src/api/index.ts',
|
|
251
|
+
content: apiIndexTs,
|
|
252
|
+
},
|
|
204
253
|
{
|
|
205
254
|
path: 'apps/web/.env.local',
|
|
206
255
|
content: envLocal,
|