2022-05-05 17:34:52 +02:00
import yargs = require ( 'yargs' ) ;
import { chdir } from 'process' ;
2023-03-19 17:37:07 +02:00
import { rootDir } from './tool-utils' ;
import { execCommand } from '@joplin/utils' ;
2022-05-05 17:34:52 +02:00
const main = async ( ) = > {
const argv = await yargs . argv ;
const filePaths = argv . _ as string [ ] ;
2024-02-26 12:16:23 +02:00
const processAll = ! ! argv . all ;
2024-02-26 18:53:48 +02:00
if ( ! processAll ) {
if ( ! filePaths || ! filePaths . length ) return ;
}
2022-05-05 17:34:52 +02:00
chdir ( rootDir ) ;
2024-02-26 18:53:48 +02:00
let cmd = [
'yarn' , 'cspell' ,
'--no-progress' ,
'--no-summary' ,
'--config' , 'cspell.json' ,
] ;
2024-02-26 12:16:23 +02:00
if ( processAll ) {
2024-02-26 18:53:48 +02:00
cmd . push ( '**/*.{ts,tsx,md,mdx}' ) ;
2024-02-26 12:16:23 +02:00
} else {
cmd = cmd . concat ( filePaths ) ;
}
2022-05-05 17:34:52 +02:00
try {
2024-02-26 12:16:23 +02:00
await execCommand ( cmd , { showStderr : false , showStdout : false } ) ;
2022-05-05 17:34:52 +02:00
} catch ( error ) {
2022-05-06 11:37:39 +02:00
if ( ! error . stdout . trim ( ) ) return ;
2024-02-27 16:22:26 +02:00
console . error ( ` The following spelling mistakes were found. Please check https://joplinapp.org/help/dev/spellcheck for \ ninformation on how to deal with spelling mistakes. \ n \ n ${ error . stdout } ` ) ;
2022-05-05 17:34:52 +02:00
process . exit ( 1 ) ;
}
} ;
main ( ) . catch ( ( error ) = > {
console . error ( 'Fatal error' ) ;
console . error ( error ) ;
process . exit ( 1 ) ;
} ) ;