Permalink
Browse files

inital import

  • Loading branch information...
0 parents commit b18d2addd74dc173f66a614a60802808356c8b00 @andrzejsliwa committed Oct 7, 2010
Showing with 178 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +35 −0 Makefile
  3. +38 −0 README.markdown
  4. +92 −0 lib/coffeeapp.coffee
  5. +12 −0 package.json
@@ -0,0 +1 @@
+.DS_Store
@@ -0,0 +1,35 @@
+#
+# CoffeeApp - coffee-script wrapper for CouchApp
+# Copyright 2010 Andrzej Sliwa (andrzej.sliwa@i-tool.eu)
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+.PHONY: all build install clean uninstall
+
+all: build
+
+build:
+ @echo 'CoffeeApp built.'
+
+install:
+ @cp ./lib/coffeeapp.coffee /usr/local/bin/coffeeapp && \
+ chmod 755 /usr/local/bin/coffeeapp && \
+ echo 'CoffeeApp installed.'
+
+clean:
+ @true
+
+uninstall:
+ @rm -f /usr/local/bin/coffeeapp && \
+ echo 'CoffeeApp uninstalled.'
@@ -0,0 +1,38 @@
+### CoffeeApp -- coffee-script wrapper for CouchApp
+
+### Installing
+
+Prerequisites: CoffeeScript requires Node.js (<http://nodejs.org/>), Npm (http://npmjs.org/)
+
+Get CoffeeApp:
+
+ git clone git://github.com/andrzejsliwa/coffeeapp.git
+
+Build Jake:
+
+ cd coffeeapp && make && sudo make install
+
+### Installing with [npm](http://npmjs.org/)
+
+ npm install coffeeapp
+
+Or, get the code, and `npm link` in the code root.
+
+### Basic usage
+
+ coffeeapp [couchapp options]
+
+
+### Description
+
+ CoffeeApp is a simple wrapper for couchapp command.
+ CoffeeApp overide normal push behavoir, by adding .releases directory which contain deployment snapshots
+ While files are copied to release snapshot... coffee-script files (.coffee) are converted on the fly to
+ java-script (.js) files.
+
+ .releases directory should be added to .gitignore or .hgignore or whatever you have using to prevent versioning.
+
+
+### Author
+
+Andrzej Sliwa, andrzej.sliwa@i-tool.eu
@@ -0,0 +1,92 @@
+#!/usr/bin/env coffee
+#
+# CoffeeApp - coffee-script wrapper for CouchApp
+# Copyright 2010 Andrzej Sliwa (andrzej.sliwa@i-tool.eu)
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+exist = require('path').existsSync
+joinPath = require('path').join
+extName = require('path').extname
+mkDir = require('fs').mkdirSync
+readDir = require('fs').readdirSync
+writeFile = require('fs').writeFileSync
+readFile = require('fs').readFileSync
+getStats = require('fs').statSync
+coffeeCompile = require('coffee-script').compile
+exec = require('child_process').exec
+
+padTwo = (number) ->
+ result = if number < 10 then '0' else ''
+ result + String(number)
+
+
+getTimestamp = ->
+ date = new Date()
+ date.getFullYear() +
+ padTwo(date.getMonth() + 1) +
+ padTwo(date.getDate()) +
+ padTwo(date.getHours() + 1) +
+ padTwo(date.getMinutes() + 1) +
+ padTwo(date.getSeconds() + 1)
+
+processRecursive = (currentDir, destination) ->
+ fileList = readDir(currentDir)
+ for fileName in fileList
+ filePath = joinPath(currentDir, fileName)
+ destFilePath = joinPath(destination, filePath)
+ if getStats(filePath).isDirectory()
+ unless fileName[0] == '.'
+ mkDir(destFilePath, 0700)
+ processRecursive(filePath, destination)
+ else
+ if extName(filePath) == '.coffee'
+ console.log('processing ' + filePath + '...')
+ writeFile(destFilePath.replace(/\.coffee$/, '.js'),
+ coffeeCompile(readFile(filePath, encoding = 'utf8'), noWrap: yes).replace(/^\(/,'').replace(/\);$/, ''), encoding = 'utf8')
+ else
+ writeFile(destFilePath, readFile(filePath, encoding = 'utf8'), encoding = 'utf8')
+
+grindCoffee = ->
+ releasesDir = '.releases'
+ unless exist(releasesDir)
+ console.log 'initialize ' + releasesDir + ' directory'
+ mkDir(releasesDir, 0700)
+ releasePath = joinPath(releasesDir, getTimestamp())
+ mkDir(releasePath, 0700)
+ processRecursive('.', releasePath)
+ process.chdir(releasePath)
+ exec('couchapp push', (error, stdout, stderr) ->
+ console.log(stdout)
+ console.log(stderr)
+ if (error != null)
+ console.log('exec error: ' + error)
+ )
+ process.cwd()
+
+
+if 'push' in process.argv
+ grindCoffee()
+else
+ options = ''
+ for opt in process.argv
+ options += " " + opt
+
+ exec('couchapp' + options, (error, stdout, stderr) ->
+ console.log(stdout)
+ console.log(stderr)
+ if (error != null)
+ console.log('exec error: ' + error)
+ )
+
@@ -0,0 +1,12 @@
+{ "name" : "coffeeapp"
+, "version" : "0.0.1"
+, "author" : "Andrzej Sliwa <andrzej.sliwa@i-tool.eu> (http://andrzejsliwa.com)"
+, "main" : "./lib/coffeeapp.coffee"
+, "bin" : { "coffeeapp" : "./lib/coffeeapp.coffee" }
+, "dependencies": { "coffee-script" : "0.9.4" }
+, "repository": {
+ "type": "git",
+ "url": "git://github.com/andrzejsliwa/coffeeapp.git"
+ },
+
+}

0 comments on commit b18d2ad

Please sign in to comment.