-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaginator.coffee
77 lines (66 loc) · 2.07 KB
/
taginator.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
67
68
69
70
71
72
73
74
75
76
77
# dependencies
express = require 'express'
fs = require 'fs'
path = require 'path'
exec = require('child_process').exec
optimist = require 'optimist'
_ = require 'lodash'
helper = require './lib/helper'
Project = require './lib/Project'
require 'consoleplusplus'
# vars
projects = null
configs = null
configFile = '/.taginator.json'
github = 'http://github.com/hoschi/taginator'
errors = []
warnings = []
# setup options
argv = optimist
.usage( "This app creates vim 'tags' files for your projects in the background.\n
Read the readme file at #{github} for more information.")
.default('domain', 'localhost')
.describe('domain', "Set the domain this app should list to.")
.default('port', 3000)
.argv
console.log optimist.help()
console.info "Starting application, open http://#{argv.domain}:#{argv.port}/ in your browser."
# configure express
app = express()
app.configure ->
# this doesn't work after publishing with npm :(
app.set 'view', __dirname + '/views'
app.set 'view engine', 'jade'
app.use express.bodyParser()
app.use express.methodOverride()
app.use app.router
app.use '/public', express.static(__dirname + '/public')
##################################################################
# process configured projects
##################################################################
# load configs from
try
configs = JSON.parse(
fs.readFileSync(
path.normalize(helper.getUserHome() + configFile), 'utf8'))
catch error
errors.push error.toString()
if !_.isArray configs
errors.push "Parsed config files don't contain an array!"
# create notifies for dirs in projects
if errors.length
console.error errors
else
projects = (new Project(config).setUp(errors, warnings) for config in configs)
# define routes
app.get '/', (req, res) ->
# fix for issue above :(
res.render __dirname + '/views/index',
title: 'Taginator'
configFile: configFile
projects: projects
errors: errors
warnings: warnings
github: github
# start server
app.listen argv.port, argv.domain