From cdc17023ff90e66e39f78a908c99d74855e9f4a0 Mon Sep 17 00:00:00 2001 From: Mats Johansen Date: Mon, 5 Feb 2024 14:58:04 +0100 Subject: [PATCH] feat(type export): remove imports in aggregated file --- packages/lib/src/types/ast.ts | 2 +- packages/lib/src/types/backend.ts | 2 +- packages/lib/src/types/biobanks.ts | 3 +-- packages/lib/src/types/helpers.ts | 2 +- packages/lib/src/types/queryData.ts | 2 +- packages/lib/src/types/response.ts | 2 +- vite.config.ts | 38 +++++++++++++++++++++++++++++ 7 files changed, 44 insertions(+), 7 deletions(-) diff --git a/packages/lib/src/types/ast.ts b/packages/lib/src/types/ast.ts index 2a7d7cc0..356bfb94 100644 --- a/packages/lib/src/types/ast.ts +++ b/packages/lib/src/types/ast.ts @@ -9,5 +9,5 @@ export type AstBottomLayerValue = { key: string; type: string; system?: string; - value: string | boolean | Array | {min: number, max: number} | {min: Date | undefined, max: Date | undefined} + value: string | boolean | Array | { min: number, max: number } | { min: Date | undefined, max: Date | undefined } } diff --git a/packages/lib/src/types/backend.ts b/packages/lib/src/types/backend.ts index 10d947f4..e4cd9cc7 100644 --- a/packages/lib/src/types/backend.ts +++ b/packages/lib/src/types/backend.ts @@ -13,4 +13,4 @@ export type BackendConfig = { catalogueKeyToResponseKeyMap: string[][]; }; -export type ResponseStore = Map \ No newline at end of file +export type ResponseStore = Map diff --git a/packages/lib/src/types/biobanks.ts b/packages/lib/src/types/biobanks.ts index 3ff2a714..138d55e1 100644 --- a/packages/lib/src/types/biobanks.ts +++ b/packages/lib/src/types/biobanks.ts @@ -1,4 +1,3 @@ - export type HeaderData = { title: string; dataKey?: string; @@ -9,4 +8,4 @@ export type HeaderData = { }[]; ascending?: boolean; hintText?: string[]; -}; \ No newline at end of file +}; diff --git a/packages/lib/src/types/helpers.ts b/packages/lib/src/types/helpers.ts index 171d3751..b2f24c24 100644 --- a/packages/lib/src/types/helpers.ts +++ b/packages/lib/src/types/helpers.ts @@ -2,4 +2,4 @@ export type ToggleAttribute = { collapsable?: boolean, open?: boolean, animated?: boolean , -} \ No newline at end of file +} diff --git a/packages/lib/src/types/queryData.ts b/packages/lib/src/types/queryData.ts index 02875bab..8cb0c254 100644 --- a/packages/lib/src/types/queryData.ts +++ b/packages/lib/src/types/queryData.ts @@ -32,4 +32,4 @@ export type AutoCompleteItem = { }; }; -export type queryStoreItem = QueryItem[] | QueryItem | QueryValue[] | QueryValue | AggregatedValue[] | AggregatedValue \ No newline at end of file +export type queryStoreItem = QueryItem[] | QueryItem | QueryValue[] | QueryValue | AggregatedValue[] | AggregatedValue diff --git a/packages/lib/src/types/response.ts b/packages/lib/src/types/response.ts index 1356bd5c..b52682a8 100644 --- a/packages/lib/src/types/response.ts +++ b/packages/lib/src/types/response.ts @@ -52,4 +52,4 @@ export type SiteData = { resourceType: string, status: string, type: string, -} \ No newline at end of file +} diff --git a/vite.config.ts b/vite.config.ts index 5fd2aaba..0eae0c93 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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 @@ -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 }); } @@ -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