Skip to content

Instantly share code, notes, and snippets.

@shukerullah
Last active September 5, 2020 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shukerullah/1eff264f820f08291952e5403479dc41 to your computer and use it in GitHub Desktop.
Save shukerullah/1eff264f820f08291952e5403479dc41 to your computer and use it in GitHub Desktop.
Adding @flow to the top of Javascript multiple files
#!/bin/bash
# Based on http://stackoverflow.com/questions/151677/tool-for-adding-license-headers-to-source-files
for i in src/*.js src/*/*.js src/*/*/*.js src/*/*/*/*.js src/*/*/*/*/*.js
do
if ! grep -q @flow $i
then
(echo -e $"/**\n * @format\n * @flow\n */\n") > flowificator
cat flowificator $i >$i.new && mv $i.new $i
rm flowificator
fi
done

This shell script will add @format and @flow to the top of all .js files that are inside src folder. Keep this shell file at the root of your project

Make a file executable in Terminal on Mac

Shell scripts must be executable files in order to run. You can use the chmod command to indicate that the text file is executable.

  1. In the Terminal app on your Mac. Enter the chmod command. For example:
chmod 755 YourScriptName.sh
  1. After making the shell script file executable, you can run it by entering its pathname. For example:
./YourScriptName.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment