Commit b3bcbb74 authored by Aral Balkan's avatar Aral Balkan
Browse files

Sync now detects erroneous invocations from well-known subfolders

(And automatically does the right thing.)
parent db625a8b
...@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. ...@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [16.0.7] - 2021-03-11 ## [16.1.0] - 2021-03-11
## Fixed ## Fixed
...@@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ...@@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- The addition of a generated folder now causes the server to restart. So, for example, if you’re going from a plain site to a Hugo site and you sync, you do not need to manually restart your production server. (https://source.small-tech.org/site.js/app/-/issues/261) - The addition of a generated folder now causes the server to restart. So, for example, if you’re going from a plain site to a Hugo site and you sync, you do not need to manually restart your production server. (https://source.small-tech.org/site.js/app/-/issues/261)
- Sync now detects common erroneous invocations from well-known site subfolders (e.g., .hugo, .dynamic, etc.) and magically fixes the path (just like the serve command does for the path to serve). (https://source.small-tech.org/site.js/app/-/issues/262)
## [16.0.6] - 2021-03-08 ## [16.0.6] - 2021-03-08
Update to @small-tech/https version 2.1.2, which includes @small-tech/auto-encrypt version 2.2.0. Update to @small-tech/https version 2.1.2, which includes @small-tech/auto-encrypt version 2.2.0.
......
...@@ -403,6 +403,8 @@ The above command will result in the following directory structure on the remote ...@@ -403,6 +403,8 @@ The above command will result in the following directory structure on the remote
(As of 15.4.0) If the sync command cannot connect in 5 seconds, it will time out. If this happens, check that you have the correct host and account details specified. If you do, there might be a problem with your connection. (As of 15.4.0) If the sync command cannot connect in 5 seconds, it will time out. If this happens, check that you have the correct host and account details specified. If you do, there might be a problem with your connection.
(As of 16.1.0) It’s a common mistake to start the sync without specifying the `--sync-from` option when not in the root of your site but in one of the well-known subfolders (e.g., `.hugo` if you’re working on a Hugo site or your `.dynamic` folder if you happen to be in it because you’re working on a site that uses DotJS.) In these instances, Site.js will detect the mistake and understand that you want to sync the site, not the subfolder and behave accordingly. If you _really_ want to sync one of the well-known subfolders for some reason, then specifically specify it by setting `--sync-from=.`. Note that this magic rewriting of the sync path doesn’t happen any time you specify a folder explicitly using the `--sync-from` option.
#### Live Sync #### Live Sync
With the Live Sync feature, you can have Site.js watch for changes to your content and sync them to your server in real-time (e.g., if you want to live blog something or want to keep a page updated with local data you’re collecting from a sensor). With the Live Sync feature, you can have Site.js watch for changes to your content and sync them to your server in real-time (e.g., if you want to live blog something or want to keep a page updated with local data you’re collecting from a sensor).
......
...@@ -319,7 +319,22 @@ function localFolder (args) { ...@@ -319,7 +319,22 @@ function localFolder (args) {
let localFolder = null let localFolder = null
// If --sync-from is not specified, we default to the path to be served (or use a default path). // If --sync-from is not specified, we default to the path to be served (or use a default path).
const syncFrom = args.named[SYNC_FROM] || path || '.' const dotWasSpecificallyRequestedForSyncFrom = (args.named[SYNC_FROM] === '.')
let syncFrom = args.named[SYNC_FROM] || path || '.'
// A common mistake is to start a sync from the .hugo, .dynamic, etc. folder
// because you happen to be working in it. Try to detect this and magically fix it.
if (!dotWasSpecificallyRequestedForSyncFrom && syncFrom === '.') {
let absoluteSyncPath = pathModule.resolve(syncFrom)
const specialFolders = /\.dynamic.*$|\.hugo.*$|\.db.*$|\.wildcard.*$/
const intelligentSyncPath = absoluteSyncPath.replace(specialFolders, '')
if (absoluteSyncPath !== intelligentSyncPath) {
syncFrom = pathModule.relative(absoluteSyncPath, intelligentSyncPath)
console.log(` 🧙 ❨site.js❩ ${clr('Magically changed sync path to the site root.', 'yellow')}`)
}
}
const syncFromEndsWithPathSeparator = syncFrom.endsWith(pathModule.sep) const syncFromEndsWithPathSeparator = syncFrom.endsWith(pathModule.sep)
// Handle the sync-folder-and-contents flag or its lack // Handle the sync-folder-and-contents flag or its lack
......
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