Last active
April 8, 2016 12:38
-
-
Save MitMaro/0ee2134e480a844c074bdc44678d58f6 to your computer and use it in GitHub Desktop.
Covert JSON to Node module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| SCRIPTROOT="$( cd "$(dirname "$0")" ; pwd -P )" | |
| for f in "$@"; do | |
| NEWFILE="${f:0:${#f} - 4}js" | |
| gsed -f "$SCRIPTROOT/jsonToModule.script" "$f" > "$NEWFILE" | |
| rm "$f" | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # remove quotes around most identifiers | |
| s/"\([a-zA-Z0-9_]*\)":/\1:/ | |
| # escape existing single quotes | |
| s/'/\\'/g | |
| # replace double quotes with single | |
| s/"/'/g | |
| # Add module loader | |
| 1s/^/'use strict';\n\nmodule.exports = / | |
| # add trailing semicolon | |
| $s/\(.*\)/\1;/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment