File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const fs = require ( 'fs' ) ;
2+ const filename = process . argv [ 2 ] ;
3+ if ( ! filename ) {
4+ console . error ( "Please specify filename" ) ;
5+ process . exit ( 1 ) ;
6+ }
7+ const text = fs . readFileSync ( filename , 'utf-8' ) ;
8+ const known = { }
9+ const output = text
10+ . split ( '\n' )
11+ . map ( l => {
12+ if ( l . startsWith ( '#' ) ) return l ;
13+ const [ lhs , rhs ] = l . split ( '=' ) . map ( w => w . trim ( ) ) ;
14+ if ( lhs ) {
15+ const previous = known [ lhs ] ;
16+ if ( rhs === previous ) return "" ;
17+ if ( previous !== undefined ) {
18+ console . warn ( `Caution: More than one mapping detected. Dropping earlier one` )
19+ console . warn ( `${ lhs } =${ previous } ` )
20+ console . warn ( `${ lhs } =${ rhs } ` )
21+ }
22+ known [ lhs ] = rhs ;
23+ return `${ lhs } =${ rhs ?? "" } `
24+ } else {
25+ return l ;
26+ }
27+ } )
28+ . filter ( l => l !== "" )
29+ . join ( '\n' )
30+
31+ if ( process . argv [ 3 ] === "--overwrite" ) {
32+ fs . writeFileSync ( filename , output ) ;
33+ } else {
34+ console . log ( output ) ;
35+ }
36+
You can’t perform that action at this time.
0 commit comments