forked from joosy/joosy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.coffee
187 lines (159 loc) · 5.63 KB
/
Gruntfile.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
module.exports = (grunt) ->
Sugar = require 'sugar'
Mincer = require 'mincer'
FS = require 'fs'
#
# Locations
#
locations =
source:
root: 'joosy.coffee'
path: 'source'
build: 'build/joosy.js'
extensions: (name) ->
root: "joosy/extensions/#{name}"
build: "build/joosy/extensions/#{name}.js"
specs:
units:
environments: 'spec/joosy/environments/*_spec.*'
core: 'spec/joosy/core/**/*_spec.*'
extensions: 'spec/joosy/extensions/**/*_spec.*'
helpers: 'spec/helpers/**/*.*'
build: '.grunt'
specOptions = (category, specs, vendor=[]) ->
host: 'http://localhost:8888/'
keepRunner: true
outfile: "spec/#{category}.html"
vendor: [
'bower_components/sinonjs/sinon.js',
'bower_components/sugar/release/sugar-full.min.js'
].concat(vendor),
specs: "#{locations.specs.build}/#{specs}"
helpers: locations.specs.build + '/' + locations.specs.helpers
#
# Grunt extensions
#
grunt.loadNpmTasks 'grunt-contrib-connect'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-jasmine'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-coffeelint'
grunt.loadNpmTasks 'grunt-release'
grunt.initConfig
release:
options:
bump: false
add: false
commit: false
push: false
connect:
specs:
options:
port: 8888
watch:
source:
files: [locations.source.path + '/**/*']
tasks: ['mince']
specs:
options:
nospawn: true
files: [ locations.specs.helpers ].add(Object.values locations.specs.units)
tasks: ['coffee']
coffee:
specs:
expand: true
src: [ locations.specs.helpers ].add(Object.values locations.specs.units)
dest: locations.specs.build
ext: '.js'
mince:
core:
include: [locations.source.path]
src: locations.source.root
dest: locations.source.build
preloaders:
include: [locations.source.path]
src: locations.source.extensions('preloaders').root
dest: locations.source.extensions('preloaders').build
resources:
include: [locations.source.path]
src: locations.source.extensions('resources').root
dest: locations.source.extensions('resources').build
form:
include: [locations.source.path]
src: locations.source.extensions('resources-form').root
dest: locations.source.extensions('resources-form').build
coffeelint:
source:
files:
src: [locations.source.path + '/joosy/**/*.coffee']
options:
'max_line_length':
level: 'ignore'
jasmine:
core:
options: specOptions('core', locations.specs.units.core, [
'bower_components/jquery/jquery.js'
])
src: locations.source.build
zepto:
options: specOptions('zepto', locations.specs.units.core, [
'bower_components/zepto/zepto.js'
])
src: locations.source.build
'environments-global':
options: specOptions('environments-global', ['spec/joosy/environments/global*'], [
'bower_components/jquery/jquery.js'
])
src: locations.source.build
'environments-amd':
options: specOptions('environments-amd', ['spec/joosy/environments/amd*'], [
'bower_components/jquery/jquery.js',
'bower_components/requirejs/require.js'
])
src: locations.source.build
extensions:
options: specOptions('extensions', locations.specs.units.extensions, [
'bower_components/jquery/jquery.js',
'bower_components/jquery-form/jquery.form.js'
])
src: [locations.source.build].include ['preloaders', 'resources', 'resources-form'].map (x) ->
locations.source.extensions(x).build
#
# Tasks
#
grunt.registerMultiTask 'mince', ->
Mincer.CoffeeEngine.configure bare: false
environment = new Mincer.Environment
environment.appendPath x for x in @data.include
grunt.file.write @data.dest, environment.findAsset(@data.src).toString()
grunt.registerTask 'default', ['connect', 'build', 'watch']
grunt.registerTask 'build', ['mince', 'coffee', 'jasmine:core:build', 'jasmine:extensions:build', 'bowerize']
grunt.registerTask 'test', ['connect', 'mince', 'coffee', 'bowerize', 'jasmine']
grunt.registerTask 'bowerize', ->
bower = require './bower.json'
meta = require './package.json'
bower.version = meta.version
FS.writeFileSync 'bower.json', JSON.stringify(bower, null, 2)
grunt.registerTask 'publish:ensureCommits', ->
complete = @async()
grunt.util.spawn {cmd: "git", args: ["status", "--porcelain" ]}, (error, result) ->
if !!error || result.stdout.length > 0
console.log ""
console.log "Uncommited changes found. Please commit prior to release or use `--force`.".bold
console.log ""
complete false
else
complete true
grunt.registerTask 'publish:gem', ->
meta = require './package.json'
complete = @async()
grunt.util.spawn {cmd: "gem", args: ["build", "joosy.gemspec"]}, (error, result) ->
return complete false if error
gem = "joosy-#{meta.version.replace('-', '.')}.gem"
grunt.log.ok "Built #{gem}"
grunt.util.spawn {cmd: "gem", args: ["push", gem]}, (error, result) ->
return complete false if error
grunt.log.ok "Published #{gem}"
grunt.file.delete gem
complete(true)
grunt.registerTask 'publish', ['test', 'publish:ensureCommits', 'release', 'publish:gem']