Skip to content

Commit 91f0875

Browse files
committed
Use ESM
1 parent 3c2b431 commit 91f0875

21 files changed

+298
-324
lines changed

.gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
.DS_Store
2-
*.log
3-
.nyc_output/
41
coverage/
52
node_modules/
3+
.DS_Store
4+
*.log
65
yarn.lock

.prettierignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
coverage/
2-
*.json
32
*.md

index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
'use strict'
2-
module.exports = require('./lib/index.js')
1+
export {args} from './lib/index.js'

lib/index.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
'use strict'
2-
3-
var stream = require('stream')
4-
var engine = require('unified-engine')
5-
var chalk = require('chalk')
6-
var chokidar = require('chokidar')
7-
var options = require('./options.js')
8-
9-
module.exports = start
1+
import stream from 'stream'
2+
import engine from 'unified-engine'
3+
import chalk from 'chalk'
4+
import chokidar from 'chokidar'
5+
import {options} from './options.js'
106

117
var noop = Function.prototype
128

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

2521
// Start the CLI.
26-
function start(cliConfig) {
22+
export function args(cliConfig) {
2723
var config
2824
var output
2925
var watcher
@@ -142,9 +138,9 @@ function start(cliConfig) {
142138

143139
// Print an error, optionally with stack.
144140
function fail(error, pretty) {
145-
var message =
146-
(pretty ? String(error).trim() : error.stack) ||
147-
/* istanbul ignore next - Old versions of Node */ error
141+
// Old versions of Node
142+
/* c8 ignore next 1 */
143+
var message = (pretty ? String(error).trim() : error.stack) || error
148144

149145
exitStatus = 1
150146

lib/options.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
'use strict'
2-
3-
var table = require('text-table')
4-
var camelcase = require('camelcase')
5-
var minimist = require('minimist')
6-
var json5 = require('json5')
7-
var fault = require('fault')
8-
var schema = require('./schema.json')
9-
10-
module.exports = options
1+
import table from 'text-table'
2+
import camelcase from 'camelcase'
3+
import minimist from 'minimist'
4+
import json5 from 'json5'
5+
import fault from 'fault'
6+
import {schema} from './schema.js'
117

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

2622
// Parse CLI options.
27-
function options(flags, configuration) {
23+
export function options(flags, configuration) {
2824
var extension = configuration.extensions[0]
2925
var name = configuration.name
3026
var config = toCamelCase(minimist(flags, minischema))
@@ -243,6 +239,7 @@ function normalize(value) {
243239

244240
// Flatten `values`.
245241
function flatten(values) {
242+
// eslint-disable-next-line prefer-spread
246243
return [].concat.apply([], values)
247244
}
248245

lib/schema.js

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
export const schema = [
2+
{
3+
long: 'help',
4+
description: 'output usage information',
5+
short: 'h',
6+
type: 'boolean',
7+
default: false
8+
},
9+
{
10+
long: 'version',
11+
description: 'output version number',
12+
short: 'v',
13+
type: 'boolean',
14+
default: false
15+
},
16+
{
17+
long: 'output',
18+
description: 'specify output location',
19+
short: 'o',
20+
value: '[path]'
21+
},
22+
{
23+
long: 'rc-path',
24+
description: 'specify configuration file',
25+
short: 'r',
26+
type: 'string',
27+
value: '<path>'
28+
},
29+
{
30+
long: 'ignore-path',
31+
description: 'specify ignore file',
32+
short: 'i',
33+
type: 'string',
34+
value: '<path>'
35+
},
36+
{
37+
long: 'setting',
38+
description: 'specify settings',
39+
short: 's',
40+
type: 'string',
41+
value: '<settings>'
42+
},
43+
{
44+
long: 'ext',
45+
description: 'specify extensions',
46+
short: 'e',
47+
type: 'string',
48+
value: '<extensions>'
49+
},
50+
{
51+
long: 'use',
52+
description: 'use plugins',
53+
short: 'u',
54+
type: 'string',
55+
value: '<plugins>'
56+
},
57+
{
58+
long: 'watch',
59+
description: 'watch for changes and reprocess',
60+
short: 'w',
61+
type: 'boolean',
62+
default: false
63+
},
64+
{
65+
long: 'quiet',
66+
description: 'output only warnings and errors',
67+
short: 'q',
68+
type: 'boolean',
69+
default: false
70+
},
71+
{
72+
long: 'silent',
73+
description: 'output only errors',
74+
short: 'S',
75+
type: 'boolean',
76+
default: false
77+
},
78+
{
79+
long: 'frail',
80+
description: 'exit with 1 on warnings',
81+
short: 'f',
82+
type: 'boolean',
83+
default: false
84+
},
85+
{
86+
long: 'tree',
87+
description: 'specify input and output as syntax tree',
88+
short: 't',
89+
type: 'boolean',
90+
default: false
91+
},
92+
{
93+
long: 'report',
94+
description: 'specify reporter',
95+
type: 'string',
96+
value: '<reporter>'
97+
},
98+
{
99+
long: 'file-path',
100+
description: 'specify path to process as',
101+
type: 'string',
102+
value: '<path>'
103+
},
104+
{
105+
long: 'ignore-path-resolve-from',
106+
description: 'resolve patterns in `ignore-path` from its directory or cwd',
107+
type: 'string',
108+
value: 'dir|cwd',
109+
default: 'dir'
110+
},
111+
{
112+
long: 'ignore-pattern',
113+
description: 'specify ignore patterns',
114+
type: 'string',
115+
value: '<globs>'
116+
},
117+
{
118+
long: 'silently-ignore',
119+
description: 'do not fail when given ignored files',
120+
type: 'boolean'
121+
},
122+
{
123+
long: 'tree-in',
124+
description: 'specify input as syntax tree',
125+
type: 'boolean'
126+
},
127+
{
128+
long: 'tree-out',
129+
description: 'output syntax tree',
130+
type: 'boolean'
131+
},
132+
{
133+
long: 'inspect',
134+
description: 'output formatted syntax tree',
135+
type: 'boolean'
136+
},
137+
{
138+
long: 'stdout',
139+
description: 'specify writing to stdout',
140+
type: 'boolean',
141+
truelike: true
142+
},
143+
{
144+
long: 'color',
145+
description: 'specify color in report',
146+
type: 'boolean',
147+
default: true
148+
},
149+
{
150+
long: 'config',
151+
description: 'search for configuration files',
152+
type: 'boolean',
153+
default: true
154+
},
155+
{
156+
long: 'ignore',
157+
description: 'search for ignore files',
158+
type: 'boolean',
159+
default: true
160+
}
161+
]

0 commit comments

Comments
 (0)