Skip to content
This repository was archived by the owner on Jul 15, 2022. It is now read-only.

Commit d4ffcc7

Browse files
committed
Merge branch 'sync-improvements'
2 parents 223e992 + 5619edf commit d4ffcc7

File tree

7 files changed

+49
-9
lines changed

7 files changed

+49
-9
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
44

55
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).
66

7+
## [16.1.0] - 2021-03-11
8+
9+
## Fixed
10+
11+
- Regression: `--sync-to` without `--sync-from` no longer fails (https://source.small-tech.org/site.js/app/-/issues/254)
12+
13+
## Improved
14+
15+
- 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)
16+
17+
- 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)
18+
719
## [16.0.6] - 2021-03-08
820

921
Update to @small-tech/https version 2.1.2, which includes @small-tech/auto-encrypt version 2.2.0.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ The above command will result in the following directory structure on the remote
403403

404404
(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.
405405

406+
(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.
407+
406408
#### Live Sync
407409

408410
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).
@@ -1652,7 +1654,7 @@ We exist in part thanks to patronage by people like you. If you share [our visio
16521654
16531655
## Copyright
16541656
1655-
© 2019-2020 [Aral Balkan](https://ar.al), [Small Technology Foundation](https://small-tech.org).
1657+
© 2019-2021 [Aral Balkan](https://ar.al), [Small Technology Foundation](https://small-tech.org).
16561658
16571659
Let’s Encrypt is a trademark of the Internet Security Research Group (ISRG). All rights reserved. Node.js is a trademark of Joyent, Inc. and is used with its permission. We are not endorsed by or affiliated with Joyent or ISRG.
16581660

bin/commands/serve.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,22 @@ function localFolder (args) {
319319
let localFolder = null
320320

321321
// If --sync-from is not specified, we default to the path to be served (or use a default path).
322-
const syncFrom = args.named[SYNC_FROM] || path || '.'
322+
const dotWasSpecificallyRequestedForSyncFrom = (args.named[SYNC_FROM] === '.')
323+
let syncFrom = args.named[SYNC_FROM] || path || '.'
324+
325+
// A common mistake is to start a sync from the .hugo, .dynamic, etc. folder
326+
// because you happen to be working in it. Try to detect this and magically fix it.
327+
if (!dotWasSpecificallyRequestedForSyncFrom && syncFrom === '.') {
328+
let absoluteSyncPath = pathModule.resolve(syncFrom)
329+
const specialFolders = /\.dynamic.*$|\.hugo.*$|\.db.*$|\.wildcard.*$/
330+
const intelligentSyncPath = absoluteSyncPath.replace(specialFolders, '')
331+
332+
if (absoluteSyncPath !== intelligentSyncPath) {
333+
syncFrom = pathModule.relative(absoluteSyncPath, intelligentSyncPath)
334+
console.log(` 🧙 ❨site.js❩ ${clr('Magically changed sync path to the site root.', 'yellow')}`)
335+
}
336+
}
337+
323338
const syncFromEndsWithPathSeparator = syncFrom.endsWith(pathModule.sep)
324339

325340
// Handle the sync-folder-and-contents flag or its lack
@@ -377,7 +392,7 @@ function remoteConnectionInfo (args) {
377392
}
378393

379394
function defaultRemotePath (account) {
380-
const localFolderPath = pathModule.resolve(syncFrom || path)
395+
const localFolderPath = pathModule.resolve(syncFrom || path || pathModule.dirname('.'))
381396
const localFolderFragments = localFolderPath.split(pathModule.sep)
382397
const localFolderName = localFolderFragments[localFolderFragments.length-1]
383398

index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,11 +1200,15 @@ class Site {
12001200

12011201
const roots = []
12021202

1203+
//
12031204
// Serve any generated static content (e.g., Hugo output) that might exist.
1204-
const generatedStaticFilesDirectory = path.join(this.pathToServe, '.generated')
1205-
if (fs.existsSync(generatedStaticFilesDirectory)) {
1205+
//
1206+
this.generatedStaticFilesDirectory = path.join(this.pathToServe, '.generated')
1207+
1208+
this.generatedContentExists = fs.existsSync(this.generatedStaticFilesDirectory)
1209+
if (this.generatedContentExists) {
12061210
this.log(` 🎠 ❨site.js❩ Serving generated static files.`)
1207-
roots.push(generatedStaticFilesDirectory)
1211+
roots.push(this.generatedStaticFilesDirectory)
12081212
}
12091213

12101214
// Add the regular static web root.
@@ -1319,6 +1323,13 @@ class Site {
13191323
this.log(` 🐁 ❨site.js❩ Wildcard route change: ${clr(`${this.prettyFileWatcherEvent(event)}`, 'green')} (${clr(file, 'cyan')}).`)
13201324
this.log('\n 🐁 ❨site.js❩ Requesting restart…\n')
13211325
await this.restartServer()
1326+
} else if (file.includes('/.generated') && !this.generatedContentExists && fs.existsSync(this.generatedStaticFilesDirectory)) {
1327+
//
1328+
// Generated folder has been added.
1329+
//
1330+
this.log(` 🐁 ❨site.js❩ Generated folder has been added: ${clr(`${this.prettyFileWatcherEvent(event)}`, 'green')} (${clr(file, 'cyan')}).`)
1331+
this.log('\n 🐁 ❨site.js❩ Requesting restart…\n')
1332+
await this.restartServer()
13221333
}
13231334
})
13241335

lib/Util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Util {
5656
}
5757

5858
// Only attempt to magically fix the path to serve (if necessary)
59-
// if the current directory way not specifically requested by the person.
59+
// if the current directory was not specifically requested by the person.
6060
let absolutePathToServe = path.resolve(pathToServe)
6161

6262
if (pathSpecified !== '.' && pathToServe === '.') {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@small-tech/site.js",
3-
"version": "16.0.6",
3+
"version": "16.1.0",
44
"description": "Small Web construction set.",
55
"keywords": [
66
"web server",

0 commit comments

Comments
 (0)