Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 9, 2021
1 parent 3c2b431 commit 91f0875
Show file tree
Hide file tree
Showing 21 changed files with 298 additions and 324 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.DS_Store
*.log
.nyc_output/
coverage/
node_modules/
.DS_Store
*.log
yarn.lock
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
coverage/
*.json
*.md
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
'use strict'
module.exports = require('./lib/index.js')
export {args} from './lib/index.js'
22 changes: 9 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
'use strict'

var stream = require('stream')
var engine = require('unified-engine')
var chalk = require('chalk')
var chokidar = require('chokidar')
var options = require('./options.js')

module.exports = start
import stream from 'stream'
import engine from 'unified-engine'
import chalk from 'chalk'
import chokidar from 'chokidar'
import {options} from './options.js'

var noop = Function.prototype

Expand All @@ -23,7 +19,7 @@ process.on('exit', onexit)
process.on('uncaughtException', fail)

// Start the CLI.
function start(cliConfig) {
export function args(cliConfig) {
var config
var output
var watcher
Expand Down Expand Up @@ -142,9 +138,9 @@ function start(cliConfig) {

// Print an error, optionally with stack.
function fail(error, pretty) {
var message =
(pretty ? String(error).trim() : error.stack) ||
/* istanbul ignore next - Old versions of Node */ error
// Old versions of Node
/* c8 ignore next 1 */
var message = (pretty ? String(error).trim() : error.stack) || error

exitStatus = 1

Expand Down
19 changes: 8 additions & 11 deletions lib/options.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
'use strict'

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.json')

module.exports = options
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'

// Schema for `minimist`.
var minischema = {
Expand All @@ -24,7 +20,7 @@ while (++index < schema.length) {
}

// Parse CLI options.
function options(flags, configuration) {
export function options(flags, configuration) {
var extension = configuration.extensions[0]
var name = configuration.name
var config = toCamelCase(minimist(flags, minischema))
Expand Down Expand Up @@ -243,6 +239,7 @@ function normalize(value) {

// Flatten `values`.
function flatten(values) {
// eslint-disable-next-line prefer-spread
return [].concat.apply([], values)
}

Expand Down
161 changes: 161 additions & 0 deletions lib/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
export const schema = [
{
long: 'help',
description: 'output usage information',
short: 'h',
type: 'boolean',
default: false
},
{
long: 'version',
description: 'output version number',
short: 'v',
type: 'boolean',
default: false
},
{
long: 'output',
description: 'specify output location',
short: 'o',
value: '[path]'
},
{
long: 'rc-path',
description: 'specify configuration file',
short: 'r',
type: 'string',
value: '<path>'
},
{
long: 'ignore-path',
description: 'specify ignore file',
short: 'i',
type: 'string',
value: '<path>'
},
{
long: 'setting',
description: 'specify settings',
short: 's',
type: 'string',
value: '<settings>'
},
{
long: 'ext',
description: 'specify extensions',
short: 'e',
type: 'string',
value: '<extensions>'
},
{
long: 'use',
description: 'use plugins',
short: 'u',
type: 'string',
value: '<plugins>'
},
{
long: 'watch',
description: 'watch for changes and reprocess',
short: 'w',
type: 'boolean',
default: false
},
{
long: 'quiet',
description: 'output only warnings and errors',
short: 'q',
type: 'boolean',
default: false
},
{
long: 'silent',
description: 'output only errors',
short: 'S',
type: 'boolean',
default: false
},
{
long: 'frail',
description: 'exit with 1 on warnings',
short: 'f',
type: 'boolean',
default: false
},
{
long: 'tree',
description: 'specify input and output as syntax tree',
short: 't',
type: 'boolean',
default: false
},
{
long: 'report',
description: 'specify reporter',
type: 'string',
value: '<reporter>'
},
{
long: 'file-path',
description: 'specify path to process as',
type: 'string',
value: '<path>'
},
{
long: 'ignore-path-resolve-from',
description: 'resolve patterns in `ignore-path` from its directory or cwd',
type: 'string',
value: 'dir|cwd',
default: 'dir'
},
{
long: 'ignore-pattern',
description: 'specify ignore patterns',
type: 'string',
value: '<globs>'
},
{
long: 'silently-ignore',
description: 'do not fail when given ignored files',
type: 'boolean'
},
{
long: 'tree-in',
description: 'specify input as syntax tree',
type: 'boolean'
},
{
long: 'tree-out',
description: 'output syntax tree',
type: 'boolean'
},
{
long: 'inspect',
description: 'output formatted syntax tree',
type: 'boolean'
},
{
long: 'stdout',
description: 'specify writing to stdout',
type: 'boolean',
truelike: true
},
{
long: 'color',
description: 'specify color in report',
type: 'boolean',
default: true
},
{
long: 'config',
description: 'search for configuration files',
type: 'boolean',
default: true
},
{
long: 'ignore',
description: 'search for ignore files',
type: 'boolean',
default: true
}
]

0 comments on commit 91f0875

Please sign in to comment.