forked from 0xfe/vexflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
201 lines (190 loc) · 5.21 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
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
200
201
const path = require('path');
module.exports = (grunt) => {
const BANNER = [
'/**',
' * VexFlow <%= pkg.version %> built on <%= grunt.template.today("yyyy-mm-dd") %>.',
' * Copyright (c) 2010 Mohit Muthanna Cheppudira <[email protected]>',
' *',
' * http://www.vexflow.com http://github.com/0xfe/vexflow',
' */',
].join('\n');
const BASE_DIR = __dirname;
const BUILD_DIR = path.join(BASE_DIR, 'build');
const RELEASE_DIR = path.join(BASE_DIR, 'releases');
const MODULE_ENTRY = path.join(BASE_DIR, 'src/index.js');
const TARGET_RAW = path.join(BUILD_DIR, 'vexflow-debug.js');
const TARGET_MIN = path.join(BUILD_DIR, 'vexflow-min.js');
const TARGET_TESTS = path.join(BUILD_DIR, 'vexflow-tests.js');
const SOURCES = ['src/*.js', '!src/header.js', '!src/container.js'];
const TEST_SOURCES = [
'tests/vexflow_test_helpers.js',
'tests/mocks.js',
'tests/*_tests.js',
'tests/run.js',
];
function webpackConfig(target, preset) {
return {
entry: MODULE_ENTRY,
output: {
path: '/',
filename: target,
library: 'Vex',
libraryTarget: 'umd',
},
devtool: 'source-map',
module: {
loaders: [
{
test: /\.js?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: [preset],
'plugins': ['add-module-exports', 'transform-object-assign'],
},
},
],
},
};
}
const webpackCommon = webpackConfig(TARGET_RAW, 'es2015');
// Unsupported build for IE versions <11
const TARGET_LEGACY_RAW = path.join(BUILD_DIR, 'vexflow-legacy-debug.js');
const TARGET_LEGACY_MIN = path.join(BUILD_DIR, 'vexflow-legacy-min.js');
const webpackLegacy = webpackConfig(TARGET_LEGACY_RAW, 'es2015-loose');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
banner: BANNER,
sourceMap: true,
},
tests: {
src: TEST_SOURCES,
dest: TARGET_TESTS,
},
},
webpack: {
build: webpackCommon,
buildLegacy: webpackLegacy,
watch: Object.assign({}, webpackCommon, {
watch: true,
keepalive: true,
failOnError: false,
watchDelay: 0,
}),
},
uglify: {
options: {
banner: BANNER,
sourceMap: true,
},
build: {
src: TARGET_RAW,
dest: TARGET_MIN,
},
buildLegacy: {
src: TARGET_LEGACY_RAW,
dest: TARGET_LEGACY_MIN,
},
},
eslint: {
target: SOURCES,
options: {
configFile: '.eslintrc.json',
},
},
qunit: {
files: ['tests/flow.html'],
},
watch: {
tests: {
files: ['tests/*'],
tasks: ['concat:tests'],
options: {
interrupt: true,
},
},
},
copy: {
release: {
files: [
{
expand: true,
dest: RELEASE_DIR,
cwd: BUILD_DIR,
src: ['*.js', 'docs/**', '*.map'],
},
],
},
},
docco: {
src: SOURCES,
options: {
layout: 'linear',
output: 'build/docs',
},
},
gitcommit: {
releases: {
options: {
message: 'Committing release binaries for new version: <%= pkg.version %>',
verbose: true,
},
files: [
{
src: [`${RELEASE_DIR}/*.js`, `${RELEASE_DIR}/*.map`],
expand: true,
},
],
},
},
bump: {
options: {
files: ['package.json', 'component.json'],
commitFiles: ['package.json', 'component.json'],
updateConfigs: ['pkg'],
createTag: false,
push: false,
},
},
release: {
options: {
bump: false,
commit: false,
},
},
clean: [BUILD_DIR],
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-docco');
grunt.loadNpmTasks('grunt-release');
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-git');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-webpack');
// Default task(s).
grunt.registerTask('default', ['eslint', 'webpack:build', 'concat', 'uglify:build', 'docco']);
grunt.registerTask('buildLegacy', ['webpack:buildLegacy', 'uglify:buildLegacy']);
grunt.registerTask('test', 'Run qunit tests.', ['webpack:build', 'concat', 'qunit']);
// Release current build.
grunt.registerTask('stage', 'Stage current binaries to releases/.', () => {
grunt.task.run('default');
grunt.task.run('buildLegacy');
grunt.task.run('qunit');
grunt.task.run('copy:release');
});
// Increment package version and publish to NPM.
grunt.registerTask('publish', 'Publish VexFlow NPM.', () => {
grunt.task.run('bump');
grunt.task.run('stage');
grunt.task.run('gitcommit:releases');
grunt.task.run('release');
});
};