unified-args
Advanced tools
Comparing version
@@ -1,2 +0,5 @@ | ||
'use strict' | ||
module.exports = require('./lib') | ||
/** | ||
* @typedef {import('./lib/index.js').Options} Options | ||
*/ | ||
export {args} from './lib/index.js' |
101
lib/index.js
@@ -1,19 +0,20 @@ | ||
'use strict' | ||
/** | ||
* @typedef {import('unified-engine').Options} EngineOptions | ||
* @typedef {import('unified-engine').Context} EngineContext | ||
* @typedef {import('unified-engine').Callback} EngineCallback | ||
* @typedef {import('./options.js').Options} Options | ||
*/ | ||
var stream = require('stream') | ||
var engine = require('unified-engine') | ||
var chalk = require('chalk') | ||
var chokidar = require('chokidar') | ||
var options = require('./options') | ||
import process from 'node:process' | ||
import stream from 'node:stream' | ||
import chalk from 'chalk' | ||
import chokidar from 'chokidar' | ||
import {engine} from 'unified-engine' | ||
import {options} from './options.js' | ||
module.exports = start | ||
var noop = Function.prototype | ||
// Fake TTY stream. | ||
var ttyStream = new stream.Readable() | ||
ttyStream.isTTY = true | ||
const ttyStream = Object.assign(new stream.Readable(), {isTTY: true}) | ||
// Exit, lazily, with the correct exit status code. | ||
var exitStatus = 0 | ||
let exitStatus = 0 | ||
@@ -25,9 +26,17 @@ process.on('exit', onexit) | ||
// Start the CLI. | ||
function start(cliConfig) { | ||
var config | ||
var output | ||
var watcher | ||
/** | ||
* Start the CLI. | ||
* | ||
* @param {Options} cliConfig | ||
*/ | ||
export function args(cliConfig) { | ||
/** @type {EngineOptions & {help: boolean, helpMessage: string, watch: boolean, version: boolean}} */ | ||
let config | ||
/** @type {chokidar.FSWatcher|undefined} */ | ||
let watcher | ||
/** @type {boolean|string|undefined} */ | ||
let output | ||
try { | ||
// @ts-expect-error: Close enough. | ||
config = options(process.argv.slice(2), cliConfig) | ||
@@ -91,11 +100,15 @@ } catch (error) { | ||
// Handle complete run. | ||
function done(err, code, context) { | ||
if (err) { | ||
/** | ||
* Handle complete run. | ||
* | ||
* @type {EngineCallback} | ||
*/ | ||
function done(error, code, context) { | ||
if (error) { | ||
clean() | ||
fail(err) | ||
fail(error) | ||
} else { | ||
exitStatus = code | ||
exitStatus = code || 0 | ||
if (config.watch && !watcher) { | ||
if (config.watch && !watcher && context) { | ||
subscribe(context) | ||
@@ -110,21 +123,26 @@ } | ||
watcher.close() | ||
watcher = null | ||
watcher = undefined | ||
} | ||
} | ||
// Subscribe a chokidar watcher to all processed files. | ||
/** | ||
* Subscribe a chokidar watcher to all processed files. | ||
* | ||
* @param {EngineContext} context | ||
*/ | ||
function subscribe(context) { | ||
watcher = chokidar | ||
// @ts-expect-error: `fileSet` is available. | ||
.watch(context.fileSet.origins, {cwd: config.cwd, ignoreInitial: true}) | ||
.on('error', done) | ||
.on('change', onchange) | ||
.on('change', (filePath) => { | ||
config.files = [filePath] | ||
engine(config, done) | ||
}) | ||
process.on('SIGINT', onsigint) | ||
function onchange(filePath) { | ||
config.files = [filePath] | ||
engine(config, done) | ||
} | ||
/** | ||
* Handle a SIGINT. | ||
*/ | ||
function onsigint() { | ||
@@ -146,7 +164,12 @@ // Hide the `^C` in terminal. | ||
// Print an error, optionally with stack. | ||
function fail(err, pretty) { | ||
var message = | ||
(pretty ? String(err).trim() : err.stack) || | ||
/* istanbul ignore next - Old versions of Node */ err | ||
/** | ||
* Print an error, optionally with stack. | ||
* | ||
* @param {Error} error | ||
* @param {boolean} [pretty=false] | ||
*/ | ||
function fail(error, pretty) { | ||
// Old versions of Node | ||
/* c8 ignore next 1 */ | ||
const message = String((pretty ? error : error.stack) || error) | ||
@@ -163,1 +186,3 @@ exitStatus = 1 | ||
} | ||
function noop() {} |
@@ -1,42 +0,79 @@ | ||
'use strict' | ||
/** | ||
* @typedef {import('unified-engine').Options} EngineOptions | ||
* @typedef {import('./schema.js').Option} Option | ||
* | ||
* @typedef {Required< | ||
* Pick< | ||
* EngineOptions, | ||
* | 'extensions' | ||
* | 'ignoreName' | ||
* | 'packageField' | ||
* | 'pluginPrefix' | ||
* | 'processor' | ||
* | 'rcName' | ||
* > | ||
* >} RequiredEngineOptions | ||
* | ||
* @typedef ArgsOptionsFields | ||
* @property {string} name | ||
* Name of executable | ||
* @property {string} description | ||
* Description of executable | ||
* @property {string} version | ||
* Version (semver) of executable | ||
* | ||
* @typedef {RequiredEngineOptions & Pick<EngineOptions, 'cwd'> & ArgsOptionsFields} Options | ||
*/ | ||
var table = require('text-table') | ||
var camelcase = require('camelcase') | ||
var minimist = require('minimist') | ||
var json5 = require('json5') | ||
var fault = require('fault') | ||
var schema = require('./schema') | ||
import table from 'text-table' | ||
import camelcase from 'camelcase' | ||
import minimist from 'minimist' | ||
import json5 from 'json5' | ||
import {fault} from 'fault' | ||
import {schema} from './schema.js' | ||
module.exports = options | ||
const own = {}.hasOwnProperty | ||
// Schema for `minimist`. | ||
var minischema = { | ||
/** | ||
* Schema for `minimist`. | ||
*/ | ||
const minischema = { | ||
unknown: handleUnknownArgument, | ||
/** @type {Record<string, string|boolean|null>} */ | ||
default: {}, | ||
/** @type {Record<string, string>} */ | ||
alias: {}, | ||
/** @type {string[]} */ | ||
string: [], | ||
/** @type {string[]} */ | ||
boolean: [] | ||
} | ||
schema.forEach(addEach) | ||
let index = -1 | ||
while (++index < schema.length) { | ||
addEach(schema[index]) | ||
} | ||
// Parse CLI options. | ||
function options(flags, configuration) { | ||
var extension = configuration.extensions[0] | ||
var name = configuration.name | ||
var config = toCamelCase(minimist(flags, minischema)) | ||
var help | ||
var ext | ||
var report | ||
/** | ||
* Parse CLI options. | ||
* | ||
* @param {string[]} flags | ||
* @param {Options} configuration | ||
*/ | ||
export function options(flags, configuration) { | ||
const extension = configuration.extensions[0] | ||
const name = configuration.name | ||
const config = toCamelCase(minimist(flags, minischema)) | ||
let index = -1 | ||
schema.forEach(function(option) { | ||
while (++index < schema.length) { | ||
const option = schema[index] | ||
if (option.type === 'string' && config[option.long] === '') { | ||
throw fault('Missing value:%s', inspect(option).join(' ')) | ||
} | ||
}) | ||
} | ||
ext = extensions(config.ext) | ||
report = reporter(config.report) | ||
help = [ | ||
const ext = commaSeparated(/** @type {string} */ (config.ext)) | ||
const report = reporter(/** @type {string} */ (config.report)) | ||
const help = [ | ||
inspectAll(schema), | ||
@@ -58,3 +95,2 @@ '', | ||
helpMessage: help, | ||
// “hidden” feature, makes testing easier. | ||
cwd: configuration.cwd, | ||
@@ -78,8 +114,15 @@ processor: configuration.processor, | ||
detectConfig: config.config, | ||
settings: settings(config.setting), | ||
settings: /** @type {Record<string, unknown>} */ ( | ||
settings(/** @type {string} */ (config.setting)) | ||
), | ||
ignoreName: configuration.ignoreName, | ||
ignorePath: config.ignorePath, | ||
ignorePathResolveFrom: config.ignorePathResolveFrom, | ||
ignorePatterns: commaSeparated( | ||
/** @type {string} */ (config.ignorePattern) | ||
), | ||
silentlyIgnore: config.silentlyIgnore, | ||
detectIgnore: config.ignore, | ||
pluginPrefix: configuration.pluginPrefix, | ||
plugins: plugins(config.use), | ||
plugins: plugins(/** @type {string} */ (config.use)), | ||
reporter: report[0], | ||
@@ -94,8 +137,11 @@ reporterOptions: report[1], | ||
/** | ||
* @param {Option} option | ||
*/ | ||
function addEach(option) { | ||
var value = option.default | ||
const value = option.default | ||
minischema.default[option.long] = value === undefined ? null : value | ||
if (option.type in minischema) { | ||
if (option.type && option.type in minischema) { | ||
minischema[option.type].push(option.long) | ||
@@ -109,16 +155,28 @@ } | ||
// Parse `extensions`. | ||
function extensions(value) { | ||
return flatten(normalize(value).map(splitList)) | ||
/** | ||
* Parse `extensions`. | ||
* | ||
* @param {string[]|string|null|undefined} value | ||
* @returns {string[]} | ||
*/ | ||
function commaSeparated(value) { | ||
return flatten(normalize(value).map((d) => splitList(d))) | ||
} | ||
// Parse `plugins`. | ||
/** | ||
* Parse `plugins`. | ||
* | ||
* @param {string[]|string|null|undefined} value | ||
* @returns {Record<string, Record<string, unknown>|undefined>} | ||
*/ | ||
function plugins(value) { | ||
var result = {} | ||
const normalized = normalize(value).map((d) => splitOptions(d)) | ||
let index = -1 | ||
/** @type {Record<string, Record<string, unknown>|undefined>} */ | ||
const result = {} | ||
normalize(value) | ||
.map(splitOptions) | ||
.forEach(function(value) { | ||
result[value[0]] = value[1] ? parseConfig(value[1], {}) : null | ||
}) | ||
while (++index < normalized.length) { | ||
const value = normalized[index] | ||
result[value[0]] = value[1] ? parseConfig(value[1], {}) : undefined | ||
} | ||
@@ -128,9 +186,17 @@ return result | ||
// Parse `reporter`: only one is accepted. | ||
/** | ||
* Parse `reporter`: only one is accepted. | ||
* | ||
* @param {string[]|string|null|undefined} value | ||
* @returns {[string|undefined, Record<string, unknown>|undefined]} | ||
*/ | ||
function reporter(value) { | ||
var all = normalize(value) | ||
.map(splitOptions) | ||
.map(function(value) { | ||
return [value[0], value[1] ? parseConfig(value[1], {}) : null] | ||
}) | ||
const all = normalize(value) | ||
.map((d) => splitOptions(d)) | ||
.map( | ||
/** | ||
* @returns {[string, Record<string, unknown>|undefined]} | ||
*/ | ||
(value) => [value[0], value[1] ? parseConfig(value[1], {}) : undefined] | ||
) | ||
@@ -140,9 +206,17 @@ return all[all.length - 1] || [] | ||
// Parse `settings`. | ||
/** | ||
* Parse `settings`. | ||
* | ||
* @param {string[]|string|null|undefined} value | ||
* @returns {Record<string, unknown>} | ||
*/ | ||
function settings(value) { | ||
var cache = {} | ||
const normalized = normalize(value) | ||
let index = -1 | ||
/** @type {Record<string, unknown>} */ | ||
const cache = {} | ||
normalize(value).forEach(function(value) { | ||
parseConfig(value, cache) | ||
}) | ||
while (++index < normalized.length) { | ||
parseConfig(normalized[index], cache) | ||
} | ||
@@ -152,18 +226,30 @@ return cache | ||
// Parse configuration. | ||
function parseConfig(flags, cache) { | ||
var flag | ||
var message | ||
/** | ||
* Parse configuration. | ||
* | ||
* @param {string} value | ||
* @param {Record<string, unknown>} cache | ||
* @returns {Record<string, unknown>} | ||
*/ | ||
function parseConfig(value, cache) { | ||
/** @type {Record<string, unknown>} */ | ||
let flags | ||
/** @type {string} */ | ||
let flag | ||
try { | ||
flags = toCamelCase(parseJSON(flags)) | ||
flags = toCamelCase(parseJSON(value)) | ||
} catch (error) { | ||
// Fix position | ||
message = error.message.replace(/at(?= position)/, 'around') | ||
throw fault('Cannot parse `%s` as JSON: %s', flags, message) | ||
throw fault( | ||
'Cannot parse `%s` as JSON: %s', | ||
value, | ||
// Fix position | ||
error.message.replace(/at(?= position)/, 'around') | ||
) | ||
} | ||
for (flag in flags) { | ||
cache[flag] = flags[flag] | ||
if (own.call(flags, flag)) { | ||
cache[flag] = flags[flag] | ||
} | ||
} | ||
@@ -174,54 +260,60 @@ | ||
// Handle an unknown flag. | ||
/** | ||
* Handle an unknown flag. | ||
* | ||
* @param {string} flag | ||
* @returns {boolean} | ||
*/ | ||
function handleUnknownArgument(flag) { | ||
// Glob. | ||
if (flag.charAt(0) !== '-') { | ||
return | ||
} | ||
// Not a glob. | ||
if (flag.charAt(0) === '-') { | ||
// Long options, always unknown. | ||
if (flag.charAt(1) === '-') { | ||
throw fault( | ||
'Unknown option `%s`, expected:\n%s', | ||
flag, | ||
inspectAll(schema) | ||
) | ||
} | ||
// Long options, always unknown. | ||
if (flag.charAt(1) === '-') { | ||
throw fault('Unknown option `%s`, expected:\n%s', flag, inspectAll(schema)) | ||
} | ||
// Short options, can be grouped. | ||
const found = flag.slice(1).split('') | ||
const known = schema.filter((d) => d.short) | ||
const knownKeys = new Set(known.map((d) => d.short)) | ||
let index = -1 | ||
// Short options, can be grouped. | ||
flag | ||
.slice(1) | ||
.split('') | ||
.forEach(each) | ||
function each(key) { | ||
var length = schema.length | ||
var index = -1 | ||
var option | ||
while (++index < length) { | ||
option = schema[index] | ||
if (option.short === key) { | ||
return | ||
while (++index < found.length) { | ||
const key = found[index] | ||
if (!knownKeys.has(key)) { | ||
throw fault( | ||
'Unknown short option `-%s`, expected:\n%s', | ||
key, | ||
inspectAll(known) | ||
) | ||
} | ||
} | ||
throw fault( | ||
'Unknown short option `-%s`, expected:\n%s', | ||
key, | ||
inspectAll(schema.filter(short)) | ||
) | ||
} | ||
function short(option) { | ||
return option.short | ||
} | ||
return true | ||
} | ||
// Inspect all `options`. | ||
/** | ||
* Inspect all `options`. | ||
* | ||
* @param {Option[]} options | ||
* @returns {string} | ||
*/ | ||
function inspectAll(options) { | ||
return table(options.map(inspect)) | ||
return table(options.map((d) => inspect(d))) | ||
} | ||
// Inspect one `option`. | ||
/** | ||
* Inspect one `option`. | ||
* | ||
* @param {Option} option | ||
* @returns {string[]} | ||
*/ | ||
function inspect(option) { | ||
var description = option.description | ||
var long = option.long | ||
let description = option.description | ||
let long = option.long | ||
@@ -241,3 +333,8 @@ if (option.default === true || option.truelike) { | ||
// Normalize `value`. | ||
/** | ||
* Normalize `value`. | ||
* | ||
* @param {string[]|string|null|undefined} value | ||
* @returns {string[]} | ||
*/ | ||
function normalize(value) { | ||
@@ -252,10 +349,20 @@ if (!value) { | ||
return flatten(value.map(normalize)) | ||
return flatten(value.map((d) => normalize(d))) | ||
} | ||
// Flatten `values`. | ||
/** | ||
* Flatten `values`. | ||
* | ||
* @param {string|string[]|string[][]} values | ||
* @returns {string[]} | ||
*/ | ||
function flatten(values) { | ||
return [].concat.apply([], values) | ||
// @ts-expect-error: TS is wrong. | ||
return values.flat() | ||
} | ||
/** | ||
* @param {string} value | ||
* @returns {string[]} | ||
*/ | ||
function splitOptions(value) { | ||
@@ -265,2 +372,6 @@ return value.split('=') | ||
/** | ||
* @param {string} value | ||
* @returns {string[]} | ||
*/ | ||
function splitList(value) { | ||
@@ -270,16 +381,25 @@ return value.split(',') | ||
// Transform the keys on an object to camel-case, recursivly. | ||
/** | ||
* Transform the keys on an object to camel-case, recursivly. | ||
* | ||
* @param {Record<string, unknown>} object | ||
* @returns {Record<string, unknown>} | ||
*/ | ||
function toCamelCase(object) { | ||
var result = {} | ||
var value | ||
var key | ||
/** @type {Record<string, unknown>} */ | ||
const result = {} | ||
/** @type {string} */ | ||
let key | ||
for (key in object) { | ||
value = object[key] | ||
if (own.call(object, key)) { | ||
let value = object[key] | ||
if (value && typeof value === 'object' && !('length' in value)) { | ||
value = toCamelCase(value) | ||
if (value && typeof value === 'object' && !Array.isArray(value)) { | ||
// @ts-expect-error: looks like an object. | ||
value = toCamelCase(value) | ||
} | ||
result[camelcase(key)] = value | ||
} | ||
result[camelcase(key)] = value | ||
} | ||
@@ -290,5 +410,10 @@ | ||
// Parse a (lazy?) JSON config. | ||
/** | ||
* Parse a (lazy?) JSON config. | ||
* | ||
* @param {string} value | ||
* @returns {Record<string, unknown>} | ||
*/ | ||
function parseJSON(value) { | ||
return json5.parse('{' + value + '}') | ||
} |
{ | ||
"name": "unified-args", | ||
"version": "7.0.0", | ||
"version": "9.0.1", | ||
"description": "Create CLIs for unified processors", | ||
@@ -15,41 +15,56 @@ "license": "MIT", | ||
"bugs": "https://github.com/unifiedjs/unified-args/issues", | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/unified" | ||
}, | ||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", | ||
"contributors": [ | ||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)" | ||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", | ||
"Christian Murphy <christian.murphy.42@gmail.com" | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"lib/" | ||
"lib/", | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"camelcase": "^5.0.0", | ||
"chalk": "^2.0.0", | ||
"@types/text-table": "^0.2.0", | ||
"camelcase": "^6.0.0", | ||
"chalk": "^4.0.0", | ||
"chokidar": "^3.0.0", | ||
"fault": "^1.0.2", | ||
"fault": "^2.0.0", | ||
"json5": "^2.0.0", | ||
"minimist": "^1.2.0", | ||
"text-table": "^0.2.0", | ||
"unified-engine": "^7.0.0" | ||
"minimist": "^1.0.0", | ||
"text-table": "^0.2.0" | ||
}, | ||
"devDependencies": { | ||
"bail": "^1.0.0", | ||
"execa": "^2.0.0", | ||
"figures": "^3.0.0", | ||
"nyc": "^14.0.0", | ||
"prettier": "^1.0.0", | ||
"remark-cli": "^6.0.0", | ||
"remark-preset-wooorm": "^5.0.0", | ||
"strip-ansi": "^5.0.0", | ||
"tape": "^4.0.0", | ||
"@types/tape": "^4.0.0", | ||
"@types/touch": "^3.0.0", | ||
"bail": "^2.0.0", | ||
"c8": "^7.0.0", | ||
"execa": "^5.0.0", | ||
"prettier": "^2.0.0", | ||
"remark": "^14.0.0", | ||
"remark-cli": "^10.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"rimraf": "^3.0.0", | ||
"strip-ansi": "^7.0.0", | ||
"tape": "^5.0.0", | ||
"touch": "^3.0.0", | ||
"unified": "^8.0.0", | ||
"vfile-reporter-json": "^2.0.0", | ||
"xo": "^0.24.0", | ||
"xtend": "^4.0.0" | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"unified": "^10.0.0", | ||
"vfile-reporter-json": "^3.0.0", | ||
"xo": "^0.44.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test/index.js", | ||
"test": "npm run format && npm run test-coverage" | ||
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" && tsc && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node --conditions development test/index.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --conditions development test/index.js", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
@@ -65,14 +80,4 @@ "prettier": { | ||
"xo": { | ||
"prettier": true, | ||
"esnext": false, | ||
"rules": { | ||
"guard-for-in": "off" | ||
} | ||
"prettier": true | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"remarkConfig": { | ||
@@ -82,3 +87,9 @@ "plugins": [ | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
} | ||
} |
281
readme.md
@@ -16,8 +16,10 @@ # unified-args | ||
[`unifiedjs.github.io`][site], the website for **unified** provides a good | ||
overview about what unified can do. | ||
Make sure to visit it and try its introductionary [Guides][]. | ||
[`unifiedjs.com`][site], the website for **unified** provides a good overview | ||
about what unified can do. | ||
## Install | ||
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): | ||
Node 12+ is needed to use it and it must be `import`ed instead of `require`d. | ||
[npm][]: | ||
@@ -39,51 +41,50 @@ | ||
#!/usr/bin/env node | ||
'use strict' | ||
import {args} from 'unified-args' | ||
import extensions from 'markdown-extensions' | ||
import {remark} from 'remark' | ||
var start = require('unified-args') | ||
var extensions = require('markdown-extensions') | ||
var remark = require('remark') | ||
var pack = require('remark/package.json') | ||
var name = pack.name | ||
start({ | ||
args({ | ||
processor: remark, | ||
name: name, | ||
description: pack.description, | ||
version: pack.version, | ||
pluginPrefix: name, | ||
extensions: extensions, | ||
packageField: name + 'Config', | ||
rcName: '.' + name + 'rc', | ||
ignoreName: '.' + name + 'ignore' | ||
name: 'remark', | ||
description: | ||
'Markdown processor powered by plugins part of the unified collective', | ||
version: '14.0.0', | ||
pluginPrefix: 'remark', | ||
extensions, | ||
packageField: 'remarkConfig', | ||
rcName: '.remarkrc', | ||
ignoreName: '.remarkignore' | ||
}) | ||
``` | ||
## Table of Contents | ||
## Contents | ||
* [API](#api) | ||
* [start(configuration)](#startconfiguration) | ||
* [`args(configuration)`](#argsconfiguration) | ||
* [CLI](#cli) | ||
* [--help](#--help) | ||
* [--version](#--version) | ||
* [--output \[path\]](#--output-path) | ||
* [--rc-path <path>](#--rc-path-path) | ||
* [--ignore-path <path>](#--ignore-path-path) | ||
* [--setting <settings>](#--setting-settings) | ||
* [--report <reporter>](#--report-reporter) | ||
* [--use <plugin>](#--use-plugin) | ||
* [--ext <extensions>](#--ext-extensions) | ||
* [--watch](#--watch) | ||
* [--tree](#--tree) | ||
* [--tree-in](#--tree-in) | ||
* [--tree-out](#--tree-out) | ||
* [--inspect](#--inspect) | ||
* [--quiet](#--quiet) | ||
* [--silent](#--silent) | ||
* [--frail](#--frail) | ||
* [--file-path <path>](#--file-path-path) | ||
* [--stdout](#--stdout) | ||
* [--color](#--color) | ||
* [--config](#--config) | ||
* [--ignore](#--ignore) | ||
* [`--help`](#--help) | ||
* [`--version`](#--version) | ||
* [`--output [path]`](#--output-path) | ||
* [`--rc-path <path>`](#--rc-path-path) | ||
* [`--ignore-path <path>`](#--ignore-path-path) | ||
* [`--ignore-path-resolve-from dir|cwd`](#--ignore-path-resolve-from-dircwd) | ||
* [`--ignore-pattern <globs>`](#--ignore-pattern-globs) | ||
* [`--silently-ignore`](#--silently-ignore) | ||
* [`--setting <settings>`](#--setting-settings) | ||
* [`--report <reporter>`](#--report-reporter) | ||
* [`--use <plugin>`](#--use-plugin) | ||
* [`--ext <extensions>`](#--ext-extensions) | ||
* [`--watch`](#--watch) | ||
* [`--tree`](#--tree) | ||
* [`--tree-in`](#--tree-in) | ||
* [`--tree-out`](#--tree-out) | ||
* [`--inspect`](#--inspect) | ||
* [`--quiet`](#--quiet) | ||
* [`--silent`](#--silent) | ||
* [`--frail`](#--frail) | ||
* [`--file-path <path>`](#--file-path-path) | ||
* [`--stdout`](#--stdout) | ||
* [`--color`](#--color) | ||
* [`--config`](#--config) | ||
* [`--ignore`](#--ignore) | ||
* [Diagnostics](#diagnostics) | ||
@@ -96,4 +97,7 @@ * [Debugging](#debugging) | ||
### `start(configuration)` | ||
This package exports the following identifiers: `args`. | ||
There is no default export. | ||
### `args(configuration)` | ||
Create a CLI for a [**unified**][unified] processor. | ||
@@ -143,24 +147,27 @@ | ||
-h --help output usage information | ||
-v --version output version number | ||
-o --output [path] specify output location | ||
-r --rc-path <path> specify configuration file | ||
-i --ignore-path <path> specify ignore file | ||
-s --setting <settings> specify settings | ||
-e --ext <extensions> specify extensions | ||
-u --use <plugins> use plugins | ||
-w --watch watch for changes and reprocess | ||
-q --quiet output only warnings and errors | ||
-S --silent output only errors | ||
-f --frail exit with 1 on warnings | ||
-t --tree specify input and output as syntax tree | ||
--report <reporter> specify reporter | ||
--file-path <path> specify path to process as | ||
--tree-in specify input as syntax tree | ||
--tree-out output syntax tree | ||
--inspect output formatted syntax tree | ||
--[no-]stdout specify writing to stdout (on by default) | ||
--[no-]color specify color in report (on by default) | ||
--[no-]config search for configuration files (on by default) | ||
--[no-]ignore search for ignore files (on by default) | ||
-h --help output usage information | ||
-v --version output version number | ||
-o --output [path] specify output location | ||
-r --rc-path <path> specify configuration file | ||
-i --ignore-path <path> specify ignore file | ||
-s --setting <settings> specify settings | ||
-e --ext <extensions> specify extensions | ||
-u --use <plugins> use plugins | ||
-w --watch watch for changes and reprocess | ||
-q --quiet output only warnings and errors | ||
-S --silent output only errors | ||
-f --frail exit with 1 on warnings | ||
-t --tree specify input and output as syntax tree | ||
--report <reporter> specify reporter | ||
--file-path <path> specify path to process as | ||
--ignore-path-resolve-from dir|cwd resolve patterns in `ignore-path` from its directory or cwd | ||
--ignore-pattern <globs> specify ignore patterns | ||
--silently-ignore do not fail when given ignored files | ||
--tree-in specify input as syntax tree | ||
--tree-out output syntax tree | ||
--inspect output formatted syntax tree | ||
--[no-]stdout specify writing to stdout (on by default) | ||
--[no-]color specify color in report (on by default) | ||
--[no-]config search for configuration files (on by default) | ||
--[no-]ignore search for ignore files (on by default) | ||
@@ -187,3 +194,3 @@ Examples: | ||
ignored by patterns in [ignore files][ignore-file]. | ||
The default behaviour is to exclude files in `node_modules` and hidden | ||
The default behavior is to exclude files in `node_modules` and hidden | ||
directories (those starting with a dot: `.`) unless explicitly given | ||
@@ -271,2 +278,37 @@ | ||
### `--ignore-path-resolve-from dir|cwd` | ||
```sh | ||
cli . --ignore-path node_modules/my-config/my-ignore --ignore-path-resolve-from cwd | ||
``` | ||
Resolve patterns in the ignore file from its directory (`dir`, default) or the | ||
current working directory (`cwd`). | ||
* **Default**: `dir` | ||
* **Engine**: [`ignorePathResolveFrom`][engine-ignore-path-resolve-from] | ||
### `--ignore-pattern <globs>` | ||
```sh | ||
cli . --ignore-pattern docs/*.md | ||
``` | ||
Additional patterns to use to ignore files. | ||
* **Default**: none | ||
* **Engine**: [`ignorePatterns`][engine-ignore-patterns] | ||
### `--silently-ignore` | ||
```sh | ||
cli **/*.md --silently-ignore | ||
``` | ||
Skip given files which are ignored by ignore files, instead of warning about | ||
them. | ||
* **Default**: off | ||
* **Engine**: [`silentlyIgnore`][engine-silently-ignore] | ||
### `--setting <settings>` | ||
@@ -284,4 +326,4 @@ | ||
The given settings are [JSON5][], with one exceptions: surrounding braces must | ||
not be used: `"foo": 1, "bar": "baz"` is valid | ||
The given settings are [JSON5][], with one exception: surrounding braces must | ||
not be used. Instead, use JSON syntax without braces, such as `"foo": 1, "bar": "baz"`. | ||
@@ -304,3 +346,3 @@ * **Default**: none | ||
[Reporter][] to load by its name or path, optionally with options, and use to | ||
report metadata about eevery processed file. | ||
report metadata about every processed file. | ||
@@ -331,2 +373,3 @@ To pass options, follow the name by an equals sign (`=`) and settings, which | ||
cli input.txt --use 'toc=max-depth:3' | ||
cli input.txt --use ./plugin.js | ||
``` | ||
@@ -381,3 +424,3 @@ | ||
If [`--output`][output] is given **without** `path` it is not honoured, to | ||
If [`--output`][output] is given **without** `path` it is not honored, to | ||
prevent an infinite loop. | ||
@@ -447,3 +490,3 @@ On operating systems other than Windows, when the watch closes, a final process | ||
Ignore files without any messages in the report. | ||
The default behaviour is to show a success message. | ||
The default behavior is to show a success message. | ||
@@ -459,4 +502,2 @@ * **Default**: off | ||
###### Note | ||
The [`quiet`][quiet], [`silent`][silent], and [`color`][color] options may not | ||
@@ -490,3 +531,3 @@ work with the used reporter. | ||
Exit with a status code of `1` if warnings or errors occur. | ||
The default behaviour is to exit with `1` on errors. | ||
The default behavior is to exit with `1` on errors. | ||
@@ -528,3 +569,3 @@ * **Default**: off | ||
* **Default**: whether the terminal [supports colour][supports-color] | ||
* **Default**: whether the terminal [supports color][supports-color] | ||
* **Engine**: [`color`][engine-color] | ||
@@ -584,4 +625,4 @@ | ||
This project has a [Code of Conduct][coc]. | ||
By interacting with this repository, organisation, or community you agree to | ||
This project has a [code of conduct][coc]. | ||
By interacting with this repository, organization, or community you agree to | ||
abide by its terms. | ||
@@ -595,5 +636,5 @@ | ||
[build-badge]: https://img.shields.io/travis/unifiedjs/unified-args.svg | ||
[build-badge]: https://github.com/unifiedjs/unified-args/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/unifiedjs/unified-args | ||
[build]: https://github.com/unifiedjs/unified-args/actions | ||
@@ -614,5 +655,5 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/unifiedjs/unified-args.svg | ||
[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[chat]: https://spectrum.chat/unified | ||
[chat]: https://github.com/unifiedjs/unified/discussions | ||
@@ -623,7 +664,7 @@ [npm]: https://docs.npmjs.com/cli/install | ||
[contributing]: https://github.com/unifiedjs/.github/blob/master/contributing.md | ||
[contributing]: https://github.com/unifiedjs/.github/blob/HEAD/contributing.md | ||
[support]: https://github.com/unifiedjs/.github/blob/master/support.md | ||
[support]: https://github.com/unifiedjs/.github/blob/HEAD/support.md | ||
[coc]: https://github.com/unifiedjs/.github/blob/master/code-of-conduct.md | ||
[coc]: https://github.com/unifiedjs/.github/blob/HEAD/code-of-conduct.md | ||
@@ -648,62 +689,68 @@ [license]: license | ||
[config-file]: https://github.com/unifiedjs/unified-engine/blob/master/doc/configure.md | ||
[config-file]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/configure.md | ||
[ignore-file]: https://github.com/unifiedjs/unified-engine/blob/master/doc/ignore.md | ||
[ignore-file]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/ignore.md | ||
[description]: https://github.com/unifiedjs/unified#description | ||
[engine-processor]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsprocessor | ||
[engine-processor]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsprocessor | ||
[engine-files]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsfiles | ||
[engine-files]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsfiles | ||
[engine-output]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsoutput | ||
[engine-output]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsoutput | ||
[engine-rc-path]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsrcpath | ||
[engine-rc-path]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsrcpath | ||
[engine-rc-name]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsrcname | ||
[engine-rc-name]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsrcname | ||
[engine-package-field]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionspackagefield | ||
[engine-package-field]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionspackagefield | ||
[engine-ignore-name]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsignorename | ||
[engine-ignore-name]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsignorename | ||
[engine-ignore-path]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsignorepath | ||
[engine-ignore-path]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsignorepath | ||
[engine-reporter]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsreporter | ||
[engine-ignore-path-resolve-from]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsignorepathresolvefrom | ||
[engine-reporter-options]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsreporteroptions | ||
[engine-ignore-patterns]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsignorepatterns | ||
[engine-settings]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionssettings | ||
[engine-silently-ignore]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionssilentlyignore | ||
[engine-plugins]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsplugins | ||
[engine-reporter]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsreporter | ||
[engine-plugin-prefix]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionspluginprefix | ||
[engine-reporter-options]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsreporteroptions | ||
[engine-extensions]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsextensions | ||
[engine-settings]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionssettings | ||
[engine-tree]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionstree | ||
[engine-plugins]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsplugins | ||
[engine-tree-in]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionstreein | ||
[engine-plugin-prefix]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionspluginprefix | ||
[engine-tree-out]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionstreeout | ||
[engine-extensions]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsextensions | ||
[engine-inspect]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsinspect | ||
[engine-tree]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionstree | ||
[engine-quiet]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsquiet | ||
[engine-tree-in]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionstreein | ||
[engine-silent]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsilent | ||
[engine-tree-out]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionstreeout | ||
[engine-frail]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsfrail | ||
[engine-inspect]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsinspect | ||
[engine-file-path]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsfilepath | ||
[engine-quiet]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsquiet | ||
[engine-out]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsout | ||
[engine-silent]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsilent | ||
[engine-color]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionscolor | ||
[engine-frail]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsfrail | ||
[engine-detect-config]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsdetectconfig | ||
[engine-file-path]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsfilepath | ||
[engine-detect-ignore]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsdetectignore | ||
[engine-out]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsout | ||
[configured]: #startconfiguration | ||
[engine-color]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionscolor | ||
[engine-detect-config]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsdetectconfig | ||
[engine-detect-ignore]: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/options.md#optionsdetectignore | ||
[configured]: #argsconfiguration | ||
[usage]: #use | ||
@@ -735,6 +782,4 @@ | ||
[site]: https://unifiedjs.github.io | ||
[site]: https://unifiedjs.com | ||
[guides]: https://unifiedjs.github.io/#guides | ||
[reporter]: https://github.com/vfile/vfile#reporters | ||
@@ -741,0 +786,0 @@ |
44452
28.09%11
57.14%797
59.72%772
6.19%Yes
NaN18
28.57%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated