fix: change format of output .d.ts files
This commit is contained in:
@@ -57,27 +57,18 @@ function schemaToTypeString(schema: Schema): string {
|
||||
*/
|
||||
function generateTypeDefinition(
|
||||
resourceName: string,
|
||||
propertyConfigs: PropertyConfig[],
|
||||
relativePath: string
|
||||
propertyConfigs: PropertyConfig[]
|
||||
): string {
|
||||
const interfaceName = path.basename(resourceName, path.extname(resourceName))
|
||||
.replace(/[^a-zA-Z0-9_$]/g, '_')
|
||||
.replace(/^(\d)/, '_$1');
|
||||
|
||||
const properties = propertyConfigs
|
||||
.map((config) => ` ${config.name}: ${schemaToTypeString(config.schema)};`)
|
||||
.map((config) => ` ${config.name}: ${schemaToTypeString(config.schema)};`)
|
||||
.join('\n');
|
||||
|
||||
return `declare module "${relativePath}" {
|
||||
export interface ${interfaceName} {
|
||||
return `type Table = {
|
||||
${properties}
|
||||
}
|
||||
}[];
|
||||
|
||||
export type RowType = ${interfaceName};
|
||||
|
||||
const data: ${interfaceName}[];
|
||||
export default data;
|
||||
}
|
||||
declare const data: Table;
|
||||
export default data;
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -167,12 +158,12 @@ export default function csvLoader(
|
||||
}
|
||||
relativePath = relativePath.replace(/\\/g, '/');
|
||||
|
||||
// Replace .csv with .d.ts for the output filename
|
||||
const dtsFileName = relativePath.replace(/\.csv$/, '.d.ts');
|
||||
// Replace .csv with .csv.d.ts for the output filename
|
||||
const dtsFileName = `${relativePath}.d.ts`;
|
||||
const outputPath = typesOutputDir
|
||||
? path.join(typesOutputDir, dtsFileName)
|
||||
: dtsFileName;
|
||||
const dtsContent = generateTypeDefinition(this.resourcePath, propertyConfigs, `./${relativePath}`);
|
||||
const dtsContent = generateTypeDefinition(this.resourcePath, propertyConfigs);
|
||||
|
||||
if (writeToDisk) {
|
||||
// Write directly to disk (useful for dev server)
|
||||
|
||||
Reference in New Issue
Block a user