Skip to content

Commit

Permalink
Chore: Adding rsync to yarn run watch (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Chan committed Oct 17, 2018
1 parent c0bb9a2 commit afe6ab6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ src/i18n/json
test/dev.html
lib
*~~bak
functional-tests/output
functional-tests/output
build/rsync.json
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
17 changes: 17 additions & 0 deletions build/RsyncPlugin.js
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 15 additions & 0 deletions build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(), {
Expand All @@ -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';
}
Expand Down

0 comments on commit afe6ab6

Please sign in to comment.