All files / src/class effect.ts

76.92% Statements 10/13
57.14% Branches 4/7
100% Functions 1/1
100% Lines 10/10

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 4915x   15x 15x                                                               15x 15x   15x   15x     11x 11x 11x      
import fse, { WriteFileOptions, CopyOptions, EnsureOptions, ReadOptions, Stats, WriteOptions } from 'fs-extra'
import { Prompter } from './question'
import { inquirerPrompter } from '@/prompters'
import { logger } from '@/utils'
 
 
export interface FileSystem {
  writeFile: (file: string, data: any, options?: WriteFileOptions | string) => Promise<void>
  readFile: (file: string, encoding: string) => Promise<string>
  pathExists: (path: string) => Promise<boolean>
  remove: (dir: string) => Promise<void>
  emptyDir: (path: string) => Promise<void>
  copy: (src: string, dest: string, options?: CopyOptions) => Promise<void>
  ensureDir: (path: string, options?: EnsureOptions | number) => Promise<void>
  readJSON: (file: string, options?: ReadOptions) => Promise<any>
  writeJSON: (file: string, object: any, options?: WriteOptions) => Promise<void>
  stat: (path: string | Buffer) => Promise<Stats>
  readdir: (path: string | Buffer) => Promise<string[]>
}
 
export interface Logger {
  trace(message): void
  debug(message): void
  info(message): void
  warn(message): void
  error(message): void
  fatal(message): void
}
 
export interface EffectOptions {
  fs?: FileSystem
  prompter?: Prompter
  logger?: Logger
}
 
export class Effect {
  public static fs: FileSystem = fse
 
  public static prompter: Prompter = inquirerPrompter
 
  public static logger: Logger = logger
 
  public static replace(options: EffectOptions = {}): void {
    Iif (options.fs) this.fs = options.fs
    Iif (options.prompter) this.prompter = options.prompter
    Iif (options.logger) this.logger = options.logger
  }
}