Permalink
Browse files

replace design.io with grunt, run `grunt --config ./grunt.coffee`

  • Loading branch information...
1 parent baca9fe commit 8139ed85d4e25c7d26f3bc7ab36ff67fec1a4060 @lancejpollard lancejpollard committed Aug 21, 2012
Showing with 73 additions and 224 deletions.
  1. +0 −109 CHANGELOG.md
  2. +0 −102 Watchfile
  3. +71 −10 grunt.coffee
  4. +1 −2 package.json
  5. +1 −1 packages/tower-application/package.json
View
@@ -1,109 +0,0 @@
-- for developing tower src (`development` branch), make sure to install the branches of coffee-script and coffeecup we're working with:
- 1. turn off design.io
- 2. `npm install`
- 3. `npm install git://github.com/viatropos/coffeecup.git`
- 4. `npm install git://github.com/viatropos/coffee-script.git`
- 5. `npm install git://github.com/viatropos/neo4js.git`
- 5. `design.io watch`
- 6. `npm test`
-
-## Node 0.8.0 Setup
-
-### Globally
-
-```
-brew upgrade node
-node -v # should be >= 0.8.0
-curl http://npmjs.org/install.sh | sh
-npm -v # should be >= 1.1.32
-npm uninstall design.io forever tower daemon -g
-npm cache clean -g
-# npm install daemon -g
-npm install git://github.com/nodejitsu/forever#node-0.8 -g
-npm install design.io -g
-npm install tower -g
-```
-
-### Locally (in generated app)
-
-```
-tower new my-app
-cd my-app
-npm install git://github.com/nodejitsu/forever#node-0.8 # install this first
-npm install
-```
-
-If you have an existing app, uninstall tower and reinstall
-
-```
-npm uninstall tower design.io forever
-npm install git://github.com/nodejitsu/forever#node-0.8
-npm install design.io forever tower
-```
-
-### Playing around with the Tower source code
-
-Specifically the **dev branch** (excited)!
-
-```
-git clone https://github.com/viatropos/tower.git # or your fork
-cd tower
-git checkout -b development origin/development
-npm install git://github.com/nodejitsu/forever#node-0.8
-npm install
-npm link # makes it global so you can play around with it in any number of generated apps
-```
-
-Then generate an app and link it:
-
-```
-tower new my-app
-cd my-app
-npm link tower # now it's using the development branch of the cloned repo
-```
-
-If you change branches or change anything in your cloned tower repo, that exact same code will be used in your generated app (thanks to the symlink).
-
-### Deploying to Heroku
-
-Specify node and npm version: https://devcenter.heroku.com/articles/nodejs-versions/.
-
-Also, if you need to execute an NPM in a `postinstall` hook in package.json, you'll get `sh: npm not found` on Heroku. So, add `"npm": ">= 1.1.1"` to your package.json.
-
-Another random note. Tower has coffee-script and coffeecup modules installed in a `postinstall` script defined in package.json. If you add coffee-script to your app's package.json (pointing to the same custom coffee-script fork), it will install it twice and there's a weird error having something to do with `chmod` and permissions on `..../bin/coffee`, _on heroku only_, probably because it's trying to remove the `coffee` command from within coffeecup - since it's installing `coffee-script` again. Just add the regular `coffee-script` dependency in your package.json if you get this error.
-
-So do this:
-
-``` json
-{
- "name": "your-app",
- "engines": {
- "node": "0.8.0",
- "npm": ">= 1.1.1"
- },
- "dependencies": {
- "coffee-script": ">= 1.3.2",
- "tower": "git://github.com/viatropos/tower.git#development",
- "npm": ">= 1.1.1"
- }
-}
-```
-
-not this:
-
-``` json
-{
- "name": "your-app",
- "engines": {
- "node": "0.8.0",
- "npm": ">= 1.1.1"
- },
- "dependencies": {
- "coffee-script": "git://github.com/viatropos/coffee-script.git",
- "tower": "git://github.com/viatropos/tower.git#development",
- "npm": ">= 1.1.1"
- }
-}
-```
-
-Other notes... It takes forever to deploy a larger app on Heroku! Like 2-3 minutes. Wondering if there is a way to push small updates that only take a second or two...
View
@@ -1,102 +0,0 @@
-File = require('pathfinder').File
-
-require('design.io').extension('watchfile')
-
-async = require('async')
-File = require('pathfinder').File
-mint = require('mint')
-fs = require('fs')
-
-require("design.io-javascripts")
- compress: false
- debug: false
- ignore: /(lib\/|public|node_modules|server\.js|spec|test|dist|generators\/.+\/templates)/
- write: (path, string) ->
- path = path.replace(/^(packages)/, "lib").replace(/\.(js|coffee)/, ".js")
- try
- File.write path, string, (error) ->
- console.log(error.stack) if error
- catch error
- console.log error.stack
-
-watch /packages\/.+\/(generators\/.+\/templates|package\.json)/
- initialize: (path, callback) ->
- @update(path, callback)
-
- update: (path, callback) ->
- string = fs.readFileSync(path)
- path = path.replace(/^packages/, 'lib')
- try
- File.write path, string, (error) ->
- console.log(error.stack) if error
- callback()
- catch error
- console.log error.stack
- callback()
-
-require("design.io-javascripts") /test\/example\/.*\.coffee$/
- compress: false
- debug: false
- ignore: /(public|node_modules|view)/
- outputPath: (path) ->
- path = path.replace("test/example/", "")
- "test/example/public/javascripts/#{path}".replace(/\.(js|coffee)/, ".js")
-
-require("design.io-javascripts") /test\/cases\/.*\.coffee$/
- ignore: /(public|node_modules|server)/
- compress: false
- debug: false
- outputPath: (path) ->
- "test/example/public/javascripts/#{path}".replace(/\.(js|coffee)/, ".js")
-
-watch /test\/example\/app\/views.*\.coffee$/
- update: (path, callback) ->
- try
- nodes = path.replace("test/example/app/views/", "").split("/")
- name = {}
-
- data = File.read(path)
- id = nodes.join("/")
- selector = id
- name = ""
-
- @broadcast body: data, id: id, selector: selector, path: "/#{name}"
-
- files = File.files("test/example/app/views")
- result = []
-
- for file in files
- continue unless file.match(/\.coffee$/)
- result.push [file.replace("test/example/", ""), File.read(file)]
-
- template = "Tower.View.cache =\n"
-
- iterator = (item, next) =>
- template += " '#{item[0]}': ->\n"
- lines = item[1].split(/\n/)
- for line, i in lines
- lines[i] = " #{line}"
- template += lines.join("\n")
- template += "\n"
- next()
-
- require('async').forEachSeries result, iterator, (error) =>
- mint.coffee template, bare: true, (error, string) =>
- if error
- console.log error
- return callback(error)
- else
- File.write "test/example/public/javascripts/app/views/templates.js", string
- callback()
-
- catch error
- callback(error)
-
- client:
- update: (data) ->
- Tower.View.cache[data.id] = data
-
- if data.reload
- window.location = data.path
- else
- Tower.get data.path
View
@@ -7,28 +7,89 @@ module.exports = (grunt) ->
!i.match('templates')
grunt.initConfig
+ pkg: '<json:package.json>'
coffee:
app:
src: files
- dest: "tmp"
+ dest: 'lib'
+ strip: 'packages/'
options:
bare: true
- preserve_dirs: true
copy:
packageJSON:
src: 'packages/**/package.json'
- strip: 'packages'
- dest: "tmp"
+ strip: 'packages/'
+ dest: 'lib'
watch:
coffee:
- files: ["<config:coffee.app.src>"]
- tasks: ["coffee:app"]
+ files: ['<config:coffee.app.src>']
+ tasks: ['coffee:app']
packageJSON:
files: ['packages/**/package.json']
tasks: ['copy:package']
- grunt.loadNpmTasks "grunt-coffee"
- grunt.registerTask "default", "coffee"
- #grunt.registerTask "copy"
-
+ #grunt.loadNpmTasks 'grunt-coffee'
+ grunt.registerTask 'default', 'coffee copy'
+
+ # https://github.com/jquery/jquery-ui/blob/master/build/tasks/build.js
+ grunt.registerMultiTask 'copy', 'Copy files to destination folder and replace @VERSION with pkg.version', ->
+ replaceVersion = (source) ->
+ source.replace /@VERSION/g, grunt.config('pkg.version')
+
+ copyFile = (src, dest) ->
+ if /(js|css|json)$/.test(src)
+ grunt.file.copy src, dest,
+ process: replaceVersion
+ else
+ grunt.file.copy src, dest
+
+ files = grunt.file.expandFiles(@file.src)
+ target = @file.dest + '/'
+ strip = @data.strip
+ renameCount = 0
+ fileName = undefined
+ strip = new RegExp('^' + grunt.template.process(strip, grunt.config()).replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&')) if typeof strip is 'string'
+ files.forEach (fileName) ->
+ targetFile = (if strip then fileName.replace(strip, '') else fileName)
+ copyFile fileName, target + targetFile
+
+ grunt.log.writeln 'Copied ' + files.length + ' files.'
+ for fileName of @data.renames
+ renameCount += 1
+ copyFile fileName, target + grunt.template.process(@data.renames[fileName], grunt.config())
+ grunt.log.writeln 'Renamed ' + renameCount + ' files.' if renameCount
+
+ # https://github.com/avalade/grunt-coffee
+ path = require("path")
+ # CoffeeScript
+ grunt.registerMultiTask "coffee", "Compile CoffeeScript files", ->
+ dest = @file.dest + '/'
+ options = @data.options
+ strip = @data.strip
+ extension = @data.extension
+ strip = new RegExp('^' + grunt.template.process(strip, grunt.config()).replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&')) if typeof strip is 'string'
+ grunt.file.expandFiles(@file.src).forEach (filepath) ->
+ targetFile = dest + (if strip then filepath.replace(strip, '') else filepath)
+ grunt.helper "coffee", filepath, targetFile, grunt.utils._.clone(options), extension
+
+ if grunt.task.current.errorCount
+ false
+ else
+ true
+
+ grunt.registerHelper "coffee", (src, destPath, options, extension) ->
+ coffee = require("coffee-script")
+ js = ""
+ options = options or {}
+ extension = (if extension then extension else ".js")
+ dest = path.dirname(destPath) + '/' + path.basename(destPath, ".coffee") + extension
+ console.log dest
+ options.bare = true if options.bare isnt false
+ try
+ js = coffee.compile(grunt.file.read(src), options)
+ grunt.file.write dest, js
+ return true
+ catch e
+ grunt.log.error "Error in " + src + ":\n" + e
+ return false
View
@@ -100,8 +100,7 @@
"mustache": ">= 0.4.0",
"jade": ">= 0.22.0",
"kue": ">= 0.3.4",
- "socket.io-client": ">= 0.9.5",
- "design.io-javascripts": ">= 0.1.0"
+ "socket.io-client": ">= 0.9.5"
},
"optionalDependencies": {},
"scripts": {
@@ -1,6 +1,6 @@
{
"name": "tower-application",
- "version": "0.4.1",
+ "version": "@VERSION",
"homepage": "http://viatropos.github.com/tower",
"main": "./server.js",
"author": "Lance Pollard <lancejpollard@gmail.com>",

0 comments on commit 8139ed8

Please sign in to comment.