Permalink
Browse files

pulled smooshing and cleaning of js and css into build.js and out of …

…app.js
  • Loading branch information...
trevorah committed Mar 3, 2013
1 parent 5e9b96f commit 4a09a2e0363ba0d8eebce63e0548ead467e6f343
Showing with 76 additions and 80 deletions.
  1. +0 −80 app.js
  2. +76 −0 build.js
View
80 app.js
@@ -8,7 +8,6 @@ var express = require('express')
, http = require('http')
, path = require('path')
, fs = require('fs')
- , walkdir = require('walkdir')
var app = express()
@@ -36,16 +35,6 @@ app.configure(function(){
app.locals.app_version = package.version
app.locals.env = process.env.NODE_ENV
app.locals.readme = fs.readFileSync( path.resolve(__dirname, './README.md'), 'utf-8')
-
- // Compress/concat files for deploy env...
- // Need to run this locally BEFORE deploying
- // to nodejitsu
- // $ NODE_ENV=predeploy node app
- if(app.locals.env === 'predeploy'){
- cleaner()
- setTimeout(smoosher,750)
- }
-
})
app.configure('development', function(){
@@ -112,72 +101,3 @@ http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'))
console.log("\nhttp://localhost:" + app.get('port') + "\n")
})
-
-/**
- Some helpers for deployment, cleaning up...
-**/
-
-// Pass in a path of a directory to walk and a
-// regex to match against. The file(s) matching
-// the patter will be deleted.
-function walkAndUnlink(dirPath, regex){
-
- var emitter = walkdir(dirPath)
-
- emitter.on('file',function(filename,stat){
- if( regex.test(filename) ){
- console.log("Removing old file: " + filename)
- fs.unlinkSync( path.resolve( dirPath, filename) )
- }
- })
-
-}
-
-// Removes old css/js files.
-function cleaner(){
-
- if(app.locals.env === 'predeploy'){
- walkAndUnlink( path.join(__dirname, 'public', 'css'), new RegExp(/style-/) )
- walkAndUnlink( path.join(__dirname, 'public', 'js'), new RegExp(/dependencies-/) )
- walkAndUnlink( path.join(__dirname, 'public', 'js'), new RegExp(/dillinger-/) )
- }
-}
-
-// Concats, minifies js and css for production
-function smoosher(){
-
- // Compress/concat files for deploy env...
- // Need to run this locally BEFORE deploying
- // to nodejitsu
- require('smoosh').make({
- "VERSION": app.locals.app_version,
- "JSHINT_OPTS": {
- "browser": true,
- "evil":true,
- "boss":true,
- "asi": true,
- "laxcomma": true,
- "expr": true,
- "lastsemic": true,
- "laxbreak":true,
- "regexdash": true,
- },
- "JAVASCRIPT": {
- "DIST_DIR": "./public/js",
- "dependencies": [ { "src": "./public/js/bootstrap.js", "jshint": false},
- { "src": "./public/js/ace.js", "jshint": false},
- { "src": "./public/js/mode-markdown.js", "jshint": false},
- { "src": "./public/js/showdown.js", "jshint": false},
- { "src": "./public/js/keymaster.js", "jshint": false}],
- "dillinger": [ "./public/js/dillinger.js" ]
- },
- "CSS": {
- "DIST_DIR": "./public/css",
- "style": [ "./public/css/style.css" ]
- }
- })
- .done(function(){
- console.log('\nSmoosh all finished...\n')
- })
-
-}
View
@@ -0,0 +1,76 @@
+// Compress/concat files for deploy env...
+// Need to run this locally BEFORE deploying
+// to nodejitsu
+
+var walkdir = require('walkdir')
+ , path = require('path')
+ , fs = require('fs')
+
+/**
+ Some helpers for deployment, cleaning up...
+**/
+
+// Pass in a path of a directory to walk and a
+// regex to match against. The file(s) matching
+// the patter will be deleted.
+function walkAndUnlink(dirPath, regex){
+
+ var emitter = walkdir(dirPath)
+
+ emitter.on('file',function(filename,stat){
+ if( regex.test(filename) ){
+ console.log("Removing old file: " + filename)
+ fs.unlinkSync( path.resolve( dirPath, filename) )
+ }
+ })
+
+}
+
+// Removes old css/js files.
+function cleaner(){
+ walkAndUnlink( path.join(__dirname, 'public', 'css'), new RegExp(/style-/) )
+ walkAndUnlink( path.join(__dirname, 'public', 'js'), new RegExp(/dependencies-/) )
+ walkAndUnlink( path.join(__dirname, 'public', 'js'), new RegExp(/dillinger-/) )
+}
+
+// Concats, minifies js and css for production
+function smoosher(){
+
+ // Compress/concat files for deploy env...
+ // Need to run this locally BEFORE deploying
+ // to nodejitsu
+ require('smoosh').make({
+ "VERSION": require('./package.json').version,
+ "JSHINT_OPTS": {
+ "browser": true,
+ "evil":true,
+ "boss":true,
+ "asi": true,
+ "laxcomma": true,
+ "expr": true,
+ "lastsemic": true,
+ "laxbreak":true,
+ "regexdash": true,
+ },
+ "JAVASCRIPT": {
+ "DIST_DIR": "./public/js",
+ "dependencies": [ { "src": "./public/js/bootstrap.js", "jshint": false},
+ { "src": "./public/js/ace.js", "jshint": false},
+ { "src": "./public/js/mode-markdown.js", "jshint": false},
+ { "src": "./public/js/showdown.js", "jshint": false},
+ { "src": "./public/js/keymaster.js", "jshint": false}],
+ "dillinger": [ "./public/js/dillinger.js" ]
+ },
+ "CSS": {
+ "DIST_DIR": "./public/css",
+ "style": [ "./public/css/style.css" ]
+ }
+ })
+ .done(function(){
+ console.log('\nSmoosh all finished...\n')
+ })
+
+}
+
+cleaner()
+setTimeout(smoosher,750)

0 comments on commit 4a09a2e

Please sign in to comment.