-
Notifications
You must be signed in to change notification settings - Fork 13
/
Gruntfile.js
167 lines (159 loc) · 4.78 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
const path = require('path');
const webpack = require('webpack');
const webpackCfg = require('./webpack.config.js');
const jsdocCfg = require('./.jsdoc.json');
module.exports = (grunt) => {
const BANNER = [
'/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */',
].join('\n');
const BASE_DIR = __dirname;
const BUILD_DIR = path.join(BASE_DIR, 'build');
const DOC_DIR = path.join(BASE_DIR, 'doc');
const MODULE_ENTRY = path.join(BASE_DIR, 'src/index.js');
const ALL_ENTRIES = path.join(BASE_DIR, 'src/index.js');
const WP_SERVER_ENTRIES = path.join(BASE_DIR, 'src/index.html');
const TARGET_RAW = 'vexflow-musicxml.js';
const TARGET_MIN = 'vexflow-musicxml-min.js';
const TARGET_TESTS = 'vexflow-musicxml-tests.js';
const SOURCES = ['src/*.js'];
const TEST_SOURCES = ['tests/*.js', 'tests/parser/*.js', 'tests/testdata/mock/*.xml', 'tests/*.html'];
function webpackConfig(config) {
return {
entry: config.entry,
output: {
path: BUILD_DIR,
publicPath: 'assets',
filename: config.target,
library: config.library,
libraryTarget: 'umd',
},
devtool: 'source-map',
module: {
loaders: [
{
test: /\.js?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: [config.preset],
'plugins': ['add-module-exports', 'transform-object-assign'],
},
},
],
},
plugins: [
// new webpack.optimize.UglifyJsPlugin({
// sourceMap: true,
// }),
],
};
}
const webpackTest = webpackConfig({
entry: MODULE_ENTRY,
target: TARGET_TESTS,
library: 'Vex.Flow.MusicXml',
preset: 'es2015',
});
const webpackAll = webpackConfig({
entry: ALL_ENTRIES,
target: TARGET_RAW,
library: 'Vex',
preset: 'es2015',
});
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
dev: {
files: [SOURCES, 'tests/*.html'],
tasks: ['fast'],
},
test: {
files: [TEST_SOURCES],
tasks: ['test'],
},
meteor: {
files: [TEST_SOURCES, SOURCES],
tasks: ['meteor'],
},
},
uglify: {
options: {
banner: BANNER,
sourceMap: true,
},
build: {
src: path.resolve(BUILD_DIR, TARGET_RAW),
dest: path.resolve(BUILD_DIR, TARGET_MIN),
},
},
eslint: {
target: SOURCES,
options: {
configFile: '.eslintrc',
},
},
clean: {
all: [BUILD_DIR, 'doc/*', '!doc/images/**'],
doc: ['doc/*', '!doc/images/**'],
options: {'no-write': false}
},
webpack: {
test: Object.assign(webpackCfg, webpackTest),
all: webpackAll,
watch: Object.assign({}, webpackAll, {
watch: true,
keepalive: true,
}),
},
// FIXME: grunt-webpack-server does not support webpack 3.x configs
webpack_server: {
options: {
webpackCfg,
port: 8080,
stats: !process.env.NODE_ENV || process.env.NODE_ENV === 'development',
},
dev: {
keepAlive: true,
webpack: {
devtool: 'eval',
debug: true,
},
},
},
mochaTest: {
test: {
options: {
reporter: 'spec',
captureFile: 'results.txt', // Optionally capture the reporter output to a file
quiet: false, // Optionally suppress output to standard out (defaults to false)
clearRequireCache: false, // Optionally clear the require cache before running tests (defaults to false)
require: 'babel-register',
recursive: true,
},
src: ['tests/run.js'],
},
},
jsdoc: {
dist: {
src: ['src/*.js', 'src/xml/*.js', 'src/vex/*.js', 'src/visitors/*.js', 'tests/*.js', 'README.md'],
options: Object.assign({ destination: DOC_DIR }, jsdocCfg),
},
},
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-webpack');
grunt.loadNpmTasks('grunt-webpack-server');
// Default task(s).
grunt.registerTask('default', ['eslint', 'webpack:all', 'uglify:build', 'doc']);
grunt.registerTask('test', ['clean:all', 'eslint', 'webpack:test', 'mochaTest', 'doc']);
grunt.registerTask('meteor', ['clean:all', 'eslint', 'webpack:test', 'mochaTest', 'webpack:all', 'doc']);
grunt.registerTask('fast', ['webpack:all']);
grunt.registerTask('doc', ['clean:doc', 'jsdoc']);
};