forked from rstudio/shiny
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
251 lines (225 loc) · 7.8 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
242
243
244
245
246
247
248
249
250
251
module.exports = function(grunt) {
var instdir = '../inst/';
var js_srcdir = '../srcjs/'
gruntConfig = {
pkg: pkgInfo(),
clean: {
options: { force: true },
src: [
instdir + "www/shared/shiny.js",
instdir + "www/shared/shiny.js.map",
instdir + "www/shared/shiny.min.js",
instdir + "www/shared/shiny.min.js.map",
"./temp_concat/shiny.js",
"./temp_concat/shiny.js.map",
instdir + 'www/shared/datepicker/js/bootstrap-datepicker.min.js',
instdir + 'www/shared/ionrangeslider/js/ion.rangeSlider.min.js'
]
},
concat: {
options: {
process: function(src, filepath) {
return '//---------------------------------------------------------------------\n' +
'// Source file: ' + filepath + '\n\n' + src;
},
sourceMap: true
},
shiny: {
src: [
js_srcdir + '_start.js',
js_srcdir + 'utils.js',
js_srcdir + 'browser.js',
js_srcdir + 'input_rate.js',
js_srcdir + 'shinyapp.js',
js_srcdir + 'notifications.js',
js_srcdir + 'modal.js',
js_srcdir + 'file_processor.js',
js_srcdir + 'binding_registry.js',
js_srcdir + 'output_binding.js',
js_srcdir + 'output_binding_text.js',
js_srcdir + 'output_binding_image.js',
js_srcdir + 'output_binding_html.js',
js_srcdir + 'output_binding_downloadlink.js',
js_srcdir + 'output_binding_datatable.js',
js_srcdir + 'output_binding_adapter.js',
js_srcdir + 'input_binding.js',
js_srcdir + 'input_binding_text.js',
js_srcdir + 'input_binding_textarea.js',
js_srcdir + 'input_binding_password.js',
js_srcdir + 'input_binding_number.js',
js_srcdir + 'input_binding_checkbox.js',
js_srcdir + 'input_binding_slider.js',
js_srcdir + 'input_binding_date.js',
js_srcdir + 'input_binding_daterange.js',
js_srcdir + 'input_binding_select.js',
js_srcdir + 'input_binding_radio.js',
js_srcdir + 'input_binding_checkboxgroup.js',
js_srcdir + 'input_binding_actionbutton.js',
js_srcdir + 'input_binding_tabinput.js',
js_srcdir + 'input_binding_fileinput.js',
js_srcdir + 'init_shiny.js',
js_srcdir + 'reactlog.js',
js_srcdir + '_end.js'
],
// The temp_concat/ directory would have gone under /srcjs/, but the
// Babel Grunt plugin has trouble finding presets if it operates on a
// file that's not under the current directory. So we'll put it under
// ./
dest: './temp_concat/shiny.js',
nonull: true
},
},
babel: {
options: {
sourceMap: true,
compact: false,
presets: ['es2015']
},
shiny: {
src: './temp_concat/shiny.js',
dest: instdir + '/www/shared/shiny.js'
}
},
eslint: {
options: {
parser: 'babel-eslint',
format: require('eslint-stylish-mapped'),
extends: 'eslint:recommended',
rules: {
"consistent-return": 1,
"dot-location": [1, "property"],
"eqeqeq": 1,
// "no-shadow": 1,
"no-undef": 1,
"no-unused-vars": [1, {"args": "none"}],
// "no-use-before-define": [1, {"functions": false}],
"semi": [1, "always"]
},
envs: [
"es6",
"browser",
"jquery"
],
globals: ["strftime"]
},
shiny: ['./temp_concat/shiny.js']
},
uglify: {
shiny: {
options: {
banner: '/*! <%= pkg.name %> <%= pkg.version %> | ' +
'(c) 2012-<%= grunt.template.today("yyyy") %> RStudio, Inc. | ' +
'License: <%= pkg.license %> */\n',
sourceMap: true,
// Base the .min.js sourcemap off of the .js sourcemap created by concat
sourceMapIn: instdir + 'www/shared/shiny.js.map',
sourceMapIncludeSources: true
},
src: instdir + 'www/shared/shiny.js',
dest: instdir + 'www/shared/shiny.min.js'
},
datepicker: {
src: [
instdir + 'www/shared/datepicker/js/bootstrap-datepicker.js',
instdir + 'www/shared/datepicker/js/locales/bootstrap-datepicker.*.js'
],
dest: instdir + 'www/shared/datepicker/js/bootstrap-datepicker.min.js'
},
ionrangeslider: {
src: instdir + 'www/shared/ionrangeslider/js/ion.rangeSlider.js',
dest: instdir + 'www/shared/ionrangeslider/js/ion.rangeSlider.min.js'
}
},
copy: {
babelPolyfill: {
src: "node_modules/babel-polyfill/dist/polyfill.min.js",
dest: "../inst/www/shared/babel-polyfill.min.js"
}
},
watch: {
shiny: {
files: ['<%= concat.shiny.src %>', '../DESCRIPTION'],
tasks: [
'newer:concat',
'newer:eslint',
'configureBabel',
'newer:babel',
'newer:uglify'
]
},
babelPolyfill: {
files: '<%= copy.babelPolyfill.src %>',
tasks: ['newer:copy:babelPolyfill']
},
datepicker: {
files: '<%= uglify.datepicker.src %>',
tasks: ['newer:uglify:datepicker']
}
},
newer: {
options: {
override: function(detail, include) {
// If DESCRIPTION is updated, we'll also need to re-minify shiny.js
// because the min.js file embeds the version number.
if (detail.task === 'uglify' && detail.target === 'shiny') {
include(isNewer('../DESCRIPTION', detail.time));
} else {
include(false);
}
}
}
}
};
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-newer');
// Need this here so that babel reads in the source map file after it's
// generated. Without this task, it would read in the source map when Grunt
// runs, which is wrong, if the source map doesn't exist, or is change later.
grunt.task.registerTask("configureBabel", "configures babel options", function() {
gruntConfig.babel.options.inputSourceMap = grunt.file.readJSON('./temp_concat/shiny.js.map');
});
grunt.initConfig(gruntConfig);
grunt.registerTask('default', [
'newer:concat',
'newer:eslint',
'configureBabel',
'newer:babel',
'newer:uglify',
'newer:copy'
]);
// ---------------------------------------------------------------------------
// Utility functions
// ---------------------------------------------------------------------------
// Return an object which merges information from package.json and the
// DESCRIPTION file.
function pkgInfo() {
var pkg = grunt.file.readJSON('package.json');
pkg.name = descKeyValue('Package');
pkg.version = descKeyValue('Version');
pkg.license = descKeyValue('License');
return pkg;
}
// From the DESCRIPTION file, get the value of a key. This presently only
// works if the value is on one line, the same line as the key.
function descKeyValue(key) {
var lines = require('fs').readFileSync('../DESCRIPTION', 'utf8').split('\n');
var pattern = new RegExp('^' + key + ':');
var txt = lines.filter(function(line) {
return pattern.test(line);
});
txt = txt[0];
pattern = new RegExp(key + ': *');
txt = txt.replace(pattern, '');
return txt;
}
// Return true if file's mtime is newer than mtime; false otherwise.
function isNewer(file, mtime) {
return require('fs').statSync(file).mtime > mtime;
}
};