mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-05-03 17:42:56 +00:00
Merge pull request #858 from balena-io/sync-watch
Use webpack watching for sync.js for a faster dev cycle
This commit is contained in:
commit
d57db859d4
55
sync.js
55
sync.js
@ -1,31 +1,48 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
// Sync changes in the javascript code to a running supervisor on a device in the local network
|
if (!process.argv[2] || ['help', '-h', '--help'].includes(process.argv[2])) {
|
||||||
//
|
console.log(`
|
||||||
// Usage:
|
Sync changes in the javascript code to a running supervisor on a device in the local network
|
||||||
// ./sync.js <device IP>
|
|
||||||
//
|
|
||||||
// The script will first build a non-optimized version of the js code and sync the resulting app.js
|
|
||||||
// onto the supervisor container at the specified IP. It will also restart the supervisor container.
|
|
||||||
// The device must be a development variant of balenaOS and the supervisor must be running.
|
|
||||||
|
|
||||||
fs = require('fs');
|
Usage:
|
||||||
|
./sync.js <device IP>
|
||||||
|
|
||||||
doSync = require('balena-sync').sync('local-balena-os-device').sync;
|
The script will first build a non-optimized version of the js code and sync the resulting app.js
|
||||||
|
onto the supervisor container at the specified IP. It will also restart the supervisor container.
|
||||||
// Avoid a super confusing error where the cwd doesn't exist
|
The device must be a development variant of balenaOS and the supervisor must be running.
|
||||||
dir = __dirname + '/dist';
|
`)
|
||||||
if (!fs.existsSync(dir)) {
|
process.exit(1)
|
||||||
fs.mkdirSync(dir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
opts = {
|
const childProcess = require('child_process');
|
||||||
|
|
||||||
|
const webpack = require('webpack');
|
||||||
|
const webpackConfig = require('./webpack.config');
|
||||||
|
const compiler = webpack(webpackConfig({ noOptimize: true }));
|
||||||
|
|
||||||
|
const doSync = require('balena-sync').sync('local-balena-os-device').sync;
|
||||||
|
|
||||||
|
const syncOpts = {
|
||||||
deviceIp: process.argv[2],
|
deviceIp: process.argv[2],
|
||||||
baseDir: dir,
|
baseDir: __dirname + '/dist',
|
||||||
destination: '/usr/src/app/dist',
|
destination: '/usr/src/app/dist',
|
||||||
appName: 'resin_supervisor',
|
appName: 'resin_supervisor',
|
||||||
skipGitignore: true,
|
skipGitignore: true,
|
||||||
before: 'npm install && npm run build -- --env.noOptimize',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
doSync(opts);
|
childProcess.execSync('npm install', { stdio: 'inherit' });
|
||||||
|
|
||||||
|
compiler.watch({
|
||||||
|
ignored: /node_modules/,
|
||||||
|
}, (err, stats) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(stats.toString({ colors: true }));
|
||||||
|
if (stats.hasErrors()) {
|
||||||
|
console.error('Skipping sync due to errors');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
doSync(syncOpts);
|
||||||
|
});
|
||||||
|
@ -106,7 +106,9 @@ module.exports = function (env) {
|
|||||||
return callback()
|
return callback()
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new ForkTsCheckerWebpackPlugin(),
|
new ForkTsCheckerWebpackPlugin({
|
||||||
|
async: false
|
||||||
|
}),
|
||||||
new CopyWebpackPlugin([
|
new CopyWebpackPlugin([
|
||||||
{
|
{
|
||||||
from: './src/migrations',
|
from: './src/migrations',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user