-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
141 lines (125 loc) · 4.03 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
'use strict';
const os = require('os');
const isWindows = os.type().toLowerCase().match(/windows/);
/**
* Gruntfile for the web assets for the `formation` JS library. Automates and tests builds
* for development and production. Use this when you modify source code files to build and
* test the codebase.
*/
module.exports = function(grunt) {
// Project configuration.
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack');
const defaultWebpackConfig = require('./webpack.config.js');
const pkg = grunt.file.readJSON('package.json');
grunt.initConfig({
pkg,
paths : {
docs : 'docs',
jsSrc : 'src',
jsTestSrc : 'tests',
jsTestResultsSrc : 'test-results',
jsOut : 'dist'
},
/* Set up our linter for JS files */
jshint : {
options : {
jshintrc : '.jshintrc'
},
all : {
src : [
'Gruntfile.js',
'webpack.config.js',
'<%= paths.jsSrc %>/**/*.js',
'<%= paths.jsTestSrc %>/**/*.js'
]
}
},
webpack : {
options : defaultWebpackConfig,
dev : {
devtool: 'source-map',
mode: 'development',
},
build : {
mode: 'production',
output: {
filename: 'formation.min.js'
},
optimization: {
minimizer: [
new UglifyJsPlugin({
parallel: true,
sourceMap: true,
})
]
},
plugins : [
new webpack.BannerPlugin({
banner: `Package: ${pkg.name}\r\n${pkg.description}\r\nVersion: ${pkg.version}\r\nAuthor: ${pkg.author}\r\nBuilt: ${grunt.template.today('yyyy-mm-dd HH:MM')}`,
entryOnly : true
}),
]
}
},
mochaTest: {
test: {
src: ['<%= paths.jsTestSrc %>/**/*.js'],
options : {
timeout : 7000,
reporter : 'spec',
require: ['babel-register', 'jsdom-global/register']
}
}
},
mocha_istanbul: { // jshint ignore:line
coverage : {
src:['<%= paths.jsTestSrc %>/**/*.js'],
options: {
coverageFolder: '<%= paths.jsTestResultsSrc %>',
nodeExec: isWindows ? require.resolve('./node_modules/.bin/babel-node.cmd') : require.resolve('./node_modules/.bin/babel-node'),
scriptPath: require.resolve('isparta/lib/cli'),
mochaOptions: ['--compilers', 'js:babel-register', '--require', 'jsdom-global/register'],
reportFormats: ['lcov', 'html']
}
}
},
istanbul_check_coverage : { // jshint ignore:line
default : {
options: {
coverageFolder: '<%= paths.jsTestResultsSrc %>'
}
}
},
/* Copy compiled JS files to docs examples JS folder so GitHub Pages site has newest version. */
copy : {
toDocs : {
files : [
{
expand: true,
cwd: './<%= paths.jsOut %>',
src: '*.*',
dest: './<%= paths.docs %>/examples/js'
}
]
}
}
});
// Load up all appropriate Tasks
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-mocha-istanbul');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-webpack');
/* Register our tasks */
// The development build will lint all JS, concatenate all dependency JS, and concatenate project source JS.
grunt.registerTask('dev', ['jshint:all', 'webpack:dev']);
// Just run unit tests without re-building the development source each time.
grunt.registerTask('unitTests', ['mocha_istanbul']);
grunt.registerTask('unitTests:mocha', ['mochaTest']);
// The test build will build the development source and unit test that.
grunt.registerTask('test', ['dev', 'unitTests']);
// Our production build will first unit test all development code before producing production output.
grunt.registerTask('build', ['test', 'webpack:build', 'copy:toDocs']);
};