Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Adding rsync to yarn run watch #241

Merged
merged 1 commit into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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