All files / utils/services/file file.service.ts

60% Statements 6/10
0% Branches 0/2
0% Functions 0/1
50% Lines 4/8

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 228x 8x 8x     8x                                
import { Service } from '../../container';
import { writeFileSync } from 'fs';
import { ensureDirSync } from 'fs-extra';
 
@Service()
export class FileService {
    writeEffectTypes(effects: Array<any>) {
        const types = `
function strEnum<T extends string>(o: Array<T>): {[K in T]: K} {
    return o.reduce((res, key) => {
        res[key] = key;
        return res;
    }, Object.create(null));
}
export const EffectTypes = strEnum(${JSON.stringify(effects).replace(/"/g, `'`).replace(/,/g, ',\n')});
export type EffectTypes = keyof typeof EffectTypes;
`;
          const folder = process.env.INTROSPECTION_FOLDER || `./src/app/core/api-introspection/`;
            ensureDirSync(folder);
            writeFileSync(folder + 'EffectTypes.ts', types, 'utf8');
    }
}