From 712996853317c71eb6981c562ce14350034d02a9 Mon Sep 17 00:00:00 2001 From: Conrad Chan Date: Wed, 17 Oct 2018 10:54:40 -0700 Subject: [PATCH] Chore: Adding rsync to yarn run watch --- .gitignore | 3 ++- README.md | 6 ++++++ build/RsyncPlugin.js | 17 +++++++++++++++++ build/webpack.config.js | 15 +++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 build/RsyncPlugin.js diff --git a/.gitignore b/.gitignore index 2bd421210..4a8268061 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ src/i18n/json test/dev.html lib *~~bak -functional-tests/output \ No newline at end of file +functional-tests/output +build/rsync.json diff --git a/README.md b/README.md index d12d0e40c..145c35d91 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,12 @@ Supported image file extensions: `ai, bmp, dcm, eps, gif, png, ps, psd, svs, tga 9. Test your first build! `yarn run build` 10. To test only local annotation changes, see [instantiating a custom instance of Box Annotations](https://github.com/box/box-annotations/#passing-an-instance-of-box-annotations-into-box-content-preview). 11. To link and test your local code changes along with your local Preview changes, run `yarn link` in this repository and `yarn link box-annotations` wherever [Box Content Preview](github.com/box/box-content-preview/) is cloned locally. +12. To automatically rsync files after a Webpack build, add a build/rsync.json file with a `location` field. This file should look like: +``` +{ + "location": "YOUR_DESIRED_RSYNC_LOCATION_HERE" +} +``` For more information on contributing see [Contributing](docs/contributing.md). diff --git a/build/RsyncPlugin.js b/build/RsyncPlugin.js new file mode 100644 index 000000000..93764428f --- /dev/null +++ b/build/RsyncPlugin.js @@ -0,0 +1,17 @@ +const execSync = require('child_process').execSync; + +function RsyncPlugin(source, destination) { + this.source = source; + this.destination = destination; +} + +/* eslint-disable no-console */ +RsyncPlugin.prototype.apply = function rsync(compiler) { + compiler.plugin('done', () => { + console.log(''); + console.log(`🔄 🔄 🔄 Rsync starting for ${this.source} 🔄 🔄 🔄`); + execSync(`rsync -avzq --exclude=".*" "${this.source}" "${this.destination}"`, { stdio: [0, 1, 2] }); + }); +}; + +module.exports = RsyncPlugin; diff --git a/build/webpack.config.js b/build/webpack.config.js index 07ca32e7c..a042fcf3a 100644 --- a/build/webpack.config.js +++ b/build/webpack.config.js @@ -5,11 +5,21 @@ const isDev = process.env.NODE_ENV === 'dev'; const path = require('path'); const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); +const RsyncPlugin = require('./RsyncPlugin'); const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); const { BannerPlugin } = require('webpack'); const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); const commonConfig = require('./webpack.common.config'); const license = require('./license'); +const fs = require('fs'); + +let rsyncLocation = ''; +if (fs.existsSync('build/rsync.json')) { + /* eslint-disable */ + const rsyncConf = require('./rsync.json'); + rsyncLocation = rsyncConf.location; + /* eslint-enable */ +} /* eslint-disable key-spacing, require-jsdoc */ const config = Object.assign(commonConfig(), { @@ -23,6 +33,11 @@ const config = Object.assign(commonConfig(), { }); if (isDev) { + // If build/rsync.json exists, rsync bundled files to specified directory + if (rsyncLocation) { + config.plugins.push(new RsyncPlugin('lib/.', rsyncLocation)); + } + // Add inline source map config.devtool = 'inline-source-map'; }