move node_modules and grunt file to root dir

This commit is contained in:
Barret Schloerke
2018-05-17 16:13:13 -04:00
parent 5280b72b85
commit bcebf737c3
7 changed files with 4517 additions and 2084 deletions

View File

@@ -1,255 +0,0 @@
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
},
},
"string-replace": {
version: {
files: {
'./temp_concat/shiny.js': './temp_concat/shiny.js'
},
options: {
replacements: [{
pattern: /{{ VERSION }}/g,
replacement: pkgInfo().version
}]
}
}
},
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"}],
"guard-for-in": 1,
// "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'
}
},
watch: {
shiny: {
files: ['<%= concat.shiny.src %>', '../DESCRIPTION'],
tasks: [
'newer:concat',
'newer:eslint',
'configureBabel',
'newer:babel',
'newer:uglify'
]
},
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-string-replace');
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
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:string-replace',
'newer:eslint',
'configureBabel',
'newer:babel',
'newer:uglify'
]);
// ---------------------------------------------------------------------------
// 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;
}
};

View File

@@ -31,7 +31,7 @@ Periodically, it's good to upgrade the packages to a recent version. There's two
1. Use `yarn upgrade` to upgrade all dependencies to their latest version based on the version range specified in the package.json file (the yarn.lock file will be recreated as well. Yarn packages use [semantic versioning](https://yarnpkg.com/en/docs/dependency-versions), i.e. each version is writen with a maximum of 3 dot-separated numbers such that: `major.minor.patch`. For example in the version `3.1.4`, 3 is the major version number, 1 is the minor version number and 4 is the patch version number. Here are the most used operators (these appear before the version number):
- `~` is for upgrades that keep the minor version the same (assuming that was specified);
- `^` is for upgrades that keep the major version the same (more or less -- more specifically, it allow changes that do not modify the first non-zero digit in the version, either the 3 in 3.1.4 or the 4 in 0.4.2.). This is the default operator added to the package.json when you run `yarn add [package-name]`.
2. Use `yarn upgrade [package]` to upgrade a single named package to the version specified by the latest tag (potentially upgrading the package across major versions).
@@ -65,19 +65,19 @@ And here is how the CLI works (same source):
To run all default grunt tasks specified in the Gruntfile (concatenation, minification, and jshint), simply go into the `tools` directory and run:
```
grunt
yarn run build
```
Sometimes grunt gets confused about whether the output files are up to date, and won't overwrite them even if the input files have changed. If this happens, run:
```
grunt clean
yarn run clean
```
It's also useful to run `grunt` so that it monitors files for changes and run tasks as necessary. This is done with:
```
grunt watch
yarn run watch
```
One of the tasks concatenates all the .js files in `/srcjs` together into `/inst/www/shared/shiny.js`. Another task minifies `shiny.js` to generate `shiny.min.js`. The minified file is supplied to the browser, along with a source map file, `shiny.min.js.map`, which allows a user to view the original Javascript source when using the debugging console in the browser.

View File

@@ -1,24 +0,0 @@
{
"private": true,
"scripts": {
"build": "grunt",
"clean": "grunt clean",
"watch": "grunt watch"
},
"devDependencies": {
"babel-eslint": "^6.0.0",
"babel-preset-es2015": "^6.6.0",
"eslint-stylish-mapped": "^1.0.0",
"grunt": "^1.0.1",
"grunt-babel": "^6.0.0",
"grunt-cli": "^1.2.0",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-concat": "^1.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-uglify": "1.0.1",
"grunt-contrib-watch": "^1.0.0",
"grunt-eslint": "^18.0.0",
"grunt-newer": "^1.1.2",
"grunt-string-replace": "^1.3.1"
}
}

File diff suppressed because it is too large Load Diff