Skip to content

Commit

Permalink
Various fixes:
Browse files Browse the repository at this point in the history
- #19
- #20
- #24
- Replaced anymatch with micromatch
- Introduced NPM's new package-lock.json
  • Loading branch information
gavoja committed Jun 7, 2017
1 parent c22e16c commit a708edb
Show file tree
Hide file tree
Showing 8 changed files with 942 additions and 138 deletions.
26 changes: 11 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ aemsync -t targets -w path_to_watch
-e: Anymatch exclude filter; any file matching the pattern will be skipped.
-d: Enable debug mode.
```

```
aemsync -t http://admin:admin@localhost:4502,http://admin:admin@localhost:4503 -w ~/workspace/my_project
```
Expand All @@ -53,29 +52,26 @@ let onPushEnd = (err, host) => {
if (err) {
return console.log(`Error when pushing package to ${host}.`, err)
}
console.log(`Package pushed to ${host}.`)
console.log(`Package pushed to ${host}.`)
}

// Create Pusher and Watcher.
let pusher = new Pusher(targets, pushInterval, onPushEnd)
let watcher = new Watcher()

// Initialize queue processing.
pusher.start()

// Watch over workingDir.
watcher.watch(workingDir, exclude, (localPath) => {
// Add item to Pusher's queue when a change is detected.
pusher.enqueue(localPath)
})
aemsync({workingDir, targets, exclude, pushInterval, onPushEnd})
```

### Description

The Watcher uses Node's `fs.watch()` function to watch over directory changes recursively. For Windows and OSX the `recursive` option is used, which significantly improves the performance. Any changes inside `jcr_root/*` folders are detected and deployed to AEM instance(s) as a package.
The Watcher uses Node's `fs.watch()` function to watch over directory changes recursively. For Windows and OSX the `recursive` option is used, which significantly improves the performance.
Any changes inside `jcr_root` folders are detected and deployed to AEM instance(s) as a package. Rules:
* Changes to first level folders under `jcr_root` are igored. This is to avoid accidentally removing `apps`, `libs` or any other first level folders in AEM.
* The following are ignored by default: `.svn`, `.git`, `.hg`.

Update interval is the time the Pusher waits for file changes before the package is created. In case of multiple file changes (e.g. switching between code branches), creating a new package per file should be avoided and instead, all changes should be pushed in one go. Lowering the value decreases the delay for a single file change but may increase the delay for multiple file changes. If you are unsure, please leave the default value.

Note that some of the file changes will result in pushing the entire parent folder:
* Ading, removing or renaming files or directories.
* Changing `.content.xml`.
* Changing any file or directory inside `nt:unstructured` subtree. In this case the first non `nt:unstructured` ancestor will be pushed. This behaviour ensures proper handling of self-contained unstructured blocks of nodes such as dialogs that are distributed across multiple files (see [issue 19](https://github.com/gavoja/aemsync/issues/19)).

### Known issues

Packages are installed using package manager service (`/crx/packmgr/service.jsp`), which takes some time to initialize after AEM startup. If the push happens before, the Sling Post Servlet will take over causing the `/crx/packmgr/service.jsp/file` node to be added to the repository.
62 changes: 32 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,33 @@
const minimist = require('minimist')
const path = require('path')
const fs = require('graceful-fs')
const log = require('./src/log.js')
const log = require('./src/log')
const chalk = require('chalk')
const Watcher = require('./src/watcher.js')
const Pusher = require('./src/pusher.js')
const Watcher = require('./src/watcher')
const Pusher = require('./src/pusher')

const MSG_HELP = `Usage: aemsync [OPTIONS]
Options:
-t targets Defult is http://admin:admin@localhost:4502
-w path_to_watch Default is current
-e exclude_filter Micromatch exclude filter; disabled by default
-i sync_interval Update interval; default is 300ms
-d Enable debug mode
-h Displays this screen
const MSG_HELP = `Usage: aemsync [OPTIONS]
Options:
-t targets Defult is http://admin:admin@localhost:4502
-w path_to_watch Default is current
-e exclude_filter Anymach exclude filter; disabled by default
-i sync_interval Update interval; default is 300ms
-d Enable debug mode
-h Displays this screen
Website: https://github.com/gavoja/aemsync`

function aemsync (args) {
let pusher = new Pusher(args.targets.split(','), args.pushInterval, args.onPushEnd)
let watcher = new Watcher()

pusher.start()
watcher.watch(args.workingDir, args.exclude, (localPath) => {
pusher.enqueue(localPath)
})
}

function main () {
let args = minimist(process.argv.slice(2))

Expand All @@ -42,28 +52,20 @@ function main () {
let pushInterval = args.i ? args.i : 300
let exclude = args.e ? args.e : ''

log.info(`
Working dir: ${chalk.yellow(workingDir)}
Targets: ${chalk.yellow(targets)}
Interval: ${chalk.yellow(pushInterval)}
Exclude: ${chalk.yellow(exclude)}
log.info(`
Working dir: ${chalk.yellow(workingDir)}
Targets: ${chalk.yellow(targets)}
Interval: ${chalk.yellow(pushInterval)}
Exclude: ${chalk.yellow(exclude)}
`)

let pusher = new Pusher(targets.split(','), pushInterval)
let watcher = new Watcher()

pusher.start()
watcher.watch(workingDir, exclude, (localPath) => {
pusher.enqueue(localPath)
})
aemsync({workingDir, targets, pushInterval, exclude})
}

if (require.main === module) {
main()
}

module.exports = {
main: main,
Watcher: Watcher,
Pusher: Pusher
}
aemsync.Watcher = Watcher
aemsync.Pusher = Pusher
module.exports = aemsync
Loading

0 comments on commit a708edb

Please sign in to comment.