import { promises as fs } from "fs" ; import * as tr from "text-runner-core" ; import * as YAML from "yamljs" ; import * as config from "./configuration" ; /** provides the config file content as a Configuration instance */ export async function load ( cmdLineArgs ) { return parse ( await read ( cmdLineArgs ) ) ; } /** creates a new Text-Runner configuration file */ export async function create ( cmdLineArgs ) { await fs . writeFile ( cmdLineArgs . configFileName || "text-run.yml" , `# white-list for files to test
# This is a glob expression, see https://github.com/isaacs/node-glob#glob-primer
# The folder "node_modules" is already excluded.
# To exclude the "vendor" folder: '{,!(vendor)/**/}*.md'
files: "**/*.md"

# black-list of files not to test
# applied after the white-list above.
exclude: []

# the formatter to use (detailed, dot, progress, summary)
format: detailed

# regex patterns for link targets to ignore
ignoreLinkTargets: []

# Define which folders of your Markdown source get compiled to HTML
# and published under a different URL path.
#
# In this example, the public URL "/blog/foo"
# would be hosted as "post/foo.md":
# publications:
#   - localPath: /posts/
#     publicPath: /blog
#     publicExtension: ''

# Name of the default filename in folders.
# If you set this, and a link points to a folder,
# Text-Runner assumes the link points to the default file in that folder.
# defaultFile: index.md

# prefix that makes anchor tags active regions
regionMarker: type

# whether to display/emit skipped activities
showSkipped: false

# whether to run the tests in an external temp directory,
# uses ./tmp if false,
# you can also provide a custom directory path here
systemTmp: false

# whether to verify online files/links (warning: this makes tests flaky)
online: false

# whether to delete all files in the workspace folder before running the tests
emptyWorkspace: true` ) ; } /** provides the textual config file content */ async function read ( cmdLineArgs ) { if ( cmdLineArgs . configFileName ) { try { const result = await fs . readFile ( cmdLineArgs . configFileName , "utf8" ) ; return result ; } catch ( e ) { throw new tr . UserError ( `cannot read configuration file "${ cmdLineArgs . configFileName }"` , e . message ) ; } } try { const result = await fs . readFile ( "text-run.yml" , "utf8" ) ; return result ; } catch ( e ) { return "" ; } } /** parses the textual config file content into a Configuration instance */ function parse ( fileContent ) { if ( fileContent === "" ) { return new config . Data ( { } ) ; } const fileData = YAML . parse ( fileContent ) ; return new config . Data ( { regionMarker : fileData . regionMarker , defaultFile : fileData . defaultFile , emptyWorkspace : fileData . emptyWorkspace , exclude : fileData . exclude , files : fileData . files , formatterName : fileData . format , ignoreLinkTargets : fileData . ignoreLinkTargets , online : fileData . online , publications : fileData . publications , showSkipped : fileData . showSkipped , systemTmp : fileData . systemTmp , workspace : fileData . workspace , } ) ; }