@@ -18,10 +18,15 @@ const argv = yargs(process.argv.slice(2))
1818 "$0 [paths..]" ,
1919 "Remove `compat_features` from `.yml` files that have an equivalently tagged set of features in @mdn/browser-compat-data" ,
2020 ( yargs ) =>
21- yargs . positional ( "paths" , {
22- describe : "Directories or files to check/update." ,
23- default : [ "features" ] ,
24- } ) ,
21+ yargs
22+ . positional ( "paths" , {
23+ describe : "Directories or files to check/update." ,
24+ default : [ "features" ] ,
25+ } )
26+ . option ( "f" , {
27+ alias : "force" ,
28+ type : "boolean" ,
29+ } ) ,
2530 ) . argv ;
2631
2732const logger = winston . createLogger ( {
@@ -53,7 +58,9 @@ const tagsToFeatures: Map<string, Feature[]> = (() => {
5358 return map ;
5459} ) ( ) ;
5560
56- function cleanup ( sourcePath : string ) : void {
61+ function cleanup ( sourcePath : string , options ?: { force ?: boolean } ) : void {
62+ options = { ...options } ;
63+
5764 const source = YAML . parseDocument (
5865 fs . readFileSync ( sourcePath , { encoding : "utf-8" } ) ,
5966 ) ;
@@ -72,7 +79,7 @@ function cleanup(sourcePath: string): void {
7279 if ( compat_features ) {
7380 const { key : keyData , value : data } = compat_features ;
7481 const features = data . items . map ( ( item ) => item . value ) . sort ( ) ;
75- if ( isDeepStrictEqual ( features , taggedCompatFeatures ) ) {
82+ if ( options . force || isDeepStrictEqual ( features , taggedCompatFeatures ) ) {
7683 // Preserve comments around the compat_features key
7784 const comments = keyData . commentBefore ? [ keyData . commentBefore ] : [ ] ;
7885 data . items . reduce ( ( acc , item ) => {
@@ -107,7 +114,7 @@ function main() {
107114 } ) ;
108115
109116 for ( const sourcePath of filePaths ) {
110- cleanup ( sourcePath ) ;
117+ cleanup ( sourcePath , { force : argv . force } ) ;
111118 }
112119}
113120
0 commit comments