import { ensureDir } from "fs-extra" ; import { readJson , writeJson } from "../util/io" ; import { joinPaths } from "../util/util" ; import { dataDirPath } from "./settings" ; if ( process . env . LONGJOHN ) { console . log ( "=== USING LONGJOHN ===" ) ; const longjohn = require ( "longjohn" ) as { async_trace_limit : number ; } ; longjohn . async_trace_limit = - 1 ; } /** Which registry to publish to */ export enum Registry { /** types-registry and @types/* on NPM */ NPM , definitelytyped types Github } /** Settings that may be determined dynamically. */ export interface Options { /**
     * e.g. '../DefinitelyTyped'
     * This is overridden to `cwd` when running the tester, as that is run from within DefinitelyTyped.
     * If undefined, downloads instead.
     */ readonly definitelyTypedPath : string | undefined ; /** Whether to show progress bars. Good when running locally, bad when running on travis / azure. */ readonly progress : boolean ; /** Disabled on azure since it has problems logging errors from other processes. */ readonly parseInParallel : boolean ; } export namespace Options { /** Options for running locally. */ export const defaults = { definitelyTypedPath : "../DefinitelyTyped" , progress : true , parseInParallel : true } ; export const azure = { definitelyTypedPath : undefined , progress : false , parseInParallel : false } ; } export interface TesterOptions extends Options { readonly definitelyTypedPath : string ; } export function readDataFile ( generatedBy , fileName ) { return readFileAndWarn ( generatedBy , dataFilePath ( fileName ) ) ; } /** If a file doesn't exist, warn and tell the step it should have been generated by. */ export async function readFileAndWarn ( generatedBy , filePath ) { try { return await readJson ( filePath ) ; } catch ( e ) { console . error ( `Run ${ generatedBy } first!` ) ; throw e ; } } export async function writeDataFile ( filename , content , formatted = true ) { await ensureDir ( dataDirPath ) ; await writeJson ( dataFilePath ( filename ) , content , formatted ) ; } export function dataFilePath ( filename ) { return joinPaths ( dataDirPath , filename ) ; }