Skip to content

Instantly share code, notes, and snippets.

@psealock
Created September 5, 2017 22:08
Show Gist options
  • Save psealock/ffa6fc914af5213e769463bf20de1227 to your computer and use it in GitHub Desktop.
Save psealock/ffa6fc914af5213e769463bf20de1227 to your computer and use it in GitHub Desktop.
/** @format */
var fs = require( 'fs' );
function replaceLine( file ) {
fs.readFile( file, 'utf8', function( err, data ) {
if ( err ) {
return console.log( err );
}
var result = data.replace(
/import PropTypes from 'prop-types';\n\n(?=import)/g,
"import PropTypes from 'prop-types';\n"
);
fs.writeFile( file, result, 'utf8', function( err ) {
if ( err ) return console.log( err );
} );
} );
}
replaceLine( process.argv[ 2 ] );
#!/bin/bash
# Initialize from the provided arguments
TARGET="${1:?No target supplied. Please provide a target directory or file.}"
FILES=$(find $TARGET -type f -name '*.jsx' -o -name '*.js')
for filename in $FILES; do
echo "Processing $filename"
node proptypes-extra-line.js $filename
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment