From e0754bbe1df4fe2a5b73c88525bb7d83bf617061 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Fri, 15 May 2020 15:28:07 -0700 Subject: [PATCH] do not commit generated content to VCS This removes `markdown-magic` and replaces its functionality with the built-in data capabilities of 11ty. The TOC, `--help` output, and source files are now all done via global data scripts in `docs/_data`. When building documentation, we will no longer get changes to e.g., `docs/index.md` because of the automatically generated content. --- .eslintrc.yml | 1 + docs/README.md | 2 +- docs/_data/files.js | 52 +++++ docs/_data/toc.js | 21 ++ docs/_data/usage.js | 21 ++ docs/api-tutorials/custom-reporter.md | 65 +----- docs/index.md | 131 +---------- package-lock.json | 317 ++++---------------------- package-scripts.js | 18 +- package.json | 2 - scripts/markdown-magic.config.js | 105 --------- 11 files changed, 152 insertions(+), 583 deletions(-) create mode 100644 docs/_data/files.js create mode 100644 docs/_data/toc.js create mode 100644 docs/_data/usage.js delete mode 100644 scripts/markdown-magic.config.js diff --git a/.eslintrc.yml b/.eslintrc.yml index 34c77cabe4..f2914ee076 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -27,6 +27,7 @@ overrides: - test/integration/options/watch.spec.js - test/integration/helpers.js - lib/growl.js + - docs/_data/**/*.js parserOptions: ecmaVersion: 2018 env: diff --git a/docs/README.md b/docs/README.md index ab083fe29d..f85b53adec 100644 --- a/docs/README.md +++ b/docs/README.md @@ -34,7 +34,7 @@ _So you wanna build the site?_ cp: docs/_dist/_headers: No such file or directory ``` -- See `package-scripts.js` for details on what the builds are actually doing; especially see [markdown-magic](https://npm.im/markdown-magic) for how we're dynamically inserting information into `docs/index.md`. +- See `package-scripts.js` for details on what the builds are actually doing. ## License diff --git a/docs/_data/files.js b/docs/_data/files.js new file mode 100644 index 0000000000..12a14578c9 --- /dev/null +++ b/docs/_data/files.js @@ -0,0 +1,52 @@ +'use strict'; + +const {resolve, relative, dirname} = require('path'); +const {promises: fs} = require('fs'); + +const PROJECT_ROOT_DIR = resolve(__dirname, '..', '..'); +const FILES = [ + { + slug: 'simplereporter', + path: require.resolve('../../test/integration/fixtures/simple-reporter.js'), + header: '// my-reporter.js' + } +]; + +const HEADER = '```js\n'; +const FOOTER = '```\n'; + +const loadFile = async (path, {header} = {}) => { + const relativeDir = relative(dirname(path), PROJECT_ROOT_DIR); + let content = await fs.readFile(path, 'utf-8'); + // replace relative paths in `require()` to root with "mocha". + // might not work in the general case. not gonna parse an AST for this + // e.g. `require('../../lib/foo')` => `require('mocha/lib/foo')` + // also trim any trailing whitespace + content = content + .replace( + new RegExp(`require\\(['"]${relativeDir}(.*?)['"]\\)`, 'g'), + "require('mocha$1')" + ) + .trim(); + return `${HEADER}${header}\n\n${content}${FOOTER}`; +}; + +/** + * Loads files from disk (see `FILES` above) to be shown as data. + * Used for embedding sources directly into pages + */ +module.exports = async () => { + const files = await Promise.all( + FILES.map(async ({path, header, slug}) => { + const content = await loadFile(path, {header}); + return {slug, content}; + }) + ); + return files.reduce( + (files, {slug, content}) => ({ + ...files, + [slug]: content + }), + {} + ); +}; diff --git a/docs/_data/toc.js b/docs/_data/toc.js new file mode 100644 index 0000000000..9937c6fc10 --- /dev/null +++ b/docs/_data/toc.js @@ -0,0 +1,21 @@ +'use strict'; + +const markdownToc = require('markdown-toc'); +const {readFileSync} = require('fs'); +const {resolve} = require('path'); + +const IGNORED_HEADINGS_REGEXP = /Features|Table of Contents|Backers|Sponsors/i; +const DOCUMENT_PATH = resolve(__dirname, '..', 'index.md'); + +module.exports = () => { + const doc = readFileSync(DOCUMENT_PATH, 'utf-8'); + return markdownToc(doc, { + slugify: require('uslug'), + firsth1: false, + bullets: '-', + maxdepth: 2, + // if filter is supplied, maxdepth is apparently ignored, + // so we have to do it ourselves. + filter: (str, ele) => ele.lvl < 2 && !IGNORED_HEADINGS_REGEXP.test(str) + }).content; +}; diff --git a/docs/_data/usage.js b/docs/_data/usage.js new file mode 100644 index 0000000000..ee13a19de9 --- /dev/null +++ b/docs/_data/usage.js @@ -0,0 +1,21 @@ +'use strict'; + +const stripAnsi = require('strip-ansi'); +const {resolve} = require('path'); +const {execSync} = require('child_process'); + +const executable = require.resolve('../../bin/mocha'); +const flag = '--help'; + +/** + * Return the output of `mocha --help` for display + */ +module.exports = () => { + return stripAnsi( + String( + execSync(`"${process.execPath}" ${executable} ${flag}`, { + cwd: resolve(__dirname, '..') + }) + ).trim() + ); +}; diff --git a/docs/api-tutorials/custom-reporter.md b/docs/api-tutorials/custom-reporter.md index a0cfe48d66..1e73fba7c8 100644 --- a/docs/api-tutorials/custom-reporter.md +++ b/docs/api-tutorials/custom-reporter.md @@ -6,70 +6,7 @@ For example, if `mocha-foo-reporter` was published to the npm registry, you coul If you're looking to get started quickly, here's an example of a custom reporter: - - -```js -// my-reporter.js -'use strict'; - -const Mocha = require('mocha'); -const { - EVENT_RUN_BEGIN, - EVENT_RUN_END, - EVENT_TEST_FAIL, - EVENT_TEST_PASS, - EVENT_SUITE_BEGIN, - EVENT_SUITE_END -} = Mocha.Runner.constants; - -// this reporter outputs test results, indenting two spaces per suite -class MyReporter { - constructor(runner) { - this._indents = 0; - const stats = runner.stats; - - runner - .once(EVENT_RUN_BEGIN, () => { - console.log('start'); - }) - .on(EVENT_SUITE_BEGIN, () => { - this.increaseIndent(); - }) - .on(EVENT_SUITE_END, () => { - this.decreaseIndent(); - }) - .on(EVENT_TEST_PASS, test => { - // Test#fullTitle() returns the suite name(s) - // prepended to the test title - console.log(`${this.indent()}pass: ${test.fullTitle()}`); - }) - .on(EVENT_TEST_FAIL, (test, err) => { - console.log( - `${this.indent()}fail: ${test.fullTitle()} - error: ${err.message}` - ); - }) - .once(EVENT_RUN_END, () => { - console.log(`end: ${stats.passes}/${stats.passes + stats.failures} ok`); - }); - } - - indent() { - return Array(this._indents).join(' '); - } - - increaseIndent() { - this._indents++; - } - - decreaseIndent() { - this._indents--; - } -} - -module.exports = MyReporter; -``` - - +{{ files.simplereporter }} To use this reporter, execute `mocha --reporter /path/to/my-reporter.js`. diff --git a/docs/index.md b/docs/index.md index 415430a3d4..246534bbf5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -8,12 +8,12 @@ Mocha is a feature-rich JavaScript test framework running on [Node.js][] and in -{% include backers.md %} {% include sponsors.md %} +{% include backers.md %} ## Features @@ -49,39 +49,7 @@ Mocha is a feature-rich JavaScript test framework running on [Node.js][] and in ## Table of Contents - - -- [Installation](#installation) -- [Getting Started](#getting-started) -- [Run Cycle Overview](#run-cycle-overview) -- [Detects Multiple Calls to `done()`](#detects-multiple-calls-to-done) -- [Assertions](#assertions) -- [Asynchronous Code](#asynchronous-code) -- [Synchronous Code](#synchronous-code) -- [Arrow Functions](#arrow-functions) -- [Hooks](#hooks) -- [Pending Tests](#pending-tests) -- [Exclusive Tests](#exclusive-tests) -- [Inclusive Tests](#inclusive-tests) -- [Retry Tests](#retry-tests) -- [Dynamically Generating Tests](#dynamically-generating-tests) -- [Timeouts](#timeouts) -- [Diffs](#diffs) -- [Command-Line Usage](#command-line-usage) -- [Interfaces](#interfaces) -- [Reporters](#reporters) -- [Node.JS native ESM support](#nodejs-native-esm-support) -- [Running Mocha in the Browser](#running-mocha-in-the-browser) -- [Desktop Notification Support](#desktop-notification-support) -- [Configuring Mocha (Node.js)](#configuring-mocha-nodejs) -- [The `test/` Directory](#the-test-directory) -- [Error Codes](#error-codes) -- [Editor Plugins](#editor-plugins) -- [Examples](#examples) -- [Testing Mocha](#testing-mocha) -- [More Information](#more-information) - - +{{ toc }} ## Installation @@ -820,92 +788,9 @@ Mocha supports the `err.expected` and `err.actual` properties of any thrown `Ass ## Command-Line Usage - - -```text - -mocha [spec..] - -Run tests with Mocha - -Commands - mocha inspect [spec..] Run tests with Mocha [default] - mocha init create a client-side Mocha setup at - -Rules & Behavior - --allow-uncaught Allow uncaught errors to propagate [boolean] - --async-only, -A Require all tests to use a callback (async) or - return a Promise [boolean] - --bail, -b Abort ("bail") after first test failure [boolean] - --check-leaks Check for global variable leaks [boolean] - --delay Delay initial execution of root suite [boolean] - --exit Force Mocha to quit after tests complete [boolean] - --forbid-only Fail if exclusive test(s) encountered [boolean] - --forbid-pending Fail if pending test(s) encountered [boolean] - --global, --globals List of allowed global variables [array] - --retries Retry failed tests this many times [number] - --slow, -s Specify "slow" test threshold (in milliseconds) - [string] [default: 75] - --timeout, -t, --timeouts Specify test timeout threshold (in milliseconds) - [string] [default: 2000] - --ui, -u Specify user interface [string] [default: "bdd"] - -Reporting & Output - --color, -c, --colors Force-enable color output [boolean] - --diff Show diff on failure - [boolean] [default: true] - --full-trace Display full stack traces [boolean] - --growl, -G Enable Growl notifications [boolean] - --inline-diffs Display actual/expected differences - inline within each string [boolean] - --reporter, -R Specify reporter to use - [string] [default: "spec"] - --reporter-option, --reporter-options, Reporter-specific options - -O () [array] - -Configuration - --config Path to config file [string] [default: (nearest rc file)] - --package Path to package.json for config [string] - -File Handling - --extension File extension(s) to load - [array] [default: ["js","cjs","mjs"]] - --file Specify file(s) to be loaded prior to root suite - execution [array] [default: (none)] - --ignore, --exclude Ignore file(s) or glob pattern(s) - [array] [default: (none)] - --recursive Look for tests in subdirectories [boolean] - --require, -r Require module [array] [default: (none)] - --sort, -S Sort test files [boolean] - --watch, -w Watch files in the current working directory for changes - [boolean] - --watch-files List of paths or globs to watch [array] - --watch-ignore List of paths or globs to exclude from watching - [array] [default: ["node_modules",".git"]] - -Test Filters - --fgrep, -f Only run tests containing this string [string] - --grep, -g Only run tests matching this string or regexp [string] - --invert, -i Inverts --grep and --fgrep matches [boolean] - -Positional Arguments - spec One or more files, directories, or globs to test - [array] [default: ["test"]] - -Other Options - --help, -h Show usage information & exit [boolean] - --version, -V Show version number & exit [boolean] - --list-interfaces List built-in user interfaces & exit [boolean] - --list-reporters List built-in reporters & exit [boolean] - -Mocha Resources - Chat: https://gitter.im/mochajs/mocha - GitHub: https://github.com/mochajs/mocha.git - Docs: https://mochajs.org/ - ``` - - +{{ usage }} +``` ### `--allow-uncaught` @@ -1969,9 +1854,3 @@ or the [source](https://github.com/mochajs/mocha/blob/master/lib/mocha.js). [wallaby.js]: https://wallabyjs.com/ [yargs-configobject-extends]: http://yargs.js.org/docs/#api-configobject-extends-keyword [zsh-globbing]: http://zsh.sourceforge.net/Doc/Release/Expansion.html#Recursive-Globbing - - - -[gitter]: https://gitter.im/mochajs/mocha - - diff --git a/package-lock.json b/package-lock.json index a7c70cbcdf..aa023f0d08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -978,7 +978,7 @@ }, "array-equal": { "version": "1.0.0", - "resolved": "http://registry.npmjs.org/array-equal/-/array-equal-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/array-equal/-/array-equal-1.0.0.tgz", "integrity": "sha1-jCpe8kcv2ep0KwTHenUJO6J1fJM=", "dev": true }, @@ -1838,7 +1838,7 @@ }, "bl": { "version": "1.2.2", - "resolved": "http://registry.npmjs.org/bl/-/bl-1.2.2.tgz", + "resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz", "integrity": "sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==", "dev": true, "requires": { @@ -1861,7 +1861,7 @@ "bn.js": { "version": "4.11.8", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", - "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==", + "integrity": "sha1-LN4J617jQfSEdGuwMJsyU7GxRC8=", "dev": true }, "body-parser": { @@ -3106,7 +3106,7 @@ }, "browserify-aes": { "version": "1.2.0", - "resolved": "http://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", + "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", "dev": true, "requires": { @@ -3149,7 +3149,7 @@ }, "browserify-rsa": { "version": "4.0.1", - "resolved": "http://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz", + "resolved": "https://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz", "integrity": "sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ=", "dev": true, "requires": { @@ -3427,7 +3427,7 @@ }, "camelcase-keys": { "version": "2.1.0", - "resolved": "http://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz", + "resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz", "integrity": "sha1-MIvur/3ygRkFHvodkyITyRuPkuc=", "dev": true, "requires": { @@ -3630,7 +3630,7 @@ "cipher-base": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", - "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", + "integrity": "sha1-h2Dk7MJy9MNjUy+SbYdKriwTl94=", "dev": true, "requires": { "inherits": "^2.0.1", @@ -3725,7 +3725,7 @@ }, "slice-ansi": { "version": "0.0.4", - "resolved": "http://registry.npmjs.org/slice-ansi/-/slice-ansi-0.0.4.tgz", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-0.0.4.tgz", "integrity": "sha1-7b+JA/ZvfOL46v1s7tZeJkyDGzU=", "dev": true }, @@ -4321,7 +4321,7 @@ }, "create-hash": { "version": "1.2.0", - "resolved": "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", + "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", "dev": true, "requires": { @@ -4334,7 +4334,7 @@ }, "create-hmac": { "version": "1.1.7", - "resolved": "http://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", + "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", "dev": true, "requires": { @@ -4349,7 +4349,7 @@ "createerror": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/createerror/-/createerror-1.3.0.tgz", - "integrity": "sha512-w9UZUtkaGd8MfS7eMG7Sa0lV5vCJghqQfiOnwNVrPhbZScUp5h0jwYoAF933MKlotlG1JAJOCCT3xU6r+SDKNw==", + "integrity": "sha1-xma9TNa5TjVBU5ZWnUZJ3QzbMxM=", "dev": true }, "cross-env": { @@ -4422,7 +4422,7 @@ }, "css-color-names": { "version": "0.0.4", - "resolved": "http://registry.npmjs.org/css-color-names/-/css-color-names-0.0.4.tgz", + "resolved": "https://registry.npmjs.org/css-color-names/-/css-color-names-0.0.4.tgz", "integrity": "sha1-gIrcLnnPhHOAabZGyyDsJ762KeA=", "dev": true }, @@ -4820,12 +4820,6 @@ "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", "dev": true }, - "deepmerge": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-1.5.2.tgz", - "integrity": "sha512-95k0GDqvBjZavkuvzx/YqVLv/6YYa17fz6ILMSf7neqQITCPbnfEnQvEgMPNjH4kgobe7+WIL0yJEHku+H3qtQ==", - "dev": true - }, "default-require-extensions": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/default-require-extensions/-/default-require-extensions-3.0.0.tgz", @@ -5059,7 +5053,7 @@ }, "diffie-hellman": { "version": "5.0.3", - "resolved": "http://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz", + "resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz", "integrity": "sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==", "dev": true, "requires": { @@ -5269,7 +5263,7 @@ }, "duplexer": { "version": "0.1.1", - "resolved": "http://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", + "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=", "dev": true }, @@ -5573,7 +5567,7 @@ }, "es6-promisify": { "version": "5.0.0", - "resolved": "http://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", + "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=", "dev": true, "requires": { @@ -6186,7 +6180,7 @@ }, "event-stream": { "version": "3.3.4", - "resolved": "http://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz", + "resolved": "https://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz", "integrity": "sha1-SrTJoPWlTbkzi0w02Gv86PSzVXE=", "dev": true, "requires": { @@ -6214,7 +6208,7 @@ "evp_bytestokey": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", - "integrity": "sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==", + "integrity": "sha1-f8vbGY3HGVlDLv4ThCaE4FJaywI=", "dev": true, "requires": { "md5.js": "^1.3.4", @@ -6773,30 +6767,6 @@ "semver-regex": "^2.0.0" } }, - "findup": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/findup/-/findup-0.1.5.tgz", - "integrity": "sha1-itkpozk7rGJ5V6fl3kYjsGsOLOs=", - "dev": true, - "requires": { - "colors": "~0.6.0-1", - "commander": "~2.1.0" - }, - "dependencies": { - "colors": { - "version": "0.6.2", - "resolved": "http://registry.npmjs.org/colors/-/colors-0.6.2.tgz", - "integrity": "sha1-JCP+ZnisDF2uiFLl0OW+CMmXq8w=", - "dev": true - }, - "commander": { - "version": "2.1.0", - "resolved": "http://registry.npmjs.org/commander/-/commander-2.1.0.tgz", - "integrity": "sha1-0SG7roYNmZKj1Re6lvVliOR8Z4E=", - "dev": true - } - } - }, "flat": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/flat/-/flat-4.1.0.tgz", @@ -7223,7 +7193,7 @@ }, "debug": { "version": "2.2.0", - "resolved": "http://registry.npmjs.org/debug/-/debug-2.2.0.tgz", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz", "integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo=", "dev": true, "requires": { @@ -7232,7 +7202,7 @@ }, "ms": { "version": "0.7.1", - "resolved": "http://registry.npmjs.org/ms/-/ms-0.7.1.tgz", + "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz", "integrity": "sha1-nNE8A62/8ltl7/3nzoZO6VIBcJg=", "dev": true }, @@ -7633,7 +7603,7 @@ "html-encoding-sniffer": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-1.0.2.tgz", - "integrity": "sha512-71lZziiDnsuabfdYiUeWdCVyKuqwWi23L8YeIgV9jSSZHCtb6wB1BKWooH7L3tn4/FuZJMVWyNaIDr4RGmaSYw==", + "integrity": "sha1-5w2EuU2lOqN14R/jo1G+ZkLKRvg=", "dev": true, "requires": { "whatwg-encoding": "^1.0.1" @@ -7662,29 +7632,10 @@ }, "htmlescape": { "version": "1.1.1", - "resolved": "http://registry.npmjs.org/htmlescape/-/htmlescape-1.1.1.tgz", + "resolved": "https://registry.npmjs.org/htmlescape/-/htmlescape-1.1.1.tgz", "integrity": "sha1-OgPtwiFLyjtmQko+eVk0lQnLA1E=", "dev": true }, - "http-basic": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/http-basic/-/http-basic-2.5.1.tgz", - "integrity": "sha1-jORHvbW2xXf4pj4/p4BW7Eu02/s=", - "dev": true, - "requires": { - "caseless": "~0.11.0", - "concat-stream": "^1.4.6", - "http-response-object": "^1.0.0" - }, - "dependencies": { - "caseless": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.11.0.tgz", - "integrity": "sha1-cVuW6phBWTzDMGeSP17GDr2k99c=", - "dev": true - } - } - }, "http-cache-semantics": { "version": "3.8.1", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-3.8.1.tgz", @@ -7722,12 +7673,6 @@ "requires-port": "1.x.x" } }, - "http-response-object": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/http-response-object/-/http-response-object-1.1.0.tgz", - "integrity": "sha1-p8TnWq6C87tJBOT0P2FWc7TVGMM=", - "dev": true - }, "http-signature": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", @@ -8497,12 +8442,6 @@ "is-path-inside": "^1.0.0" } }, - "is-local-path": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/is-local-path/-/is-local-path-0.1.6.tgz", - "integrity": "sha1-gV0USxTVac7L6tTVaTCX8Aqb9sU=", - "dev": true - }, "is-natural-number": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/is-natural-number/-/is-natural-number-4.0.1.tgz", @@ -8591,7 +8530,7 @@ "is-plain-object": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", - "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", + "integrity": "sha1-LBY7P6+xtgbZ0Xko8FwqHDjgdnc=", "dev": true, "requires": { "isobject": "^3.0.1" @@ -9360,7 +9299,7 @@ "dependencies": { "minimist": { "version": "1.2.0", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true } @@ -10392,7 +10331,7 @@ }, "map-stream": { "version": "0.1.0", - "resolved": "http://registry.npmjs.org/map-stream/-/map-stream-0.1.0.tgz", + "resolved": "https://registry.npmjs.org/map-stream/-/map-stream-0.1.0.tgz", "integrity": "sha1-5WqpTEyAVaFkBKBnS3jyFffI4ZQ=", "dev": true }, @@ -10465,133 +10404,6 @@ "integrity": "sha1-MsXGUZmmRXMWMi0eQinRNAfIx88=", "dev": true }, - "markdown-magic": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/markdown-magic/-/markdown-magic-1.0.0.tgz", - "integrity": "sha512-H2Y8eGA19kF5EPs1vdJp0+21mqEkJylFu134anEtolygwvaHZDyBKQVE5mUXxWkuvWizBp5QQU8O8BA8hradmA==", - "dev": true, - "requires": { - "commander": "^2.9.0", - "deepmerge": "^1.3.0", - "find-up": "^2.1.0", - "fs-extra": "^1.0.0", - "globby": "^6.1.0", - "is-local-path": "^0.1.6", - "markdown-toc": "^1.2.0", - "sync-request": "^3.0.1" - }, - "dependencies": { - "array-union": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz", - "integrity": "sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=", - "dev": true, - "requires": { - "array-uniq": "^1.0.1" - } - }, - "find-up": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", - "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", - "dev": true, - "requires": { - "locate-path": "^2.0.0" - } - }, - "fs-extra": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-1.0.0.tgz", - "integrity": "sha1-zTzl9+fLYUWIP8rjGR6Yd/hYeVA=", - "dev": true, - "requires": { - "graceful-fs": "^4.1.2", - "jsonfile": "^2.1.0", - "klaw": "^1.0.0" - } - }, - "globby": { - "version": "6.1.0", - "resolved": "http://registry.npmjs.org/globby/-/globby-6.1.0.tgz", - "integrity": "sha1-9abXDoOV4hyFj7BInWTfAkJNUGw=", - "dev": true, - "requires": { - "array-union": "^1.0.1", - "glob": "^7.0.3", - "object-assign": "^4.0.1", - "pify": "^2.0.0", - "pinkie-promise": "^2.0.0" - } - }, - "jsonfile": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", - "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=", - "dev": true, - "requires": { - "graceful-fs": "^4.1.6" - } - }, - "klaw": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz", - "integrity": "sha1-QIhDO0azsbolnXh4XY6W9zugJDk=", - "dev": true, - "requires": { - "graceful-fs": "^4.1.9" - } - }, - "locate-path": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", - "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", - "dev": true, - "requires": { - "p-locate": "^2.0.0", - "path-exists": "^3.0.0" - } - }, - "p-limit": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", - "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", - "dev": true, - "requires": { - "p-try": "^1.0.0" - } - }, - "p-locate": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", - "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", - "dev": true, - "requires": { - "p-limit": "^1.1.0" - } - }, - "p-try": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", - "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=", - "dev": true - }, - "path-exists": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", - "dev": true - } - } - }, - "markdown-magic-package-json": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/markdown-magic-package-json/-/markdown-magic-package-json-2.0.1.tgz", - "integrity": "sha512-ahEHLW4ovxjGEDkNdirKl01uU6dcZkjtqhc4iJIgwxXwDVq4ThN7cHf1rIA4uaDD4JHAK2hsTHAr7F1TggGt2Q==", - "dev": true, - "requires": { - "findup": "^0.1.5" - } - }, "markdown-table": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/markdown-table/-/markdown-table-1.1.3.tgz", @@ -10601,7 +10413,7 @@ "markdown-toc": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/markdown-toc/-/markdown-toc-1.2.0.tgz", - "integrity": "sha512-eOsq7EGd3asV0oBfmyqngeEIhrbkc7XVP63OwcJBIhH2EpG2PzFcbZdhy1jutXSlRBBVMNXHvMtSr5LAxSUvUg==", + "integrity": "sha1-RKFWBoREkDFK/ARESD+eexEiwzk=", "dev": true, "requires": { "concat-stream": "^1.5.2", @@ -10812,7 +10624,7 @@ }, "media-typer": { "version": "0.3.0", - "resolved": "http://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=", "dev": true }, @@ -10828,7 +10640,7 @@ "dependencies": { "lru-cache": { "version": "2.5.0", - "resolved": "http://registry.npmjs.org/lru-cache/-/lru-cache-2.5.0.tgz", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.5.0.tgz", "integrity": "sha1-2COIrpyWC+y+oMc7uet5tsbOmus=", "dev": true } @@ -10853,7 +10665,7 @@ }, "meow": { "version": "3.7.0", - "resolved": "http://registry.npmjs.org/meow/-/meow-3.7.0.tgz", + "resolved": "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz", "integrity": "sha1-cstmi0JSKCkKu/qFaJJYcwioAfs=", "dev": true, "requires": { @@ -10995,7 +10807,7 @@ "miller-rabin": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/miller-rabin/-/miller-rabin-4.0.1.tgz", - "integrity": "sha512-115fLhvZVqWwHPbClyntxEVfVDfl9DLLTuJvq3g2O/Oxi8AiNouAHvDSzHS0viUJc+V5vm3eq91Xwqn9dp4jRA==", + "integrity": "sha1-8IA1HIZbDcViqEYpZtqlNUPHik0=", "dev": true, "requires": { "bn.js": "^4.0.0", @@ -11283,7 +11095,7 @@ "no-case": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/no-case/-/no-case-2.3.2.tgz", - "integrity": "sha512-rmTZ9kz+f3rCvK2TD1Ue/oZlns7OGoIWP4fc3llxxRXlOkHKoWPPWJOfFYpITabSow43QJbRIoHQXtt10VldyQ==", + "integrity": "sha1-YLgTOWvjmz8SiKTB7V0efSi0ZKw=", "dev": true, "requires": { "lower-case": "^1.1.1" @@ -12235,7 +12047,7 @@ }, "os-homedir": { "version": "1.0.2", - "resolved": "http://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", "dev": true }, @@ -12256,7 +12068,7 @@ }, "os-tmpdir": { "version": "1.0.2", - "resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", "dev": true }, @@ -12626,7 +12438,7 @@ }, "pause-stream": { "version": "0.0.11", - "resolved": "http://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz", + "resolved": "https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz", "integrity": "sha1-/lo0sMvOErWqaitAPuLnO2AvFEU=", "dev": true, "requires": { @@ -12712,7 +12524,7 @@ "postcss": { "version": "5.2.18", "resolved": "https://registry.npmjs.org/postcss/-/postcss-5.2.18.tgz", - "integrity": "sha512-zrUjRRe1bpXKsX1qAJNJjqZViErVuyEkMTRrwu4ud4sbTtIBRmtaYDrHmcGgmrbsW3MHfmtIf+vJumgQn+PrXg==", + "integrity": "sha1-ut+hSX1GJE9jkPWLMZgw2RB4U8U=", "dev": true, "requires": { "chalk": "^1.1.3", @@ -12760,7 +12572,7 @@ }, "pify": { "version": "2.3.0", - "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", "dev": true }, @@ -13559,7 +13371,7 @@ "postcss": { "version": "5.2.18", "resolved": "https://registry.npmjs.org/postcss/-/postcss-5.2.18.tgz", - "integrity": "sha512-zrUjRRe1bpXKsX1qAJNJjqZViErVuyEkMTRrwu4ud4sbTtIBRmtaYDrHmcGgmrbsW3MHfmtIf+vJumgQn+PrXg==", + "integrity": "sha1-ut+hSX1GJE9jkPWLMZgw2RB4U8U=", "dev": true, "requires": { "chalk": "^1.1.3", @@ -14730,7 +14542,7 @@ }, "safe-regex": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", "integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=", "dev": true, "requires": { @@ -14800,7 +14612,7 @@ "sax": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", - "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", + "integrity": "sha1-KBYjTiN4vdxOU1T6tcqold9xANk=", "dev": true }, "saxes": { @@ -14853,7 +14665,7 @@ "dependencies": { "commander": { "version": "2.8.1", - "resolved": "http://registry.npmjs.org/commander/-/commander-2.8.1.tgz", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.8.1.tgz", "integrity": "sha1-Br42f+v9oMMwqh4qBy09yXYkJdQ=", "dev": true, "requires": { @@ -15163,7 +14975,7 @@ }, "sha.js": { "version": "2.4.11", - "resolved": "http://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", + "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", "dev": true, "requires": { @@ -15246,7 +15058,7 @@ }, "shasum": { "version": "1.0.2", - "resolved": "http://registry.npmjs.org/shasum/-/shasum-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/shasum/-/shasum-1.0.2.tgz", "integrity": "sha1-5wEjENj0F/TetXEhUOVni4euVl8=", "dev": true, "requires": { @@ -15851,7 +15663,7 @@ }, "split": { "version": "0.3.3", - "resolved": "http://registry.npmjs.org/split/-/split-0.3.3.tgz", + "resolved": "https://registry.npmjs.org/split/-/split-0.3.3.tgz", "integrity": "sha1-zQ7qXmOiEd//frDwkcQTPi0N0o8=", "dev": true, "requires": { @@ -15950,7 +15762,7 @@ }, "starts-with": { "version": "1.0.2", - "resolved": "http://registry.npmjs.org/starts-with/-/starts-with-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/starts-with/-/starts-with-1.0.2.tgz", "integrity": "sha1-Fnk6cp2J1M89T7LtovkIrjV/GW8=", "dev": true }, @@ -16005,7 +15817,7 @@ }, "stream-combiner": { "version": "0.0.4", - "resolved": "http://registry.npmjs.org/stream-combiner/-/stream-combiner-0.0.4.tgz", + "resolved": "https://registry.npmjs.org/stream-combiner/-/stream-combiner-0.0.4.tgz", "integrity": "sha1-TV5DPBhSYd3mI8o/RMWGvPXErRQ=", "dev": true, "requires": { @@ -16422,17 +16234,6 @@ "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", "dev": true }, - "sync-request": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/sync-request/-/sync-request-3.0.1.tgz", - "integrity": "sha1-yqEjWq+Im6UBB2oYNMQ2gwqC+3M=", - "dev": true, - "requires": { - "concat-stream": "^1.4.7", - "http-response-object": "^1.0.1", - "then-request": "^2.0.1" - } - }, "syntax-error": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/syntax-error/-/syntax-error-1.4.0.tgz", @@ -16598,7 +16399,7 @@ "dependencies": { "bluebird": { "version": "2.9.34", - "resolved": "http://registry.npmjs.org/bluebird/-/bluebird-2.9.34.tgz", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-2.9.34.tgz", "integrity": "sha1-L3tOyAIWMoqf3evfacjUlC/v99g=", "dev": true }, @@ -16734,31 +16535,9 @@ } } }, - "then-request": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/then-request/-/then-request-2.2.0.tgz", - "integrity": "sha1-ZnizL6DKIY/laZgbvYhxtZQGDYE=", - "dev": true, - "requires": { - "caseless": "~0.11.0", - "concat-stream": "^1.4.7", - "http-basic": "^2.5.1", - "http-response-object": "^1.1.0", - "promise": "^7.1.1", - "qs": "^6.1.0" - }, - "dependencies": { - "caseless": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.11.0.tgz", - "integrity": "sha1-cVuW6phBWTzDMGeSP17GDr2k99c=", - "dev": true - } - } - }, "through": { "version": "2.3.8", - "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, @@ -16839,7 +16618,7 @@ "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", - "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", + "integrity": "sha1-bTQzWIl2jSGyvNoKonfO07G/rfk=", "dev": true, "requires": { "os-tmpdir": "~1.0.2" @@ -18465,7 +18244,7 @@ "webidl-conversions": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz", - "integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==", + "integrity": "sha1-qFWYCx8LazWbodXZ+zmulB+qY60=", "dev": true }, "whatwg-encoding": { diff --git a/package-scripts.js b/package-scripts.js index 7406018366..8d2fb5a712 100644 --- a/package-scripts.js +++ b/package-scripts.js @@ -275,26 +275,12 @@ module.exports = { description: 'Post-process docs after build', hiddenFromHelp: true }, - preprocess: { - default: { - script: - 'md-magic --config ./scripts/markdown-magic.config.js --path docs/index.md', - description: 'Preprocess documentation', - hiddenFromHelp: true - }, - api: { - script: - 'md-magic --config ./scripts/markdown-magic.config.js --path "docs/api-tutorials/*.md"', - description: 'Preprocess API documentation', - hiddenFromHelp: true - } - }, watch: { - script: 'nps docs.preprocess && eleventy --serve', + script: 'eleventy --serve', description: 'Watch docs for changes & build' }, api: { - script: 'nps docs.preprocess.api && jsdoc -c jsdoc.conf.json', + script: 'jsdoc -c jsdoc.conf.json', description: 'Build API docs' } }, diff --git a/package.json b/package.json index 777d26bd28..336e672d3d 100644 --- a/package.json +++ b/package.json @@ -112,8 +112,6 @@ "markdown-it-attrs": "^3.0.2", "markdown-it-emoji": "^1.4.0", "markdown-it-prism": "^2.0.5", - "markdown-magic": "^1.0.0", - "markdown-magic-package-json": "^2.0.1", "markdown-toc": "^1.2.0", "markdownlint-cli": "^0.22.0", "nps": "^5.9.12", diff --git a/scripts/markdown-magic.config.js b/scripts/markdown-magic.config.js deleted file mode 100644 index f800a5c9f0..0000000000 --- a/scripts/markdown-magic.config.js +++ /dev/null @@ -1,105 +0,0 @@ -'use strict'; - -/** - * Add autogenerated stuff to our docs (`docs/index.md`) - * @see https://npm.im/markdown-magic - * @private - * @module - */ - -const {execSync} = require('child_process'); -const fs = require('fs'); -const path = require('path'); -const markdownToc = require('markdown-toc'); -const stripAnsi = require('strip-ansi'); - -exports.transforms = { - /** - * Takes STDOUT of some command and injects it into the markdown - */ - usage: (content, options) => { - const {executable} = options; - const flag = options.flag || '--help'; - const header = options.header || '\n```'; - const footer = options.footer || '```\n'; - const output = stripAnsi( - String( - execSync(`"${process.execPath}" ${executable} ${flag}`, { - cwd: path.join(__dirname, '..') - }) - ).trim() - ); - return [header, output, footer].join('\n\n'); - }, - /** - * We can't use the builtin `TOC` plugin in markdown-magic - * because it's simply not flexible enough; we can't pad with newlines, - * nor can we provide a custom filter. the custom filter would be required - * since the `TOC` plugin supplies its own which means we can't use the - * `maxdepth` option, which we need! - */ - toc: (content, options, config) => { - const IGNORED_HEADINGS_REGEXP = /Features|Table of Contents/i; - const toc = markdownToc(config.outputContent, { - slugify: require('uslug'), - bullets: options.bullets, - firsth1: false, - // if filter is supplied, maxdepth is apparently ignored, - // so we have to do it ourselves. - filter: (str, ele) => ele.lvl < 2 && !IGNORED_HEADINGS_REGEXP.test(str) - }).content; - return '\n' + toc + '\n'; - }, - manifest: require('markdown-magic-package-json'), - /** - * Inserts the contents of a file; takes same options as builtin CODE plugin, - * but does not fetch remote URLs, tries to replace relative paths, and - * formats in a way our markdown linter likes. - */ - file: (content, options, config) => { - let output; - if (!options.src) { - return false; - } - const fileDir = path.dirname(config.originalPath); - const filePath = path.join(fileDir, options.src); - const rootDir = path.join(__dirname, '..'); - const relativeDir = path.relative(path.dirname(filePath), rootDir); - - const syntax = options.syntax || path.extname(filePath).replace(/^./, ''); - try { - output = fs.readFileSync(filePath, 'utf8', (err, contents) => { - if (err) { - console.log(`FILE NOT FOUND: ${filePath}`); - throw err; - } - return contents; - }); - } catch (err) { - console.log(`FILE NOT FOUND: ${filePath}`); - throw err; - } - - // replace relative paths in `require()` to root with "mocha". - // might not work in the general case. not gonna parse an AST for this - // e.g. `require('../../lib/foo')` => `require('mocha/lib/foo')` - // also trim any trailing whitespace - output = output - .replace( - new RegExp(`require\\(['"]${relativeDir}(.*?)['"]\\)`, 'g'), - "require('mocha$1')" - ) - .trim(); - - let header = ''; - if (options.header) { - header = `\n${options.header}`; - } - - return ` -\`\`\`${syntax}${header} -${output} -\`\`\` -`; - } -};