Permalink
Browse files

1. take code to ingest command line arguments out of the bash library.

2. interpolate data into the bash library when building.
  • Loading branch information...
1 parent 54e74cc commit 3faf245f05862745bfeb3a760387ac59222d4ceb @JamieMason committed Nov 5, 2013
Showing with 172 additions and 84 deletions.
  1. +47 −0 bin/imageOptim
  2. +46 −41 bin/imageOptimBashLib
  3. +47 −0 src/imageOptim
  4. +0 −38 src/imageOptimBashLib
  5. +32 −5 tasks/environment.js
View
@@ -1,9 +1,56 @@
#!/bin/bash
+# ------------------------------------
+# LOCATE THIS SCRIPT
+# ------------------------------------
+
CLI_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+# ------------------------------------
+# IMPORT BASH LIBRARY
+# ------------------------------------
+
source "${CLI_PATH}/imageOptimBashLib"
# ------------------------------------
+# INGEST COMMAND LINE ARGUMENTS
+# ------------------------------------
+
+while [ "$1" != "" ]; do
+ case $1 in
+ -d | --directory )
+ shift;
+ DIRECTORY_OPTION="$1"
+ ;;
+ -a | --image-alpha )
+ USE_IMAGE_ALPHA="true"
+ ;;
+ -j | --jpeg-mini )
+ USE_JPEGMINI="true"
+ ;;
+ -q | --quit )
+ QUIT_ON_COMPLETE="true"
+ ;;
+ -h | --help )
+ usage;
+ exit 0
+ ;;
+ -e | --examples )
+ examples;
+ exit 0
+ ;;
+ -v | --version )
+ echo $VERSION;
+ exit 0
+ ;;
+ * )
+ usage
+ exit 1
+ esac
+ shift
+done
+
+# ------------------------------------
# POPULATE VARIABLES
# ------------------------------------
View
@@ -28,7 +28,7 @@
# ------------------------------------
# current version of ImageOptim-CLI from package.json
-VERSION="{{version}}"
+VERSION="1.6.23"
# {DirectoryPath} Absolute file system path to this shell script.
CLI_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
@@ -121,53 +121,58 @@ function success {
# Display usage information
function usage {
-{{usage}}
+ echo "Usage: imageOptim [options]"
+ echo ""
+ echo "Options:"
+ echo ""
+ echo " -d, --directory directory of images to process"
+ echo " -a, --image-alpha pre-process PNGs with ImageAlpha.app *"
+ echo " -j, --jpeg-mini pre-process JPGs with JPEGmini.app **"
+ echo " -q, --quit quit all apps when complete"
+ echo " -h, --help display this usage information"
+ echo " -e, --examples display some example commands and uses"
+ echo " -v, --version display the version number"
+ echo ""
+ echo "* http://pngmini.com"
+ echo "** https://itunes.apple.com/us/app/jpegmini/id498944723"
+ echo ""
}
# Display usage examples
function examples {
-{{examples}}
+ echo "### Optimise a directory of images"
+ echo ""
+ echo "This command will optimise all image files in your Awesome project."
+ echo ""
+ echo " imageOptim --directory ~/Sites/Awesome # [options]"
+ echo ""
+ echo "### Optimise a filtered set of images"
+ echo ""
+ echo "This command will optimise just the .jpg files in your Awesome project."
+ echo ""
+ echo " find ~/Sites/Awesome -name '*.jpg' | imageOptim # [options]"
+ echo ""
+ echo "### Passing additional options"
+ echo ""
+ echo "The long format for enabling options is as follows;"
+ echo ""
+ echo " imageOptim --jpeg-mini --image-alpha --quit --directory path/to/images"
+ echo ""
+ echo "The equivalent of the above in short format is as follows;"
+ echo ""
+ echo " imageOptim -j -a -q -d path/to/images"
+ echo ""
+ echo "### Adding to git pre-commit hook"
+ echo ""
+ echo "Adding the below to **your_project/.git/hooks/pre-commit** will run ImageOptim-CLI"
+ echo "each time you commit new and changed files into your project. Any files which"
+ echo "aren't images will be ignored."
+ echo ""
+ echo " git diff --cached --name-only --diff-filter=ACM | imageOptim # [options]"
+ echo ""
}
# ------------------------------------
-# INGEST COMMAND LINE ARGUMENTS
-# ------------------------------------
-
-while [ "$1" != "" ]; do
- case $1 in
- -d | --directory )
- shift;
- DIRECTORY_OPTION="$1"
- ;;
- -a | --image-alpha )
- USE_IMAGE_ALPHA="true"
- ;;
- -j | --jpeg-mini )
- USE_JPEGMINI="true"
- ;;
- -q | --quit )
- QUIT_ON_COMPLETE="true"
- ;;
- -h | --help )
- usage;
- exit 0
- ;;
- -e | --examples )
- examples;
- exit 0
- ;;
- -v | --version )
- echo $VERSION;
- exit 0
- ;;
- * )
- usage
- exit 1
- esac
- shift
-done
-
-# ------------------------------------
# DETERMINE WHAT EXISTS AT A GIVEN LOCATION
# ------------------------------------
View
@@ -1,9 +1,56 @@
#!/bin/bash
+# ------------------------------------
+# LOCATE THIS SCRIPT
+# ------------------------------------
+
CLI_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+# ------------------------------------
+# IMPORT BASH LIBRARY
+# ------------------------------------
+
source "${CLI_PATH}/imageOptimBashLib"
# ------------------------------------
+# INGEST COMMAND LINE ARGUMENTS
+# ------------------------------------
+
+while [ "$1" != "" ]; do
+ case $1 in
+ -d | --directory )
+ shift;
+ DIRECTORY_OPTION="$1"
+ ;;
+ -a | --image-alpha )
+ USE_IMAGE_ALPHA="true"
+ ;;
+ -j | --jpeg-mini )
+ USE_JPEGMINI="true"
+ ;;
+ -q | --quit )
+ QUIT_ON_COMPLETE="true"
+ ;;
+ -h | --help )
+ usage;
+ exit 0
+ ;;
+ -e | --examples )
+ examples;
+ exit 0
+ ;;
+ -v | --version )
+ echo $VERSION;
+ exit 0
+ ;;
+ * )
+ usage
+ exit 1
+ esac
+ shift
+done
+
+# ------------------------------------
# POPULATE VARIABLES
# ------------------------------------
View
@@ -130,44 +130,6 @@ function examples {
}
# ------------------------------------
-# INGEST COMMAND LINE ARGUMENTS
-# ------------------------------------
-
-while [ "$1" != "" ]; do
- case $1 in
- -d | --directory )
- shift;
- DIRECTORY_OPTION="$1"
- ;;
- -a | --image-alpha )
- USE_IMAGE_ALPHA="true"
- ;;
- -j | --jpeg-mini )
- USE_JPEGMINI="true"
- ;;
- -q | --quit )
- QUIT_ON_COMPLETE="true"
- ;;
- -h | --help )
- usage;
- exit 0
- ;;
- -e | --examples )
- examples;
- exit 0
- ;;
- -v | --version )
- echo $VERSION;
- exit 0
- ;;
- * )
- usage
- exit 1
- esac
- shift
-done
-
-# ------------------------------------
# DETERMINE WHAT EXISTS AT A GIVEN LOCATION
# ------------------------------------
View
@@ -47,6 +47,7 @@ module.exports = function(grunt) {
var paths = {
examples: 'src/examples.md',
imageOptim: 'bin/imageOptim',
+ imageOptimBashLib: 'bin/imageOptimBashLib',
imageOptimAppleScriptLib: 'bin/imageOptimAppleScriptLib',
npmMeta: 'package.json',
readme: 'README.md',
@@ -59,20 +60,46 @@ module.exports = function(grunt) {
data.version = require(paths.npmMeta).version;
+ // get usage template
readFile(paths.usage, function(usage) {
+
+ // format usage appropriately for the terminal
data.usage = usage.split('\n').map(lineToShellEcho).join('\n');
+
+ // get usage examples
readFile(paths.examples, function(examples) {
+
+ // format usage examples appropriately for the terminal
data.examples = examples.split('\n').map(lineToShellEcho).join('\n');
+
+ // interpolate data with the imageoptim-cli bash script
mergeObjectWithFile(paths.imageOptim, data, function() {
- mergeObjectWithFile(paths.imageOptimAppleScriptLib, data, function() {
- data.usage = usage.split('\n').map(lineToMarkdownCodeBlock).join('\n');
- data.examples = examples;
- mergeObjectWithFile(paths.readme, data, function() {
- done();
+
+ // interpolate data with the imageoptim-cli bash library
+ mergeObjectWithFile(paths.imageOptimBashLib, data, function() {
+
+ // interpolate data with the imageoptim-cli applescript library
+ mergeObjectWithFile(paths.imageOptimAppleScriptLib, data, function() {
+
+ // format usage appropriately for the readme
+ data.usage = usage.split('\n').map(lineToMarkdownCodeBlock).join('\n');
+
+ // take original example usage data which is appropriate for the readme
+ data.examples = examples;
+
+ // interpolate data with the readme
+ mergeObjectWithFile(paths.readme, data, function() {
+ done();
+ });
+
});
+
});
+
});
+
});
+
});
});

0 comments on commit 3faf245

Please sign in to comment.