/
grunt.coffee
117 lines (102 loc) · 3.53 KB
/
grunt.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# https://github.com/cowboy/grunt/blob/master/docs/task_init.md
module.exports = (grunt) ->
file = grunt.file
grunt.loadNpmTasks('grunt-contrib-less')
grunt.loadNpmTasks('grunt-contrib-stylus')
require('tower').Application.instance().initialize
databases: ['memory']
defaultDatabase: 'memory'
# @todo grunt.loadNpmTasks('tower-tasks')
require(require('path').join(Tower.srcRoot, 'lib/tower-tasks/tasks'))(grunt)
grunt.registerMultiTask 'wiki', 'Compile wiki for towerjs.org', ->
markdown = require('github-flavored-markdown')
wikiRoot = Tower.join(Tower.srcRoot, 'wiki')
docs = file.expand(Tower.join(wikiRoot, 'en/docs/**/*.md'))
guides = file.expand(Tower.join(wikiRoot, 'en/guides/**/*.md'))
cheatSheets = file.expand(Tower.join(wikiRoot, 'en/cheat-sheets/**/*.md'))
renderMarkdown = (doc) ->
filePath = Tower.join(Tower.root, 'public/docs', Tower.basename(doc, '.md') + '.html')
Tower.writeFileSync(filePath, markdown.parse(Tower.readFileSync(doc, 'utf-8')))
docs.forEach(renderMarkdown)
guides.forEach(renderMarkdown)
cheatSheets.forEach(renderMarkdown)
# script files
scriptPaths = file.expand([
'app/!(templates)/**/*.coffee'
'test/**/*.coffee'
'config/shared/locales/**/*.coffee'
'config/server/locales/**/*.coffee'
'config/shared/application.coffee'
'config/server/application.coffee'
'config/shared/routes.coffee'
'config/server/routes.coffee'
'config/shared/assets.coffee'
'config/shared/assets.coffee'
])
# vendor script files
vendorScriptPaths = file.expand([
'vendor/javascripts/**/*.js'
])
config =
pkg: '<json:package.json>'
coffee:
all:
src: scriptPaths
dest: 'public/javascripts'
options:
bare: false
less:
bootstrap:
src: 'vendor/stylesheets/bootstrap/bootstrap.less'
dest: 'public/stylesheets/vendor/stylesheets/bootstrap/bootstrap.css'
watch:
stylus:
files: ['app/stylesheets/client/application.styl']
tasks: ['stylus']
copy:
javascripts:
src: ['vendor/**/*.js']
dest: 'public/javascripts'
stylesheets:
src: ['vendor/**/*.css']
dest: 'public/stylesheets'
images:
src: ['vendor/**/*.{png,gif,jpg}']
dest: 'public/images'
api:
src: [Tower.join(Tower.srcRoot, 'doc/**/*')]
strip: "#{Tower.srcRoot}/doc#{Tower.pathSeparator}"
dest: 'public/api'
wiki:
compile: {}
templates:
compile: {}
stylus:
compile:
options:
#'include css': true
'paths': ['app/client/stylesheets']
files:
'public/stylesheets/app/stylesheets/client/application.css': 'app/stylesheets/client/application.styl'
# @todo if you `npm link tower` to this app, then it should
# copy the dist/tower.js to vendor/javascripts/tower.js when it changes.
scriptPaths.forEach (name) ->
config.coffee[name] =
src: name
dest: 'public/javascripts'
options:
bare: true
config.watch[name] =
files: [name]
tasks: ["coffee:#{name}"]
vendorScriptPaths.forEach (name) ->
config.copy[name] =
src: [name]
dest: 'public/javascripts'
config.watch[name] =
files: [name]
tasks: ["copy:#{name}"]
grunt.initConfig(config)
grunt.registerTask 'copy:assets', 'copy:api copy:stylesheets copy:javascripts copy:images'
grunt.registerTask 'default', 'copy:assets wiki coffee:all less stylus templates'
grunt.registerTask 'start', 'default watch'