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' ;
2024-02-28 16:26:52 +02:00
import { fileExtension } from '@joplin/utils/path' ;
const supportedExtensions = [ 'ts' , 'tsx' , 'md' , 'mdx' ] ;
2022-05-05 17:34:52 +02:00
const main = async ( ) = > {
const argv = await yargs . argv ;
2024-02-28 16:26:52 +02:00
let filePaths = ( argv . _ as string [ ] ) || [ ] ;
2024-02-26 12:16:23 +02:00
const processAll = ! ! argv . all ;
2024-02-28 16:26:52 +02:00
filePaths = filePaths . filter ( f = > supportedExtensions . includes ( fileExtension ( f ) . toLowerCase ( ) ) ) ;
if ( ! processAll && ! 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-28 16:26:52 +02:00
cmd . push ( ` **/*.{ ${ supportedExtensions . join ( ',' ) } } ` ) ;
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 ) ;
} ) ;