/
s3-deployer.coffee
47 lines (37 loc) · 1.06 KB
/
s3-deployer.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
fs = require 'fs'
knox = require 'knox'
client = knox.createClient
key: process.env.S3KEY
secret: process.env.S3SECRET
bucket: 'www.devpathchicago.com'
deploy = {}
module.exports = deploy
deploy.dir = (path) ->
@read path, (err, paths) =>
if err then throw err
@upload paths
deploy.read = (dir, cb) ->
results = []
fs.readdir dir, (err, list) ->
if err then return cb err
i = 0
do next = ->
file = list[i++]
if !file then return cb null, results
file = "#{dir}/#{file}"
fs.stat file, (err, stat) ->
if stat and stat.isDirectory()
deploy.read file, (err, res) ->
results = results.concat res
next()
else
results.push file
next()
deploy.upload = (paths) ->
paths.forEach (path) ->
splitFileName = path.split '/'
fileName = splitFileName[splitFileName.length - 1]
client.putFile path, "/#{fileName}", (err, res) ->
console.log 'error putting', path, "/#{fileName}"
if err then throw err
console.log "Deployed #{path}"