1
1
#!/usr/bin/env node
2
- 'use strict ';
3
- const meow = require ( 'meow' ) ;
4
- const findReadmeFile = require ( './lib/find-readme-file.js' ) ;
5
- const awesomeLint = require ( './index.js' ) ;
2
+ import process from 'node:process ';
3
+ import meow from 'meow' ;
4
+ import findReadmeFile from './lib/find-readme-file.js' ;
5
+ import awesomeLint from './index.js' ;
6
6
7
- const getReporter = name => {
8
- // Check if reporter is an npm package
7
+ const getReporter = async name => {
8
+ // Check if reporter is an npm package.
9
9
try {
10
- return require ( name ) . report ;
10
+ const { report} = await import ( name ) ;
11
+ return report ;
11
12
} catch ( error ) {
12
13
if ( error . code === 'MODULE_NOT_FOUND' ) {
13
14
console . error ( `No reporter found matching \`${ name } \`. Using default reporter (vfile-reporter-pretty).` ) ;
@@ -17,34 +18,31 @@ const getReporter = name => {
17
18
}
18
19
} ;
19
20
20
- const main = async ( ) => {
21
- const cli = meow ( `
22
- Usage
23
- $ awesome-lint [url|filename]
24
-
25
- Options
26
- --reporter, -r Use a custom reporter
27
- ` , {
28
- flags : {
29
- reporter : {
30
- type : 'string' ,
31
- alias : 'r'
32
- }
33
- }
34
- } ) ;
21
+ const cli = meow ( `
22
+ Usage
23
+ $ awesome-lint [url|filename]
35
24
36
- const input = cli . input [ 0 ] ;
25
+ Options
26
+ --reporter, -r Use a custom reporter
27
+ ` , {
28
+ importMeta : import . meta,
29
+ flags : {
30
+ reporter : {
31
+ type : 'string' ,
32
+ shortFlag : 'r' ,
33
+ } ,
34
+ } ,
35
+ } ) ;
37
36
38
- const options = { } ;
37
+ const input = cli . input [ 0 ] ;
39
38
40
- options . filename = input ? input : findReadmeFile ( process . cwd ( ) ) ;
39
+ const options = { } ;
41
40
42
- const reporterName = cli . flags . reporter ;
43
- if ( reporterName ) {
44
- options . reporter = getReporter ( reporterName ) ;
45
- }
41
+ options . filename = input ?? findReadmeFile ( process . cwd ( ) ) ;
46
42
47
- await awesomeLint . report ( options ) ;
48
- } ;
43
+ const reporterName = cli . flags . reporter ;
44
+ if ( reporterName ) {
45
+ options . reporter = await getReporter ( reporterName ) ;
46
+ }
49
47
50
- main ( ) ;
48
+ await awesomeLint . report ( options ) ;
0 commit comments