Verified Commit 1f473a16 authored by Aral Balkan's avatar Aral Balkan
Browse files

Add --exit-on-sync flag to the sync command for one-type sync

(Useful in deployments.)
parent 0ba0715a
......@@ -81,6 +81,12 @@ Like the other commands, if you do not specify a folder, the current folder will
__Important:__ The trailing slash is important. It means “sync the contents of this folder but not the folder itself”. If you leave out the trailing slash, it means “sync the contents of this folder and the folder itself”. The latter will result in a folder of the same name as your local folder being created in your destination folder on the remote server. Indie Web Server inherits this functionality from the rsync command itself and keeps it for consistency.
__Note:__ If you want to carry out a one-time sync and not run the server afterwards, use the `--exit-on-sync` flag. e.g.,
```shell
$ web-server sync my-folder my-demo.site --exit-on-sync
```
### Global (ephemeral)
Start serving the _site_ directory at your _hostname_ as a regular process using globally-trusted Let’s Encrypt certificates:
......
......@@ -43,6 +43,7 @@ function help () {
const optionFolder = option('folder')
const optionProxy = option('proxy')
const optionSync = option('sync')
const optionExitOnSync = option('exit-on-sync')
const prompt = clr('', 'blue')
......@@ -90,6 +91,7 @@ function help () {
${optionAccount}\tThe ssh account to use on remote server (defaults to same as on current session).
${optionFolder}\tThe subfolder of home folder to sync to on remote machine (defaults to name of served folder).
${optionProxy}\tProxy the specified host and port instead of starting a regular local server.
${optionExitOnSync}\tExit once the first sync has occurred. Useful in deployment scripts.
${heading('Examples:')}
......
......@@ -20,6 +20,8 @@
const localServer = require('./local')
const proxyServer = require('./proxy')
const Graceful = require('node-graceful')
const RsyncWatcher = require('../lib/RsyncWatcher')
const ensure = require('../lib/ensure')
const clr = require('../../lib/clr')
......@@ -104,6 +106,12 @@ function sync (options) {
'sync': function () {
// Sync succeeded.
console.log(` 💞 [Sync] Local folder ${clr(options.syncLocalFolder, 'cyan')} synced to ${clr(options.syncRemoteHost, 'cyan')}`)
if (options.syncExitOnSync) {
// We've been asked to exit once we’ve successfully synced. Do so.
console.log('\n 👋 Exit on sync requested, exiting…')
Graceful.exit()
}
},
'watch': function () {
// Watch succeeded.
......
......@@ -252,7 +252,7 @@ class CommandLineInterface {
const syncOptionsDerivedFromPositionalArguments = { syncLocalFolder: null, syncRemoteHost: null }
const syncOptions = { syncRemoteConnectionString: null, syncLocalFolder: null, syncStartProxyServer: null, syncRemoteHost: null }
const syncOptions = { syncRemoteConnectionString: null, syncLocalFolder: null, syncStartProxyServer: null, syncRemoteHost: null, syncExitOnSync: null }
if (command.isSync) {
......@@ -261,6 +261,9 @@ class CommandLineInterface {
function namedArgumentExists(namedArgument) {
return typeof command.namedArguments[namedArgument] === 'string'
}
''
// Sync on exit flag.
syncOptions.syncExitOnSync = command.namedArguments['exit-on-sync'] === true
// Check for conflicts between positional arguments and named arguments
// and fail if there are any.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment