forked from dutscher/aemsync
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (55 loc) · 1.72 KB
/
index.js
File metadata and controls
69 lines (55 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict'
const minimist = require('minimist')
const path = require('path')
const fs = require('graceful-fs')
const log = require('./src/log.js')
const chalk = require('chalk')
const Watcher = require('./src/watcher.js').Watcher
const Pusher = require('./src/pusher.js').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 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 main () {
let args = minimist(process.argv.slice(2))
// Show help.
if (args.h) {
console.log(MSG_HELP)
return
}
// Get other args.
log.isDebug = args.d
let workingDir = path.resolve(args.w ? args.w : '.')
if (!fs.existsSync(workingDir)) {
log.info('Invalid path:', chalk.yellow(workingDir))
return
}
let targets = args.t ? args.t : 'http://admin:admin@localhost:4502'
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)}
`)
let pusher = new Pusher(targets.split(','), pushInterval)
let watcher = new Watcher()
pusher.start()
watcher.watch(workingDir, exclude, (localPath) => {
pusher.addItem(localPath)
})
}
if (require.main === module) {
main()
}
module.exports = {
main: main,
Watcher: Watcher,
Pusher: Pusher
}