This repository has been archived by the owner on Sep 6, 2023. It is now read-only.
forked from ironchicken/MEItoVexFlow
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathGruntfile.js
169 lines (144 loc) · 4.84 KB
/
Gruntfile.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
module.exports = function (grunt) {
'use strict';
// Load plugins.
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-requirejs');
grunt.loadNpmTasks('grunt-closurecompiler');
grunt.loadNpmTasks('grunt-contrib-jasmine');
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
requirejs: {
compile: {
options: {
name: 'mei2vf/Interface',
baseUrl: "src",
mainConfigFile: "src/config.js",
out: 'dist/<%= pkg.name %>.js',
wrap: {
start: "(function($, VF, undefined) {",
end: "})(jQuery, Vex.Flow);"
},
exclude: [
'jquery',
'vex'
],
optimize: "none",
done: function (done, output) {
var duplicates = require('rjs-build-analysis').duplicates(output);
if (duplicates.length > 0) {
grunt.log.subhead('Duplicates found in requirejs build:');
grunt.log.warn(duplicates);
done(new Error('r.js built duplicate modules, please check the excludes option.'));
}
done();
},
// based on jQuery's convert function, see [https://github.com/jquery/jquery/blob/master/build/tasks/build.js]
onBuildWrite: function (name, path, contents) {
var rdefineEnd = /\}\);[^}\w]*$/;
var amdName;
// Convert var modules
if (/.\/var\//.test(path)) {
contents = contents
.replace(/define\([\w\W]*?return/, "var " + (/var\/([\w-]+)/.exec(name)[1]) + " =")
.replace(rdefineEnd, "");
} else {
// Ignore jQuery's exports (the only necessary one)
if (name !== "jquery") {
contents = contents
.replace(/\s*return\s+[^\}]+(\}\);[^\w\}]*)$/, "$1")
// Multiple exports
.replace(/\s*exports\.\w+\s*=\s*\w+;/g, "");
}
// Remove define wrappers, closure ends, and empty declarations
contents = contents
.replace(/define\([^{]*?{/, "")
.replace(rdefineEnd, "");
// Remove anything wrapped with
// /* ExcludeStart */ /* ExcludeEnd */
// or a single line directly after a // BuildExclude comment
contents = contents
.replace(/\/\*\s*ExcludeStart\s*\*\/[\w\W]*?\/\*\s*ExcludeEnd\s*\*\//ig, "")
.replace(/\/\/\s*BuildExclude\n\r?[\w\W]*?\n\r?/ig, "");
// Remove empty definitions
contents = contents
.replace(/define\(\[[^\]]+\]\)[\W\n]+$/, "");
}
return contents;
}
}
}
},
closurecompiler: {
minify: {
files: {
'dist/<%= pkg.name %>.min.js': ['dist/<%= pkg.name %>.js']
},
options: {
"compilation_level": "SIMPLE_OPTIMIZATIONS",
"max_processes": 5
}
}
},
connect: {
server: {
options: {
port: 8000
}
}
},
watch: {
scripts: {
files: ['src/*.js'],
tasks: ['compile'],
options: {
livereload: true
}
}
},
jasmine: {
testdev: {
src: 'src/*/*.js',
options: {
specs: 'tests/spec/*/*.js',
helpers: ['tests/loadXMLDoc.js', 'tests/phantomPolyFill.js'],
host: 'http://127.0.0.1:8000/',
template: require('grunt-template-jasmine-requirejs'),
options: {
keepRunner: true
},
templateOptions: {
requireConfig: {
baseUrl: 'src/',
paths: {
'tests': '../tests',
'jquery': '../bower_components/jquery/dist/jquery.min',
'vex': '../bower_components/vexflow/releases/vexflow-min',
'vexflow': '../src/mei2vf/vexflow',
'common': '../src/common',
'mei2vf': '../src/mei2vf',
'meilib': '../src/meilib'
},
shim: {
'vex': {
exports: 'Vex'
}
}
}
}
}
}
}
});
// Tasks.
grunt.registerTask('run', ['connect', 'watch']);
// unit and rendering tests of requirejs code in phantomJS
grunt.registerTask('test', ['connect', 'jasmine:testdev']);
grunt.registerTask('compile', ['requirejs:compile']);
grunt.registerTask('minify', ['closurecompiler:minify']);
grunt.registerTask('build', ['compile', 'minify']);
grunt.registerTask('dist', ['test', 'compile', 'minify']);
grunt.registerTask('default', ['dist']);
};