forked from syntaxhighlighter/syntaxhighlighter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
164 lines (137 loc) · 4.16 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
module.exports = (grunt) ->
fs = require 'fs'
grunt.loadNpmTasks 'grunt-contrib-uglify'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-karma'
grunt.loadNpmTasks 'grunt-browserify'
grunt.loadNpmTasks 'grunt-contrib-clean'
grunt.loadNpmTasks 'grunt-contrib-copy'
grunt.config.init
clean:
build: 'dist'
copy:
build:
src: 'index.html'
dest: 'dist/index.html'
brushes:
src: 'node_modules/brush-*/lib/brush-*.js'
dest: 'dist/brushes/'
flatten: true
expand: true
rename: (dest, src) ->
src = src.replace /-javascript/, '-jscript' # a minor exception
dest + src.replace /^brush-/, ''
themes:
src: 'node_modules/theme-*/css/theme-*.css'
dest: 'dist/css/'
flatten: true
expand: true
rename: (dest, src) -> dest + src.replace /^theme-/, ''
karma:
options: configFile: 'karma.conf.coffee'
background: background: true
single: singleRun: true
watch:
options: spawn: false
test:
tasks: ['karma:background:run']
files: [
'dist/**/*.*'
'test/**/*.spec.coffee'
]
js:
tasks: ['build:js', 'karma:background:run']
files: [
'src/**/*.js'
'../*/lib/*.js'
]
css:
tasks: ['copy:themes', 'karma:background:run']
files: ['../theme-*/css/*.css']
browserify:
core:
# files:
src: 'src/syntaxhighlighter.js'
dest: 'dist/syntaxhighlighter.js'
# 'dist/syntaxhighlighter.js': 'src/syntaxhighlighter.js'
uglify:
core:
files:
'dist/syntaxhighlighter.min.js': 'dist/syntaxhighlighter.js'
options:
banner: BANNER
# brushes:
# files: [
# expand: true,
# cwd: 'src/brushes',
# src: '**/*.js',
# dest: 'dist/brushes'
# ]
# options:
# banner: BANNER
grunt.registerTask 'jssize', ->
stats = fs.statSync "#{__dirname}/dist/syntaxhighlighter.min.js"
grunt.log.ok "syntaxhighlighter.min.js #{Math.round stats.size / 1024} KB".blue.bold
grunt.registerTask 'express', 'Launches basic HTTP server for tests', ->
express = require 'express'
staticMiddleware = require 'serve-static'
indexMiddleware = require 'serve-index'
done = @async()
app = express()
dir = "#{__dirname}/demos"
app.use staticMiddleware dir
app.use indexMiddleware dir
app.use '/dist', staticMiddleware "#{dir}/../dist"
app.use '/components', staticMiddleware "#{dir}/../components"
app.listen 3000
grunt.log.ok 'You can access tests on ' + 'http://localhost:3000'.blue + ' (Ctrl+C to stop)'
grunt.registerTask 'build:js', ['browserify', 'uglify', 'jssize']
grunt.registerTask 'build', ['clean', 'copy', 'build:js']
grunt.registerTask 'test', ['build', 'karma:single']
# grunt.registerTask 'inspect', ['express', 'watch']
grunt.registerTask 'dev', ['karma:background:start', 'watch']
TEST = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hello SyntaxHighlighter</title>
<script type="text/javascript" src="scripts/shCore.js"></script>
<script type="text/javascript" src="scripts/shBrushJScript.js"></script>
<link type="text/css" rel="stylesheet" href="styles/shCoreDefault.css">
<script type="text/javascript">SyntaxHighlighter.all();</script>
<style type="text/css">
body {
background: white;
font-family: helvetica;
}
</style>
</head>
<body>
<h1>Hello SyntaxHighlighter</h1>
<pre class="brush: js;">
function helloSyntaxHighlighter()
{
return "hi!";
}
</pre>
</html>
"""
BANNER = """
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* <%= version %> (<%= date %>)
*
* @copyright
* Copyright (C) 2004-2013 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
"""