forked from OscarGodson/EpicEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJakefile.js
199 lines (173 loc) · 6.33 KB
/
Jakefile.js
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
198
199
var fs = require('fs')
, path = require('path')
, VERSION = fs.readFileSync(path.join(process.cwd() + '/VERSION'), 'utf-8')
function concat(fileList, destPath) {
var out = fileList.map(function (filePath) {
var file = fs.readFileSync(filePath, 'utf-8')
file = file.replace(/@VERSION/g, VERSION)
return file
})
fs.writeFileSync(destPath, out.join('\n'))
}
function colorize(str, color) {
var colors =
{ 'blue': '34m'
, 'cyan': '36m'
, 'green': '01;32m'
, 'magenta': '35m'
, 'red': '31m'
, 'yellow': '33m'
}
return colors[color] ? '\033[' + colors[color] + str + '\033[39m' : str
}
desc('Lint all js files')
task('lint', [], function () {
jake.Task['lint:all'].invoke();
}, {async: true})
namespace('lint', function () {
var cwd = process.cwd()
, jakefile = path.join(cwd + '/Jakefile.js')
, jshintrc = path.join(cwd + '/.jshintrc')
, editor = path.join(cwd + '/src/editor.js')
, spec = path.join(cwd + '/spec/spec.js')
, docs = path.join(cwd + '/docs/js/main.js')
task('all', ['lint:editor', 'lint:docs', 'lint:spec', 'lint:util'], function () {
complete()
}, {async: true})
desc('Lint core EpicEditor: src/editor.js')
task('editor', [], function () {
console.log(colorize('--> Linting editor', 'yellow'))
var cwd = process.cwd()
, files = [ editor ]
, cmds = ['jshint ' + files.join(' ') + ' --config .jshintrc']
jake.exec(cmds, function () {
console.log(colorize(' √ ok', 'green'))
complete()
}, {stdout: true})
}, {async: true})
desc('Lint doc related js: docs/js/main.js')
task('docs', [], function () {
console.log(colorize('--> Linting docs', 'yellow'))
var cwd = process.cwd()
, files = [ docs ]
, cmds = ['jshint ' + files.join(' ') + ' --config .jshintrc']
jake.exec(cmds, function () {
console.log(colorize(' √ ok', 'green'))
complete()
}, {stdout: true})
}, {async: true})
desc('Lint test related js: spec/spec.js')
task('spec', [], function () {
console.log(colorize('--> Linting specs', 'yellow'))
var cwd = process.cwd()
, files = [ spec ]
, cmds = ['jshint ' + files.join(' ') + ' --config .jshintrc']
jake.exec(cmds, function () {
console.log(colorize(' √ ok', 'green'))
complete()
}, {stdout: true})
}, {async: true})
desc('Lint utility and config js files')
task('util', [], function () {
console.log(colorize('--> Linting utils', 'yellow'))
var cwd = process.cwd()
, files = [ jshintrc, jakefile ]
, cmds = ['jshint ' + files.join(' ') + ' --config .jshintrc --extra-ext .jshintrc']
jake.exec(cmds, function () {
console.log(colorize(' √ ok', 'green'))
complete()
}, {stdout: true})
}, {async: true})
})
desc('Build epiceditor.js and minify to epiceditor.min.js')
task('build', ['build:init', 'lint:editor'], function () {
console.log(colorize('--> Building', 'yellow'))
var destDir = path.join(process.cwd() + '/epiceditor/js/')
, srcDir = path.join(process.cwd() + '/src/')
, parser = process.env.parser ? process.env.parser : srcDir + 'marked/lib/marked.js'
, srcPaths =
[ srcDir + 'editor.js'
, parser
]
, destPath = destDir + 'epiceditor.js'
, destPathMin = destDir + 'epiceditor.min.js'
, cmds = ['uglifyjs ' + destPath + ' > ' + destPathMin]
// If the destination directory does not exist, create it
jake.mkdirP('epiceditor/js')
if (!path.existsSync(parser)) {
fail("Parser path not found.")
}
concat(srcPaths, destPath)
// Minify
jake.exec(cmds, function () {
console.log(colorize(' √ ok', 'green'))
complete()
}, {stdout: true})
}, {async: true})
namespace('build', function () {
desc('Force build epiceditor.js and epiceditor.min.js skipping pre-reqs')
task('force', [], function () {
console.log(colorize('--> Warning: Force build skips build pre-reqs. This build should not be commited.', 'magenta'))
jake.Task['build'].execute()
})
task('init', [], function () {
jake.exec(['git submodule update --init'], function () {
complete();
}, {stdout: true})
}, {async: true})
})
desc('Build index.html from the README')
task('docs', ['lint:docs'], function () {
console.log(colorize('--> Building docs', 'yellow'))
var destDir = path.join(process.cwd() + '/')
, srcDir = path.join(process.cwd() + '/docs/')
, readmePath = destDir + 'README.md'
, tempPath = srcDir + 'README.html'
, destPath = destDir + 'index.html'
, srcPaths =
[ srcDir + 'header.html'
, tempPath
, srcDir + 'footer.html'
]
, cmds = ['marked -o ' + tempPath + ' -i ' + readmePath + ' --gfm']
jake.exec(cmds, function () {
concat(srcPaths, destPath)
// remove temporary README.html
fs.unlink(tempPath)
console.log(colorize(' √ ok', 'green'))
complete()
}, {stdout: true})
}, {async: true})
desc('Test code against specs')
task('test', ['lint:spec'], function () {
console.log(colorize('--> Test suite is now running (CTRL+C to quit)', 'magenta'))
console.log(colorize('--> http://localhost:5057/spec/runner.html', 'yellow'))
jake.exec(['foounit serve'], function () {
complete()
}, {stdout: false})
}, {async: true})
var pkg = new jake.PackageTask('EpicEditor', 'v' + VERSION, function () {
var fileList = [ 'epiceditor']
this.packageDir = "docs/downloads"
this.packageFiles.include(fileList);
this.needZip = true;
})
desc('Kick out some ascii')
task('ascii', [], function () {
var epicAscii = "" +
" \n" +
" ', \n" +
" .eee. .' \n" +
" .eeEEEEEe. \n" +
" EEEEEEEEEEEE' .E' `eEE' .EEEEEEEEEEE \n" +
" EE .E' eEE` .E EE \n" +
" EE .E' eEE` EE EE \n" +
" EE .E' eEE` EE \n" +
" EE .E' eEE` EEEEEEEEEE \n" +
" EE eEE` EE \n" +
" EE . `eE` EE \n" +
" EE Ee' EE EE \n" +
" EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE \n"
console.log(colorize(epicAscii, 'yellow'))
console.log(colorize('EpicEditor - An Embeddable JavaScript Markdown Editor', 'yellow'))
})