Skip to content

Commit

Permalink
feat(type export): remove imports in aggregated file
Browse files Browse the repository at this point in the history
  • Loading branch information
MatsJohansen87 committed Feb 5, 2024
1 parent d3c5977 commit cdc1702
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/lib/src/types/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export type AstBottomLayerValue = {
key: string;
type: string;
system?: string;
value: string | boolean | Array<string> | {min: number, max: number} | {min: Date | undefined, max: Date | undefined}
value: string | boolean | Array<string> | { min: number, max: number } | { min: Date | undefined, max: Date | undefined }
}
2 changes: 1 addition & 1 deletion packages/lib/src/types/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export type BackendConfig = {
catalogueKeyToResponseKeyMap: string[][];
};

export type ResponseStore = Map<string, Site>
export type ResponseStore = Map<string, Site>
3 changes: 1 addition & 2 deletions packages/lib/src/types/biobanks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export type HeaderData = {
title: string;
dataKey?: string;
Expand All @@ -9,4 +8,4 @@ export type HeaderData = {
}[];
ascending?: boolean;
hintText?: string[];
};
};
2 changes: 1 addition & 1 deletion packages/lib/src/types/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export type ToggleAttribute = {
collapsable?: boolean,
open?: boolean,
animated?: boolean ,
}
}
2 changes: 1 addition & 1 deletion packages/lib/src/types/queryData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ export type AutoCompleteItem = {
};
};

export type queryStoreItem = QueryItem[] | QueryItem | QueryValue[] | QueryValue | AggregatedValue[] | AggregatedValue
export type queryStoreItem = QueryItem[] | QueryItem | QueryValue[] | QueryValue | AggregatedValue[] | AggregatedValue
2 changes: 1 addition & 1 deletion packages/lib/src/types/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ export type SiteData = {
resourceType: string,
status: string,
type: string,
}
}
38 changes: 38 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function minifyEs() {
*/
function afterBuild() :void {
concatenateDeclarationFiles('./dist/src/types/');

/**
* Building somehow adds another @samply folder to the dist folder so this workaround is needed
* to move the files to the root of the dist folder and delete the unnecessary folder
Expand All @@ -89,6 +90,8 @@ function concatenateDeclarationFiles(folderPath: string): void {

// Write the concatenated declaration files to a single file and remove the folder
writeFileSync('./dist/types.d.ts', declarationFiles);
removeImportLinesFromFile('./dist/types.d.ts');

fs.rmSync('./dist/src', { recursive: true, force: true });
}

Expand Down Expand Up @@ -126,3 +129,38 @@ function moveFile(oldFile: string, target: string): void {
}
}, 1000);
}


/**
* removes all import statements from a file
* @param filePath the path of the file
*/
function removeImportLinesFromFile(filePath: string): void {
// Read the file content
fs.readFile(filePath, 'utf8', (err: NodeJS.ErrnoException | null, data: string) => {
if (err) {
console.error('Error reading file:', err);
return;
}

// Split the content into lines
const lines: string[] = data.split('\n');

// Filter out lines starting with 'import'
const filteredLines: string[] = lines.filter(line => !line.trim().startsWith('import'));

// Join the remaining lines
const modifiedContent: string = filteredLines.join('\n');

// Write the modified content back to the file
fs.writeFile(filePath, modifiedContent, 'utf8', (err: NodeJS.ErrnoException | null) => {
if (err) {
console.error('Error writing file:', err);
return;
}
console.log('File updated successfully.');
});
});
}

// Call the function with the file path

0 comments on commit cdc1702

Please sign in to comment.