fix: typing and remove singularization
This commit is contained in:
parent
daac7badbb
commit
d78ef75272
|
|
@ -272,19 +272,19 @@ function generateTypeDefinition(
|
|||
const resourceNames = new Map<string, string>();
|
||||
|
||||
references.forEach(tableName => {
|
||||
// Convert table name to type name (parts -> Part, recipes -> Recipe)
|
||||
// Remove trailing 's' to get singular form, then capitalize
|
||||
let singularName = tableName;
|
||||
if (singularName.endsWith('s') && singularName.length > 1) {
|
||||
singularName = singularName.slice(0, -1);
|
||||
}
|
||||
const typeBase = singularName.charAt(0).toUpperCase() + singularName.slice(1);
|
||||
// Convert table name to type name by capitalizing
|
||||
const typeBase = tableName.charAt(0).toUpperCase() + tableName.slice(1);
|
||||
resourceNames.set(tableName, typeBase);
|
||||
|
||||
// Import from relative path
|
||||
const importPath = currentFilePath
|
||||
? `./${tableName}.csv`
|
||||
: `../${tableName}.csv`;
|
||||
// Generate import path based on current file path
|
||||
let importPath: string;
|
||||
if (currentFilePath) {
|
||||
// Both files are in the same directory, use relative path
|
||||
importPath = `./${tableName}.csv`;
|
||||
} else {
|
||||
// Fallback for unknown path
|
||||
importPath = `../${tableName}.csv`;
|
||||
}
|
||||
imports.push(`import type { ${typeBase} } from '${importPath}';`);
|
||||
});
|
||||
|
||||
|
|
@ -294,9 +294,21 @@ function generateTypeDefinition(
|
|||
.map((config) => ` readonly ${config.name}: ${schemaToTypeString(config.schema, resourceNames)};`)
|
||||
.join('\n');
|
||||
|
||||
// Generate both the table type and export a singular type alias for references
|
||||
// e.g., for "parts" table, export both "partsTable" and "Parts" (as alias)
|
||||
let exportAlias = '';
|
||||
if (resourceName) {
|
||||
// Capitalize resource name for the singular type
|
||||
const singularType = resourceName.charAt(0).toUpperCase() + resourceName.slice(1);
|
||||
// Remove trailing 's' if it looks like a plural (simple heuristic)
|
||||
// Actually, let's just use the table name capitalized - users can adjust if needed
|
||||
exportAlias = `\nexport type ${singularType} = ${typeName}[number];`;
|
||||
}
|
||||
|
||||
return `${importSection}type ${typeName} = readonly {
|
||||
${properties}
|
||||
}[];
|
||||
${exportAlias}
|
||||
|
||||
declare const data: ${typeName};
|
||||
export default data;
|
||||
|
|
|
|||
Loading…
Reference in New Issue