11#!/usr/bin/env node
22
3- import * as fs from 'fs/promises'
3+ import { readFile } from 'node:fs/promises'
4+ import { parseArgs } from 'node:util'
5+ import type { ParseArgsConfig } from 'node:util'
46import { parse } from '@formatjs/icu-messageformat-parser'
57import type { ParserError } from '@formatjs/icu-messageformat-parser/error'
68import { globby } from 'globby'
79import { importFromString } from 'module-from-string'
810
9- const args = process . argv . slice ( 2 )
10- const pattern = args [ 0 ]
11+ const options : ParseArgsConfig [ 'options' ] = {
12+ ignoreTag : {
13+ type : 'boolean' ,
14+ short : 'i' ,
15+ default : false ,
16+ } ,
17+ }
18+
19+ const { values, positionals } = parseArgs ( { options, allowPositionals : true } )
20+
21+ const pattern = positionals [ 0 ]
1122
1223type Locales = Record < string , string >
1324type ErrorICU = {
@@ -29,7 +40,10 @@ const findICUErrors = (
2940 const errors = Object . entries ( locales )
3041 . map ( ( [ key , value ] ) => {
3142 try {
32- parse ( value )
43+ parse ( value , {
44+ // Need to cast as node doesn't allow generic to parseArgs
45+ ignoreTag : values [ 'ignoreTag' ] as boolean ,
46+ } )
3347
3448 return undefined
3549 } catch ( err ) {
@@ -57,7 +71,7 @@ const readFiles = async (files: string[]): Promise<ErrorsICU> => {
5771
5872 if ( extension === 'json' ) {
5973 try {
60- const data = await fs . readFile ( file )
74+ const data = await readFile ( file )
6175 const jsonFile = data . toString ( )
6276
6377 const locales = JSON . parse ( jsonFile ) as Locales
@@ -71,7 +85,7 @@ const readFiles = async (files: string[]): Promise<ErrorsICU> => {
7185
7286 if ( extension === 'ts' || extension === 'js' ) {
7387 try {
74- const data = await fs . readFile ( file )
88+ const data = await readFile ( file )
7589 const javascriptFile = data . toString ( )
7690
7791 const mod : unknown = await importFromString ( javascriptFile , {
0 commit comments