Skip to content

Commit

Permalink
Added minifying tool and some scripts to help with development.
Browse files Browse the repository at this point in the history
  • Loading branch information
icub3d committed Feb 7, 2013
1 parent d065cc6 commit d7a1fb3
Show file tree
Hide file tree
Showing 23 changed files with 231 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,6 +6,7 @@
# Folders
_obj
_test
prod

# Architecture specific extensions/prefixes
*.[568vq]
Expand Down
36 changes: 0 additions & 36 deletions app.yaml

This file was deleted.

1 change: 1 addition & 0 deletions app.yaml
65 changes: 65 additions & 0 deletions build
@@ -0,0 +1,65 @@
#!/bin/bash

# Delete any files in prod
if [ -d "prod" ]; then
rm -rf "prod"
fi

# Make the prod diretory if it doesn't exist.
[ ! -d "prod" ] && mkdir prod

# Use the closure tool to build all.min.js
closure \
`find dev -name "*.js" | xargs -n1 echo -n ' --js'` \
--compilation_level SIMPLE_OPTIMIZATIONS \
--warning_level QUIET \
--js_output_file prod/all.min.js

# Use yuicompressor to minify css.
find dev -name "*.css" | xargs cat | \
yuicompressor \
--type css >prod/all.min.css

# Write out the view files as templates within the HTML page.
css=false
css_out=false
js=false
js_out=false
cat dev/index.html | while read LINE; do
case "$LINE" in
*\<!--\ APP\ CSS\ --\>*)
if ! $css_out; then
echo -n '<link rel="stylesheet" href="/all.min.css">'
css_out=true
fi
if $css; then css=false; else css=true; fi
;;
*\<!--\ APP\ JS\ --\>*)
if ! $js_out; then
echo -n '<script src="/all.min.js"></script>'
js_out=true
fi
if $js; then js=false; else js=true; fi
;;
*\<!--\ EMBED\ HERE\ --\>*)
for FILE in `find dev -name "*.html" -not -name "index.html"`; do
BFILE=`basename $FILE`
echo -n "<script type=\"text/ng-template\" id=\"$BFILE\">"
htmlcompressor $FILE
echo -n "</script>"
done
;;

*)
if $js; then continue; fi
if $css; then continue; fi
echo "$LINE"
;;
esac
done | htmlcompressor > prod/index.html

# Save favicon if it exists.
[ -f "dev/favicon.ico" ] && cp -af dev/favicon.ico prod

# We need to copy the img dir over.
[ -d "dev/img" ] && cp -af dev/img prod/img
36 changes: 36 additions & 0 deletions dev.yaml
@@ -0,0 +1,36 @@
application: lists-themarshians-com
version: 1
runtime: go
api_version: go1

handlers:
- url: /rest/.*
script: _go_app
login: required
auth_fail_action: unauthorized

- url: /
static_files: dev/index.html
upload: dev/index.html
login: required
mime_type: text/html; charset=utf-8

- url: /(.*\.css)
mime_type: text/css; charset=utf-8
static_files: dev/\1
upload: dev/(.*\.css)

- url: /(.*\.html)
mime_type: text/html; charset=utf-8
static_files: dev/\1
upload: dev/(.*\.html)

- url: /(.*\.ico)
mime_type: image/x-icon; charset=utf-8
static_files: dev/\1
upload: dev/(.*\.ico)

- url: /(.*\.js)
mime_type: text/javascript; charset=utf-8
static_files: dev/\1
upload: dev/(.*\.js)
64 changes: 64 additions & 0 deletions dev/build
@@ -0,0 +1,64 @@
#!/bin/bash

# Delete any files in prod
if [ -d "prod" ]; then
rm -rf "prod"
fi

# Make the prod diretory if it doesn't exist.
[ ! -d "prod" ] && mkdir prod

# Use the closure tool to build all.min.js
closure \
`find public -name "*.js" | xargs -n1 echo -n ' --js'` \
--compilation_level SIMPLE_OPTIMIZATIONS \
--warning_level QUIET \
--js_output_file prod/all.js

# Use yuicompressor to minify css.
find public -name "*.css" | xargs cat | \
yuicompressor \
--type css >prod/all.css

# Write out the view files as templates within the HTML page.
css=false
css_out=false
js=false
js_out=false
cat public/index.html | while read LINE; do
case "$LINE" in
*\<!--\ APP\ CSS\ --\>*)
if ! $css_out; then
echo -n '<link rel="stylesheet" href="/all.min.css">'
css_out=true
fi
if $css; then css=false; else css=true; fi
;;
*\<!--\ APP\ JS\ --\>*)
if ! $js_out; then
echo -n '<script src="/all.min.js"></script>'
js_out=true
fi
if $js; then js=false; else js=true; fi
;;
*\<!--\ EMBED\ HERE\ --\>*)
for FILE in `find public -name "*.html" -not -name "index.html"`; do
echo -n "<script type=\"text/ng-template\" id=\"$FILE\">"
htmlcompressor $FILE
echo -n "</script>"
done
;;

*)
if $js; then continue; fi
if $css; then continue; fi
echo "$LINE"
;;
esac
done | htmlcompressor > prod/index.html

# Save favicon if it exists.
[ -f "public/favicon.ico" ] && cp -af public/favicon.ico prod

# We need to copy the img dir over.
[ -d "public/img" ] && cp -af public/img prod/img
File renamed without changes.
File renamed without changes.
12 changes: 9 additions & 3 deletions public/index.html → dev/index.html
Expand Up @@ -19,24 +19,30 @@

<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap.min.css"
rel="stylesheet">

<!-- APP CSS -->
<link href="/css/main.css" rel="stylesheet">
<!-- APP CSS -->

<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-responsive.min.css"
rel="stylesheet">

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>

<!-- APP JS -->
<script src="/js/rest.js"></script>
<script src="/js/routing.js"></script>
<script src="/js/alerts.js"></script>
<script src="/js/user.js"></script>
<script src="/js/lists.js"></script>
<script src="/js/view.js"></script>
<script src="/js/date.js"></script>
<script src="/js/touch-punch.min.js"></script>
<!-- APP JS -->

<!-- we can async these because they aren't required on initial load. -->
<script async src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>
<script async src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script>
<script async src="/js/date.js"></script>
<script async src="/js/touch-punch.min.js"></script>
</head>
<body>
<div class="container">
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion public/js/user.js → dev/js/user.js
Expand Up @@ -11,4 +11,4 @@ function UserCtrl($scope, User) {
$scope.user = data;
});
}
UserCtrl.$inject['$scope', 'User'];
UserCtrl.$inject = ['$scope', 'User'];
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions gae
@@ -0,0 +1,5 @@
#!/bin/bash

IPADDR=`ip addr | grep -o "10\.84\.7\.[0-9]*" | head -n1`

$APPENGINE_SDK/dev_appserver.py --use_sqlite --high_replication -a $IPADDR $@
36 changes: 36 additions & 0 deletions prod.yaml
@@ -0,0 +1,36 @@
application: lists-themarshians-com
version: 1
runtime: go
api_version: go1

handlers:
- url: /rest/.*
script: _go_app
login: required
auth_fail_action: unauthorized

- url: /
static_files: prod/index.html
upload: prod/index.html
login: required
mime_type: text/html; charset=utf-8

- url: /(.*\.css)
mime_type: text/css; charset=utf-8
static_files: prod/\1
upload: prod/(.*\.css)

- url: /(.*\.html)
mime_type: text/html; charset=utf-8
static_files: prod/\1
upload: prod/(.*\.html)

- url: /(.*\.ico)
mime_type: image/x-icon; charset=utf-8
static_files: prod/\1
upload: prod/(.*\.ico)

- url: /(.*\.js)
mime_type: text/javascript; charset=utf-8
static_files: prod/\1
upload: prod/(.*\.js)
5 changes: 5 additions & 0 deletions publish
@@ -0,0 +1,5 @@
#!/bin/bash

./yprod

$APPENGINE_SDK/appcfg.py $@
4 changes: 4 additions & 0 deletions ydev
@@ -0,0 +1,4 @@
#!/bin/bash

[ -h app.yaml ] && unlink app.yaml
ln -s dev.yaml app.yaml
4 changes: 4 additions & 0 deletions yprod
@@ -0,0 +1,4 @@
#!/bin/bash

[ -h app.yaml ] && unlink app.yaml
ln -s prod.yaml app.yaml

0 comments on commit d7a1fb3

Please sign in to comment.