forked from hubotio/hubot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
creator.coffee
67 lines (56 loc) · 1.88 KB
/
creator.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Fs = require 'fs'
Path = require 'path'
# Simple generator class for deploying a version of hubot on heroku
class Creator
# Setup a ready to go version of hubot
#
# path - String directory to create/upgrade scripts for
constructor: (path) ->
@path = path
@templateDir = "#{__dirname}/templates"
@scriptsDir = "#{__dirname}/scripts"
# Create a folder if it doesn't already exist
#
# Throws an error if it fails
mkdirDashP: (path) ->
Path.exists path, (exists) ->
unless exists
Fs.mkdir path, 0755, (err) ->
throw err if err
# Copy the contents of a file from one place to another
#
# from - The source file to copy, must exist on disk
# to - The destination filename to write to
copy: (from, to) ->
Fs.readFile from, "utf8", (err, data) ->
console.log "Copying #{Path.resolve(from)} -> #{Path.resolve(to)}"
Fs.writeFileSync to, data, "utf8"
# Copy the default scripts hubot ships with to the scripts folder
# This allows people to easily remove scripts hubot defaults to if
# they want. It also provides them with a few examples and a top
# level scripts folder
#
# path - The destination
copyDefaultScripts: (path) ->
for file in Fs.readdirSync(@scriptsDir)
@copy "#{@scriptsDir}/#{file}", "#{path}/#{file}"
# Run the creator process
#
# Setup a ready to deploy folder that uses the hubot npm package
# Overwriting basic hubot files if they exist
run: ->
console.log "Creating a hubot install at #{@path}"
@mkdirDashP(@path)
@mkdirDashP("#{@path}/bin")
@mkdirDashP("#{@path}/scripts")
@copyDefaultScripts("#{@path}/scripts")
files = [
"Procfile",
"package.json",
"README.md",
".gitignore",
"bin/hubot",
"hubot-scripts.json"
]
@copy "#{@templateDir}/#{file}", "#{@path}/#{file}" for file in files
exports.Creator = Creator