All files / core/use-cases scan-files.ts

92% Statements 23/25
66.67% Branches 4/6
88.89% Functions 8/9
91.67% Lines 22/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 511x   1x         1x     1x       1x 1x 1x   1x     1x 1x 1x   1x 55x 55x         1x       1x 107x 65x       1x 1x       1x   1x  
import * as path from 'path';
 
const DEFAULT_EXCLUDED_DIRECTORIES = ['.git', 'node_modules'];
 
/**
 * Handle scan source code
 */
export class ScanFile {
    private static instance: ScanFile;
 
    private scannedFiles: string[] = [];
 
    private constructor() {}
 
    public static getInstance() {
        Eif (!ScanFile.instance) {
            ScanFile.instance = new ScanFile();
        }
        return ScanFile.instance;
    }
 
    public async scan(folder: string): Promise<string[]> {
        return new Promise<string[]>((resolve, reject) => {
            const finder = require('findit2')(path.resolve(folder));
 
            finder.on('directory', function(dir, stat, stop) {
                let base = path.basename(dir);
                Iif (DEFAULT_EXCLUDED_DIRECTORIES.includes(base)) {
                    stop();
                }
            });
 
            finder.on('error', error => {
                reject(error);
            });
 
            finder.on('file', (file, stat) => {
                if (path.extname(file) === '.ts') {
                    this.scannedFiles.push(file);
                }
            });
 
            finder.on('end', () => {
                resolve(this.scannedFiles);
            });
        });
    }
}
 
export default ScanFile.getInstance();