-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
198 lines (148 loc) · 5.8 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
188
189
190
191
192
193
194
195
196
197
module.exports = (grunt)->
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-contrib-less'
grunt.loadNpmTasks 'grunt-contrib-concat'
grunt.loadNpmTasks 'grunt-contrib-copy'
grunt.loadNpmTasks 'node-srv'
readline = require 'readline'
path = require 'path'
fs = require 'fs'
grunt.initConfig
coffee:
app:
files: [
expand: true
cwd: 'dist/coffee/'
src: ['**/*.coffee']
dest: 'dist/js'
ext: '.js'
]
marker:
files: [
expand: true
cwd: 'marker_core/'
src: ['*.coffee']
dest: 'marker_core/'
ext: '.js'
]
jade:
pages:
cwd: 'dist/pages/'
src: '*.jade'
dest: 'build/'
ext: '.html'
options:
pretty: true
less:
compile:
files:
"build/global.css": "dist/less/global.less"
concat:
production:
separator: '\n'
src: ['dist/js/libs/jquery.js', 'dist/js/libs/rangy-core.js', 'dist/js/libs/rangy-selectionsaverestore.js', 'dist/js/libs/underscore.js', 'dist/js/libs/backbone.js', 'dist/js/words.js', 'dist/js/analytics.js', 'dist/js/app.js']
dest: 'build/global.js'
copy:
dictionaries:
src: 'dictionaries/*.json'
dest: 'build/'
static:
expand: true
cwd: 'dist/static/'
src: '**/*'
dest: 'build/'
filter: 'isFile'
affToJson:
cwd: 'dictionaries/'
src: 'ru_RU.aff'
dest: 'dictionaries/'
ext: '.json'
dicToJson:
cwd: 'dictionaries/'
src: 'ru_RU.dic'
dest: 'dictionaries/'
ext: '.json'
srv:
server:
port: 8000
root: 'build'
index: 'index.html'
404: 'build/404.html'
watch:
coffee:
files: ['dist/coffee/**/*.coffee']
tasks: ['coffee:app']
marker:
files: ['marker_core/marker.coffee']
tasks: ['coffee:marker']
jade:
files: ['dist/pages/*.jade']
tasks: ['jade']
less:
files: ['dist/less/*.less']
tasks: ['less:compile']
concat:
files: ['dist/**/*.js']
tasks: ['concat:production']
grunt.registerTask 'default', 'watch'
grunt.registerTask 'build', ['processDictionaries', 'coffee', 'jade', 'less', 'concat', 'copy']
grunt.registerMultiTask 'jade', 'Compile jade to HTML', ->
jade = require 'pug'
for file in this.filesSrc
filepath = path.join(@data.cwd, file)
try
compiled = jade.compile grunt.file.read(filepath), grunt.util._.extend({filename: filepath}, @data.options or {})
html = compiled.call @, @data.extraData or {}
filename = path.basename file, path.extname file
savePath = path.join @data.dest, filename+(@data.ext or '.html')
grunt.file.write savePath, html
grunt.log.ok "Rendered \"#{filepath}\" at #{grunt.template.today()}"
catch e
grunt.log.error "Jade render error: #{e}"
grunt.registerTask 'processDictionaries', ['affToJson', 'dicToJson']
grunt.registerTask 'affToJson', 'Processing OpenOffice affix file to JSON', ->
done = @async()
data = grunt.config.get('affToJson')
stream = fs.createReadStream path.join data.cwd, data.src
stream.on 'end', ->
#console.log(affixObject)
fs.writeFileSync path.join(data.dest, data.src+data.ext), JSON.stringify(affixObject, null, ' ')
done true
affixObject = {}
rd = readline.createInterface
input: stream,
output: process.stdout,
terminal: false
rd.on 'line', (line)->
unless line == ''
lineArray = line.split(' ')
return if lineArray[2] == 'Y'
lineArray.shift()
lineIndex = lineArray.shift()
affixObject[lineIndex] = {} unless affixObject[lineIndex]?
lineString = lineArray.shift()
affixObject[lineIndex][lineString] = [] unless affixObject[lineIndex][lineString]?
affixObject[lineIndex][lineString].push lineArray
grunt.registerTask 'dicToJson', 'Processing OpenOffice dictionary file to JSON', ->
done = @async()
data = grunt.config.get('dicToJson')
stream = fs.createReadStream path.join data.cwd, data.src
stream.on 'end', ->
#console.log(affixObject)
fs.writeFileSync path.join(data.dest, data.src+data.ext), JSON.stringify(dicObject, null, ' ')
done true
dicObject = {}
rd = readline.createInterface
input: stream,
output: process.stdout,
terminal: false
rd.on 'line', (line)->
unless line == ''
lineArray = line.split('/')
lineIndex = lineArray.shift()
dicObject[lineIndex] = {} unless dicObject[lineIndex]?
if lineArray.length == 0
dicObject[lineIndex] = null
return false
dicObject[lineIndex] = lineArray[0]