@geekmidas/cli 0.29.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 +58 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +58 -9
- 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 +4 -4
- 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/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",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"openapi-typescript": "^7.4.2",
|
|
50
50
|
"prompts": "~2.4.2",
|
|
51
51
|
"@geekmidas/errors": "~0.1.0",
|
|
52
|
-
"@geekmidas/
|
|
52
|
+
"@geekmidas/logger": "~0.4.0",
|
|
53
53
|
"@geekmidas/constructs": "~0.6.0",
|
|
54
|
-
"@geekmidas/
|
|
55
|
-
"@geekmidas/
|
|
54
|
+
"@geekmidas/envkit": "~0.5.0",
|
|
55
|
+
"@geekmidas/schema": "~0.1.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/lodash.kebabcase": "^4.1.9",
|
|
@@ -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
|
});
|
|
@@ -478,6 +478,120 @@ describe('WorkspaceConfigSchema', () => {
|
|
|
478
478
|
});
|
|
479
479
|
});
|
|
480
480
|
|
|
481
|
+
describe('auth app configuration', () => {
|
|
482
|
+
it('should accept auth app with provider', () => {
|
|
483
|
+
const config = {
|
|
484
|
+
apps: {
|
|
485
|
+
auth: {
|
|
486
|
+
type: 'auth' as const,
|
|
487
|
+
path: 'apps/auth',
|
|
488
|
+
port: 3002,
|
|
489
|
+
provider: 'better-auth' as const,
|
|
490
|
+
},
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
const result = validateWorkspaceConfig(config);
|
|
495
|
+
|
|
496
|
+
expect(result.apps.auth.type).toBe('auth');
|
|
497
|
+
expect(result.apps.auth.provider).toBe('better-auth');
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it('should reject auth app without provider', () => {
|
|
501
|
+
const config = {
|
|
502
|
+
apps: {
|
|
503
|
+
auth: {
|
|
504
|
+
type: 'auth' as const,
|
|
505
|
+
path: 'apps/auth',
|
|
506
|
+
port: 3002,
|
|
507
|
+
// Missing provider
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
const result = safeValidateWorkspaceConfig(config);
|
|
513
|
+
|
|
514
|
+
expect(result.success).toBe(false);
|
|
515
|
+
if (result.error) {
|
|
516
|
+
const formatted = formatValidationErrors(result.error);
|
|
517
|
+
expect(formatted).toContain('Auth apps must have provider defined');
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it('should allow auth app with backend properties', () => {
|
|
522
|
+
const config = {
|
|
523
|
+
apps: {
|
|
524
|
+
auth: {
|
|
525
|
+
type: 'auth' as const,
|
|
526
|
+
path: 'apps/auth',
|
|
527
|
+
port: 3002,
|
|
528
|
+
provider: 'better-auth' as const,
|
|
529
|
+
envParser: './src/config/env',
|
|
530
|
+
logger: './src/logger',
|
|
531
|
+
telescope: true,
|
|
532
|
+
},
|
|
533
|
+
},
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
const result = validateWorkspaceConfig(config);
|
|
537
|
+
|
|
538
|
+
expect(result.apps.auth.type).toBe('auth');
|
|
539
|
+
expect(result.apps.auth.envParser).toBe('./src/config/env');
|
|
540
|
+
expect(result.apps.auth.telescope).toBe(true);
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
it('should validate fullstack workspace with auth app', () => {
|
|
544
|
+
const config = {
|
|
545
|
+
name: 'fullstack-app',
|
|
546
|
+
apps: {
|
|
547
|
+
api: {
|
|
548
|
+
type: 'backend' as const,
|
|
549
|
+
path: 'apps/api',
|
|
550
|
+
port: 3000,
|
|
551
|
+
routes: './src/endpoints/**/*.ts',
|
|
552
|
+
dependencies: ['auth'],
|
|
553
|
+
},
|
|
554
|
+
auth: {
|
|
555
|
+
type: 'auth' as const,
|
|
556
|
+
path: 'apps/auth',
|
|
557
|
+
port: 3002,
|
|
558
|
+
provider: 'better-auth' as const,
|
|
559
|
+
},
|
|
560
|
+
web: {
|
|
561
|
+
type: 'frontend' as const,
|
|
562
|
+
path: 'apps/web',
|
|
563
|
+
port: 3001,
|
|
564
|
+
framework: 'nextjs' as const,
|
|
565
|
+
dependencies: ['api', 'auth'],
|
|
566
|
+
},
|
|
567
|
+
},
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
const result = validateWorkspaceConfig(config);
|
|
571
|
+
|
|
572
|
+
expect(result.apps.api.dependencies).toEqual(['auth']);
|
|
573
|
+
expect(result.apps.auth.type).toBe('auth');
|
|
574
|
+
expect(result.apps.web.dependencies).toEqual(['api', 'auth']);
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
it('should reject invalid auth provider', () => {
|
|
578
|
+
const config = {
|
|
579
|
+
apps: {
|
|
580
|
+
auth: {
|
|
581
|
+
type: 'auth' as const,
|
|
582
|
+
path: 'apps/auth',
|
|
583
|
+
port: 3002,
|
|
584
|
+
provider: 'invalid-provider',
|
|
585
|
+
},
|
|
586
|
+
},
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
const result = safeValidateWorkspaceConfig(config);
|
|
590
|
+
|
|
591
|
+
expect(result.success).toBe(false);
|
|
592
|
+
});
|
|
593
|
+
});
|
|
594
|
+
|
|
481
595
|
describe('deploy target helpers', () => {
|
|
482
596
|
it('isDeployTargetSupported should return true for dokploy', () => {
|
|
483
597
|
expect(isDeployTargetSupported('dokploy')).toBe(true);
|
package/src/workspace/schema.ts
CHANGED
|
@@ -51,6 +51,12 @@ const ClientConfigSchema = z.object({
|
|
|
51
51
|
output: z.string().optional(),
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Auth provider schema.
|
|
56
|
+
* Currently only 'better-auth' is supported.
|
|
57
|
+
*/
|
|
58
|
+
const AuthProviderSchema = z.enum(['better-auth']);
|
|
59
|
+
|
|
54
60
|
/**
|
|
55
61
|
* Deploy target schema.
|
|
56
62
|
* Currently only 'dokploy' is supported.
|
|
@@ -177,7 +183,7 @@ const SecretsConfigSchema = z.object({
|
|
|
177
183
|
const AppConfigSchema = z
|
|
178
184
|
.object({
|
|
179
185
|
// Core properties
|
|
180
|
-
type: z.enum(['backend', 'frontend']).optional().default('backend'),
|
|
186
|
+
type: z.enum(['backend', 'frontend', 'auth']).optional().default('backend'),
|
|
181
187
|
path: z.string().min(1, 'App path is required'),
|
|
182
188
|
port: z.number().int().positive('Port must be a positive integer'),
|
|
183
189
|
dependencies: z.array(z.string()).optional(),
|
|
@@ -202,6 +208,9 @@ const AppConfigSchema = z
|
|
|
202
208
|
// Frontend-specific
|
|
203
209
|
framework: z.enum(['nextjs']).optional(),
|
|
204
210
|
client: ClientConfigSchema.optional(),
|
|
211
|
+
|
|
212
|
+
// Auth-specific
|
|
213
|
+
provider: AuthProviderSchema.optional(),
|
|
205
214
|
})
|
|
206
215
|
// Note: routes is optional for backend apps - some backends like auth servers don't use routes
|
|
207
216
|
.refine(
|
|
@@ -216,6 +225,19 @@ const AppConfigSchema = z
|
|
|
216
225
|
message: 'Frontend apps must have framework defined',
|
|
217
226
|
path: ['framework'],
|
|
218
227
|
},
|
|
228
|
+
)
|
|
229
|
+
.refine(
|
|
230
|
+
(data) => {
|
|
231
|
+
// Auth apps must have provider
|
|
232
|
+
if (data.type === 'auth' && !data.provider) {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
return true;
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
message: 'Auth apps must have provider defined',
|
|
239
|
+
path: ['provider'],
|
|
240
|
+
},
|
|
219
241
|
);
|
|
220
242
|
|
|
221
243
|
/**
|