Skip to content

Commit a4df8fb

Browse files
committed
feat: moved asset file mover to common utility
Signed-off-by: snehaljha-sf <[email protected]> Signed-off-by: snehaljha-sf <[email protected]>
1 parent 442dd5f commit a4df8fb

File tree

2 files changed

+44
-45
lines changed

2 files changed

+44
-45
lines changed

src/utils/file/fileutil.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,44 @@ export class File {
144144
this.ext = ext;
145145
}
146146
}
147+
148+
/**
149+
* Copies `.js` and `.css` files from a source directory (based on `folderName`)
150+
* to a specified destination directory.
151+
*
152+
* @param folderName - The subdirectory under `/src/` where source asset files are located (e.g., `'javascripts'`, `'styles'`).
153+
* @param destDir - The absolute or relative path to the destination directory where the assets should be copied.
154+
*
155+
* @remarks
156+
* - If the destination directory does not exist, the method logs a warning and exits.
157+
* - Only `.js` and `.css` files are copied.
158+
* - The source files remain in place after copying.
159+
*/
160+
export function pushAssestUtilites(folderName: string, destDir: string): void {
161+
const sourceDir = path.join(process.cwd(), 'src', folderName);
162+
163+
if (!fs.existsSync(destDir)) {
164+
// Destination directory does not exist. Skipping file copy.
165+
return;
166+
}
167+
168+
try {
169+
const files = fs.readdirSync(sourceDir);
170+
171+
files.forEach((file) => {
172+
const ext = path.extname(file);
173+
if (ext === '.js' || ext === '.css') {
174+
const srcPath = path.join(sourceDir, file);
175+
const destPath = path.join(destDir, file);
176+
177+
try {
178+
fs.copyFileSync(srcPath, destPath);
179+
} catch (copyErr) {
180+
Logger.logger.error(`Error copying file ${srcPath} to ${destPath}: ${copyErr}`);
181+
}
182+
}
183+
});
184+
} catch (readDirErr) {
185+
Logger.logger.error(`Error reading directory ${sourceDir}: ${readDirErr}`);
186+
}
187+
}

src/utils/resultsbuilder/assessmentReporter.ts

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable prettier/prettier */
22
/* eslint-disable @typescript-eslint/restrict-template-expressions */
33
import fs from 'fs';
4-
import path from 'path';
54
import open from 'open';
65
import {
76
ApexAssessmentInfo,
@@ -12,6 +11,7 @@ import {
1211
} from '../interfaces';
1312
import { ReportHeaderFormat } from '../reportGenerator/reportInterfaces';
1413
import { OmnistudioOrgDetails } from '../orgUtils';
14+
import { pushAssestUtilites } from '../file/fileutil';
1515
import { OSAssessmentReporter } from './OSAssessmentReporter';
1616
import { IPAssessmentReporter } from './IPAssessmentReporter';
1717
import { DRAssessmentReporter } from './DRAssessmentReporter';
@@ -81,8 +81,8 @@ export class AssessmentReporter {
8181
];
8282

8383
await this.createMasterDocument(nameUrls, basePath);
84-
this.pushAssestUtilites('javascripts', basePath);
85-
this.pushAssestUtilites('styles', basePath);
84+
pushAssestUtilites('javascripts', basePath);
85+
pushAssestUtilites('styles', basePath);
8686
}
8787

8888
private static formattedOrgDetails(orgDetails: OmnistudioOrgDetails): ReportHeaderFormat[] {
@@ -110,48 +110,6 @@ export class AssessmentReporter {
110110
];
111111
}
112112

113-
/**
114-
* Copies `.js` and `.css` files from a source directory (based on `folderName`)
115-
* to a specified destination directory.
116-
*
117-
* @param folderName - The subdirectory under `/src/` where source asset files are located (e.g., `'javascripts'`, `'styles'`).
118-
* @param destDir - The absolute or relative path to the destination directory where the assets should be copied.
119-
*
120-
* @remarks
121-
* - If the destination directory does not exist, the method logs a warning and exits.
122-
* - Only `.js` and `.css` files are copied.
123-
* - The source files remain in place after copying.
124-
*/
125-
private static pushAssestUtilites(folderName: string, destDir: string): void {
126-
const sourceDir = path.join(process.cwd(), 'src', folderName);
127-
128-
if (!fs.existsSync(destDir)) {
129-
// Destination directory does not exist. Skipping file copy.
130-
return;
131-
}
132-
133-
fs.readdir(sourceDir, (readDirErr, files) => {
134-
if (readDirErr) {
135-
// Error reading source directory: readDirErr.message
136-
return;
137-
}
138-
139-
files.forEach((file) => {
140-
const ext = path.extname(file);
141-
if (ext === '.js' || ext === '.css') {
142-
const srcPath = path.join(sourceDir, file);
143-
const destPath = path.join(destDir, file);
144-
145-
fs.copyFile(srcPath, destPath, (copyErr) => {
146-
if (copyErr) {
147-
// Failed to copy file: copyErr.message
148-
}
149-
});
150-
}
151-
});
152-
});
153-
}
154-
155113
private static async createMasterDocument(reports: nameLocation[], basePath: string): Promise<void> {
156114
let listBody = '';
157115
for (const report of reports) {

0 commit comments

Comments
 (0)