forked from cuthbertLab/music21j
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
241 lines (226 loc) · 7.67 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// Gruntfile for music21j
// Copyright Michael Scott Asato Cuthbert (cuthbert@mit.edu), BSD License
const path = require('path');
const webpack = require('webpack');
const ESLintPlugin = require('eslint-webpack-plugin');
const package_json = require('./package.json');
module.exports = grunt => {
const BANNER
= '/**\n'
+ ' * music21j version ' + package_json.version + ' built on '
+ (new Date()).toISOString().split('T')[0] + '.\n'
+ ' * Copyright (c) 2013-' + (new Date()).getFullYear() + ' '
+ 'Michael Scott Asato Cuthbert\n'
+ ' * BSD License, see LICENSE\n'
+ ' *\n'
+ ' * http://github.com/cuthbertLab/music21j\n'
+ ' */\n';
const BASE_DIR = __dirname;
const BUILD_DIR = path.join(BASE_DIR, 'build');
const DOC_DIR = path.join(BASE_DIR, 'doc');
const TEST_DIR = path.join(BASE_DIR, 'tests');
// const MODULE_ENTRY = path.join(BASE_DIR, 'src/music21_modules.js');
// const TARGET_RAW = path.join(BUILD_DIR, 'music21.debug.js');
// const TARGET_RAW_MAP = TARGET_RAW + '.map';
// const TARGET_MIN = path.join(BUILD_DIR, 'music21.min.js');
const SOURCES = [
'src/*.ts',
'src/*/*.ts',
];
const WATCH_SOURCES = SOURCES.concat(['Gruntfile.js']);
const TEST_ENTRY = path.join(TEST_DIR, 'loadAll.ts');
const TEST_SOURCES = [
'tests/loadAll.ts',
'tests/moduleTests/*.ts',
'tests/moduleTests/*/*.ts',
];
// const TARGET_TESTS = path.join(BUILD_DIR, 'music21.tests.js');
const babel_loader = babel_presets => {
return {
loader: 'babel-loader',
options: {
presets: babel_presets,
plugins: [
'@babel/plugin-transform-object-assign',
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-proposal-class-properties',
],
},
};
};
const webpackConfig = (target, preset) => {
// noinspection JSUnresolvedFunction
return {
entry: './src/main.ts', // MODULE_ENTRY,
output: {
path: BUILD_DIR,
filename: target,
library: 'music21',
libraryTarget: 'umd',
umdNamedDefine: true,
},
cache: {
type: 'memory',
},
mode: 'development',
devtool: 'source-map',
watch: true,
resolve: {
extensions: ['.ts', '.js'],
alias: {
vexflow: path.resolve(__dirname, './node_modules/vexflow/build/esm/entry/vexflow-gonville.js'),
},
},
module: {
rules: [
{ // typescript --> transpile to es6 using ts-loader,
// then babel to our target
test: /\.ts$/,
exclude: /node_modules/,
use: [
babel_loader(preset),
{ loader: 'ts-loader' },
],
},
{
test: /\.js$/,
exclude: /(node_modules|src\/ext)/,
use: [
babel_loader(preset)
],
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
plugins: [
new webpack.BannerPlugin({banner: BANNER, raw: true}),
new ESLintPlugin(
{
failOnError: false,
emitWarning: true,
extensions: ['ts', 'js'],
}
),
],
};
};
const babel_preset = [
[
'@babel/preset-env',
{
debug: false,
modules: false, // do not transform modules; let webpack do it
targets: {
browsers: [
'last 4 years',
'not < 0.04% in US',
'not firefox < 39',
'not safari < 10',
'not chrome < 49',
'not android < 80', // bug in browserslist
'not ios <= 10',
'not samsung <= 4',
'not ie <= 12', // all versions -- edge is separate
],
},
// useBuiltIns: 'usage',
// corejs: 3,
},
]
];
const webpackCommon = webpackConfig(
'music21.debug.js', // TARGET_RAW,
babel_preset,
);
const webpackTests = webpackConfig(
'music21.tests.js',
babel_preset,
);
webpackTests.entry = TEST_ENTRY;
webpackTests.output.path = TEST_DIR;
webpackTests.output.library = 'm21Tests';
webpackTests.watch = false;
// webpackTests.cache = true;
// Project configuration.
// noinspection JSUnresolvedFunction
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
webpack: {
build: Object.assign({
mode: 'production',
}, webpackCommon),
dev: Object.assign({
mode: 'development',
}, webpackCommon),
test: webpackTests,
},
jsdoc: {
dist: {
src: [
'src/music21/*.ts',
'src/music21/*/*.ts',
'README.md',
],
options: {
destination: DOC_DIR,
template: 'jsdoc-template',
configure: 'jsdoc-template/jsdoc.conf.json',
// that json document has most of the config options
},
},
},
eslint: {
target: SOURCES.concat(TEST_SOURCES),
options: {
configFile: '.eslintrc.json',
},
},
qunit: {
files: ['tests/gruntTest.html'],
},
watch: {
scripts: {
files: WATCH_SOURCES,
tasks: ['webpack:build'],
options: {
interrupt: true,
},
},
test: {
files: TEST_SOURCES.concat(WATCH_SOURCES),
tasks: ['test_no_watch'],
options: {
interrupt: true,
},
},
},
// raise the version number
bump: {
options: {
files: ['package.json'], // 'component.json'],
commitFiles: ['package.json'], // 'component.json'],
updateConfigs: ['pkg'],
createTag: false,
push: false,
},
},
});
grunt.loadNpmTasks('grunt-webpack');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-qunit');
// Plugin for the jsdoc task
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-eslint');
// Default task(s).
grunt.registerTask('default', ['webpack:build']);
grunt.registerTask('test', 'Watch qunit tests', ['watch:test']);
grunt.registerTask('test_no_watch', 'Run qunit tests', ['webpack:test', 'qunit']);
grunt.registerTask('publish', 'Raise the version and publish', () => {
grunt.task.run('jsdoc');
grunt.task.run('bump');
});
};