-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.coffee
88 lines (66 loc) · 2.29 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
# vim: tabstop=2 shiftwidth=2
module.exports = (grunt) ->
# Project configuration.
grunt.initConfig
pkg:
grunt.file.readJSON 'package.json'
coffee:
compile:
files:
'built/quine.js': 'src/coffee/quine.coffee' # 1:1 compile
cssmin:
target:
files:
'built/style.css': 'src/style.css'
uglify:
options:
maxLineLen: 80 # UglifyJS2 doesn't honor this; modified npm module.
files:
src: [
'lib/codemirror/lib/codemirror.js',
'lib/codemirror/addon/fold/foldcode.js',
'lib/codemirror/addon/fold/foldgutter.js',
'lib/codemirror/addon/fold/indent-fold.js',
'built/quine.js'
]
dest: 'built/quine.js'
inline:
options:
tag: ''
files:
src: 'src/quine.html',
dest: 'built/quine.html'
finish:
files:
src: 'built/quine.html'
dest: 'built/quine.html'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-cssmin'
grunt.loadNpmTasks 'grunt-contrib-uglify'
grunt.loadNpmTasks 'grunt-inline'
grunt.registerMultiTask 'finish', 'Ensure clean taskpaper formatting.', () ->
@.files.forEach (filePair) ->
# Check that the source file exists
if filePair.src.length is 0 then return
value = grunt.file.read filePair.src
metadataRE = /^Metadata:[\s\S]*$/m
metadata = value.match(metadataRE)[0]
# Remove unformatted Metadata: project
value = value.replace metadataRE, ''
lines = metadata.split '\n'
htmlStart = lines.length - 1
while htmlStart > 0 and not /^<!doctype/.test lines[htmlStart]
htmlStart--
# Restore project name and any notes; newlines intact
value += lines[0...htmlStart].join '\n'
# Compress html lines to single line
value += "\n #{lines[htmlStart..].join ''}"
# Append vim modeline to end of Metadata project
lines = value.split '\n'
modeline = lines[0]
value = value.slice 1
value = "#{lines[1..].join '\n'}\n\n#{modeline}"
grunt.file.write filePair.dest, value
# Default task(s).
grunt.registerTask 'default', ['coffee', 'cssmin', 'uglify', 'inline', 'finish']
grunt.registerTask 'nofinish', ['coffee', 'cssmin', 'uglify', 'inline']