Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
"website/**",
"!**/wwwroot",
"!modules/*/src/*/types.ts",
"!packages/SimpleModule.Client/src/routes.ts",
"!template/SimpleModule.Host/ClientApp/routes.ts",
"!test-projects"
]
}
Expand Down
14 changes: 14 additions & 0 deletions cli/SimpleModule.Cli/Commands/New/NewProjectCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ string frameworkVersion
ProjectTemplates.NugetConfig(solution?.RootPath)
);

// ── Type-generation scripts ───────────────────────────
var scriptsDir = Path.Combine(rootDir, "scripts");
Directory.CreateDirectory(scriptsDir);
File.WriteAllText(
Path.Combine(scriptsDir, "extract-ts-types.mjs"),
ProjectTemplates.ExtractTsTypesScript()
);
File.WriteAllText(
Path.Combine(scriptsDir, "extract-routes.mjs"),
ProjectTemplates.ExtractRoutesScript()
);

// ── Host project ──────────────────────────────────────
File.WriteAllText(
Path.Combine(hostDir, $"{projectName}.Host.csproj"),
Expand Down Expand Up @@ -290,6 +302,8 @@ string rootDir
Plan(Path.Combine(rootDir, "tsconfig.json"));
Plan(Path.Combine(rootDir, ".editorconfig"));
Plan(Path.Combine(rootDir, "nuget.config"));
Plan(Path.Combine(rootDir, "scripts", "extract-ts-types.mjs"));
Plan(Path.Combine(rootDir, "scripts", "extract-routes.mjs"));

// Host project files
Plan(Path.Combine(hostDir, $"{projectName}.Host.csproj"));
Expand Down
8 changes: 8 additions & 0 deletions cli/SimpleModule.Cli/SimpleModule.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,13 @@
Include="..\..\template\SimpleModule.Host\Properties\launchSettings.json"
LogicalName="Templates.Host.Properties.launchSettings.json"
/>
<EmbeddedResource
Include="..\..\scripts\extract-ts-types.mjs"
LogicalName="Templates.scripts.extract-ts-types.mjs"
/>
<EmbeddedResource
Include="..\..\scripts\extract-routes.mjs"
LogicalName="Templates.scripts.extract-routes.mjs"
/>
</ItemGroup>
</Project>
40 changes: 33 additions & 7 deletions cli/SimpleModule.Cli/Templates/ProjectTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,23 @@ public string BiomeJson()

var content = File.ReadAllText(path);

// Replace file includes: monorepo paths → project paths
content = content.Replace(
"\"modules/**\", \"packages/**\", \"template/**\", \"tests/**\"",
"\"src/**\", \"tests/**\"",
StringComparison.Ordinal
// The monorepo's files.includes references top-level directories (modules/**,
// packages/**, template/**) that don't exist in scaffolded projects. Swap the
// whole array; leave the rest of biome.json verbatim.
var scaffoldedIncludes =
"\"includes\": [\n"
+ " \"src/**\",\n"
+ " \"tests/**\",\n"
+ " \"!**/wwwroot\",\n"
+ " \"!src/modules/*/src/*/types.ts\",\n"
+ " \"!src/*.Host/ClientApp/routes.ts\"\n"
+ " ]";

content = Regex.Replace(
content,
"\"includes\"\\s*:\\s*\\[[^\\]]*\\]",
scaffoldedIncludes,
RegexOptions.Singleline
);

return content;
Expand Down Expand Up @@ -716,7 +728,9 @@ string frameworkVersion
"check": "biome check .",
"check:fix": "biome check --write .",
"build": "cross-env VITE_MODE=prod npm run build --workspaces --if-present",
"build:dev": "cross-env VITE_MODE=dev npm run build --workspaces --if-present"
"build:dev": "cross-env VITE_MODE=dev npm run build --workspaces --if-present",
"generate:types": "dotnet build src/{{projectName}}.Host && node scripts/extract-ts-types.mjs src/{{projectName}}.Host/obj/Debug/net10.0/generated/SimpleModule.Generator/SimpleModule.Generator.ModuleDiscovererGenerator src/modules",
"generate:routes": "dotnet build src/{{projectName}}.Host && node scripts/extract-routes.mjs src/{{projectName}}.Host/obj/Debug/net10.0/generated/SimpleModule.Generator/SimpleModule.Generator.ModuleDiscovererGenerator src/{{projectName}}.Host/ClientApp/routes.ts"
},
"devDependencies": {
"@biomejs/biome": "^2.4.10",
Expand All @@ -743,6 +757,12 @@ string frameworkVersion
""";
}

public static string ExtractTsTypesScript() =>
EmbeddedResourceReader.ReadTemplate("Templates.scripts.extract-ts-types.mjs");

public static string ExtractRoutesScript() =>
EmbeddedResourceReader.ReadTemplate("Templates.scripts.extract-routes.mjs");

private static string FallbackBiomeJson() =>
"""
{
Expand Down Expand Up @@ -777,7 +797,13 @@ private static string FallbackBiomeJson() =>
}
},
"files": {
"includes": ["src/**", "tests/**", "!**/wwwroot"]
"includes": [
"src/**",
"tests/**",
"!**/wwwroot",
"!src/modules/*/src/*/types.ts",
"!src/*.Host/ClientApp/routes.ts"
]
}
}
""";
Expand Down
19 changes: 7 additions & 12 deletions packages/SimpleModule.Client/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,16 @@ export const routes = {
},
tenants: {
api: {
deleteTenantFeature: (id: string | number, flagName: string | number) =>
`/api/tenants/${id}/features/${flagName}`,
deleteTenantFeature: (id: string | number, flagName: string | number) => `/api/tenants/${id}/features/${flagName}`,
getTenantFeatures: (id: string | number) => `/api/tenants/${id}/features`,
setTenantFeature: (id: string | number, flagName: string | number) =>
`/api/tenants/${id}/features/${flagName}`,
setTenantFeature: (id: string | number, flagName: string | number) => `/api/tenants/${id}/features/${flagName}`,
addHost: (id: string | number) => `/api/tenants/${id}/hosts`,
changeStatus: (id: string | number) => `/api/tenants/${id}/status`,
create: () => '/api/tenants' as const,
delete: (id: string | number) => `/api/tenants/${id}`,
getAll: () => '/api/tenants' as const,
getById: (id: string | number) => `/api/tenants/${id}`,
removeHost: (id: string | number, hostId: string | number) =>
`/api/tenants/${id}/hosts/${hostId}`,
removeHost: (id: string | number, hostId: string | number) => `/api/tenants/${id}/hosts/${hostId}`,
update: (id: string | number) => `/api/tenants/${id}`,
},
views: {
Expand Down Expand Up @@ -170,8 +167,7 @@ export const routes = {
manageIndex: () => '/Identity/Account/Manage' as const,
personalData: () => '/Identity/Account/Manage/PersonalData' as const,
removePhoneNumber: () => '/Identity/Account/Manage/RemovePhoneNumber' as const,
sendPhoneVerificationCode: () =>
'/Identity/Account/Manage/SendPhoneVerificationCode' as const,
sendPhoneVerificationCode: () => '/Identity/Account/Manage/SendPhoneVerificationCode' as const,
setPassword: () => '/Identity/Account/Manage/SetPassword' as const,
},
},
Expand Down Expand Up @@ -216,8 +212,7 @@ export const routes = {
userinfo: () => '/connect/userinfo' as const,
activeSessions: () => '/Identity/Account/Manage/ActiveSessions' as const,
revokeOtherSessions: () => '/Identity/Account/Manage/ActiveSessions/revoke-others' as const,
revokeSession: (tokenId: string | number) =>
`/Identity/Account/Manage/ActiveSessions/${tokenId}/revoke`,
revokeSession: (tokenId: string | number) => `/Identity/Account/Manage/ActiveSessions/${tokenId}/revoke`,
},
views: {
clientsCreate: () => '/openiddict/clients/create' as const,
Expand All @@ -228,8 +223,7 @@ export const routes = {
admin: {
api: {
adminRoles: () => '/admin/roles' as const,
adminSessions: (id: string | number, tokenId: string | number) =>
`/admin/users/${id}/sessions/${tokenId}`,
adminSessions: (id: string | number, tokenId: string | number) => `/admin/users/${id}/sessions/${tokenId}`,
adminUsers: () => '/admin/users' as const,
},
views: {
Expand All @@ -243,3 +237,4 @@ export const routes = {
},
},
} as const;

24 changes: 18 additions & 6 deletions scripts/extract-routes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
// Extracts TypeScript route definitions from TypeScriptRoutes.g.cs
// Usage: node scripts/extract-routes.mjs <generated-dir> <output-path>

import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
import {
existsSync,
readFileSync,
writeFileSync,
mkdirSync,
} from 'fs';
import { resolve, dirname, join } from 'path';

function writeIfChanged(path, contents) {
if (existsSync(path) && readFileSync(path, 'utf-8') === contents) {
return false;
}
writeFileSync(path, contents);
return true;
}

const generatedDir = process.argv[2];
const outputPath =
process.argv[3] ||
Expand Down Expand Up @@ -34,10 +47,9 @@ if (!tsMatch) {

const tsContent = tsMatch[1];
const outPath = resolve(outputPath);
const next = `// Auto-generated from endpoint Route constants \u2014 do not edit\n${tsContent}`;

mkdirSync(dirname(outPath), { recursive: true });
writeFileSync(
outPath,
`// Auto-generated from endpoint Route constants \u2014 do not edit\n${tsContent}`,
);
console.log(`Wrote routes to ${outPath}`);
if (writeIfChanged(outPath, next)) {
console.log(`Wrote routes to ${outPath}`);
}
25 changes: 19 additions & 6 deletions scripts/extract-ts-types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@
// Extracts TypeScript interfaces from per-module DtoTypeScript_*.g.cs files
// Usage: node scripts/extract-ts-types.mjs <generated-dir> <modules-dir>

import { readdirSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
import {
readdirSync,
readFileSync,
writeFileSync,
mkdirSync,
existsSync,
} from 'fs';
import { resolve, join } from 'path';

function writeIfChanged(path, contents) {
if (existsSync(path) && readFileSync(path, 'utf-8') === contents) {
return false;
}
writeFileSync(path, contents);
return true;
}

const generatedDir = process.argv[2];
const modulesDir = process.argv[3] || 'modules';

Expand Down Expand Up @@ -52,9 +66,8 @@ for (const file of files) {
mkdirSync(resolve(modulesDir, moduleName, 'src', projectDir), {
recursive: true,
});
writeFileSync(
outPath,
`// Auto-generated from [Dto] types \u2014 do not edit\n${tsContent}`,
);
console.log(`Wrote ${moduleName} types to ${outPath}`);
const next = `// Auto-generated from [Dto] types \u2014 do not edit\n${tsContent}`;
if (writeIfChanged(outPath, next)) {
console.log(`Wrote ${moduleName} types to ${outPath}`);
}
}
Loading
Loading