"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1280.1/src/lib/get-file-contents.ts" (20 Feb 2024, 458 Bytes) of package /linux/misc/snyk-cli-1.1280.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 import * as fs from 'fs';
    2 import * as path from 'path';
    3 
    4 export function getFileContents(
    5   root: string,
    6   fileName: string,
    7 ): {
    8   content: string;
    9   fileName: string;
   10 } {
   11   const fullPath = path.resolve(root, fileName);
   12   if (!fs.existsSync(fullPath)) {
   13     throw new Error(
   14       'Manifest ' + fileName + ' not found at location: ' + fileName,
   15     );
   16   }
   17   const content = fs.readFileSync(fullPath, 'utf-8');
   18   return {
   19     content,
   20     fileName,
   21   };
   22 }