This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Gruntfile.js
164 lines (154 loc) · 4.41 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
module.exports = function toExport(grunt) {
grunt.initConfig({
/**
* Pull in the package.json file so we can read its metadata.
*/
pkg: grunt.file.readJSON('package.json'),
/**
*
* Pull in config-specific vars
*
*/
config: grunt.file.readJSON('config.json'),
env: {
dev: {
NODE_ENV: 'development',
},
dist: {
NODE_ENV: 'production',
},
},
/**
* Copy dependencies into static paths
*/
copy: {
main: {
files: [
{
expand: true,
flatten: true,
src: ['node_modules/respond.js/dest/*'],
dest: '<%= config.frontEndPath %>/js/built/lib/respond/',
filter: 'isFile',
},
],
},
},
/**
* https://github.com/gruntjs/grunt-contrib-sass
*/
sass: {
dev: {
options: {
style: 'expanded',
sourceMap: true,
},
files: {
'<%= config.frontEndPath %>/css/style.css': '<%= config.frontEndPath %>/css/scss/main.scss',
},
},
},
/**
* CSSMin: https://github.com/gruntjs/grunt-contrib-cssmin
*
* Minify CSS for production
*/
cssmin: {
target: {
files: {
'<%= config.frontEndPath %>/css/regulations.min.css': ['<%= config.frontEndPath %>/css/style.css'],
},
},
},
/**
* ESLint: https://github.com/sindresorhus/grunt-eslint
*
* Validate files with ESLint.
*/
eslint: {
target: [
'Gruntfile.js',
'<%= config.frontEndPath %>/js/source/*.js',
'<%= config.frontEndPath %>/js/source/events/**/*.js',
'<%= config.frontEndPath %>/js/source/models/**/*.js',
'<%= config.frontEndPath %>/js/source/views/**/*.js',
'<%= config.frontEndPath %>/js/source/views/**/*.jsx',
],
},
/**
* Browserify:
*
* Require('modules') in the browser/bundle up dependencies.
*/
browserify: {
dev: {
files: {
'<%= config.frontEndPath %>/js/built/regulations.js': ['<%= config.frontEndPath %>/js/source/regulations.js', '<%= config.frontEndPath %>/js/source/regulations.js'],
},
options: {
transform: ['babelify', 'browserify-shim'],
browserifyOptions: {
debug: true,
extensions: ['.js', '.jsx'],
},
},
},
dist: {
files: {
'<%= config.frontEndPath %>/js/built/regulations.min.js': ['<%= config.frontEndPath %>/js/source/regulations.js'],
},
options: {
transform: ['babelify', 'browserify-shim'],
browserifyOptions: {
debug: true,
extensions: ['.js', '.jsx'],
},
plugin: [
[function minifyify(b) {
b.plugin('minifyify', {
map: grunt.template.process('<%= config.frontEndPath %>/js/built/regulations.min.map'),
output: grunt.template.process('<%= config.frontEndPath %>/js/built/regulations.min.map'),
});
}],
],
},
},
},
mocha_istanbul: {
coverage: {
src: ['<%= config.frontEndPath %>/js/unittests/specs/**/*.js'],
options: {
root: '<%= config.frontEndPath %>/js',
scriptPath: require.resolve('isparta/lib/cli'),
istanbulOptions: ['--include-all-sources'],
mochaOptions: ['--compilers', 'js:babel-register'],
nodeExec: require.resolve('.bin/babel-node'),
coverageFolder: '<%= config.frontEndPath %>/js/unittests/coverage',
coverage: false,
},
},
},
});
/* eslint-disable global-require,import/no-extraneous-dependencies */
grunt.event.on('coverage', (lcov, done) => {
require('coveralls').handleInput(lcov, (err) => {
if (err) {
done(err);
}
done();
});
});
/**
* The above tasks are loaded here.
*/
require('load-grunt-tasks')(grunt);
/* eslint-enable */
/**
* Create task aliases by registering new tasks
*/
grunt.registerTask('test', ['eslint', 'mocha_istanbul']);
grunt.registerTask('test-js', ['eslint', 'mocha_istanbul']);
grunt.registerTask('build-dev', ['env:dev', 'copy', 'browserify:dev', 'sass']);
grunt.registerTask('build-dist', ['env:dist', 'copy', 'browserify:dist', 'sass', 'cssmin']);
grunt.registerTask('default', ['build-dist']);
};