Skip to content

Commit 4b163a4

Browse files
committed
Merge pull request #261 from elistone/monitor-file
Monitor file
2 parents afb0088 + dc15ec3 commit 4b163a4

File tree

6 files changed

+85
-43
lines changed

6 files changed

+85
-43
lines changed

README.md

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,40 @@
11
# Atom Remote Sync
2-
32
This package provides functionality for:
4-
5-
* Uploading changes automatically when you save a file
6-
* Uploading/downloading files to/from the server
7-
* Displaying diffs between the local and remote files with your favourite diff tool
8-
* set difftoolCommand in AtomSettingView of `remote-sync` The path to your diff tool executable
3+
- Uploading changes automatically when you save a file
4+
- Uploading/downloading files to/from the server
5+
- Displaying diffs between the local and remote files with your favourite diff tool
6+
- Monitor files for external change and automatically upload
7+
- set difftoolCommand in AtomSettingView of `remote-sync` -- The path to your diff tool executable
98

109
Currently, both SCP/SFTP and FTP are supported.
1110

1211
## Installation
13-
1412
You can install this like any other Atom package, with one of these methods:
15-
16-
* Open your settings in Atom, select the "Install" tab, search for "remote-sync", and click install on it
17-
* Run `apm install remote-sync` in a terminal
18-
* Download or clone this repository to your `~/.atom/packages/` directory and enter the directory run `apm install`
13+
- Open your settings in Atom, select the "Install" tab, search for "remote-sync", and click install on it
14+
- Run `apm install remote-sync` in a terminal
15+
- Download or clone this repository to your `~/.atom/packages/` directory and enter the directory run `apm install`
1916

2017
## Usage
21-
2218
Create file `.remote-sync.json` in your project root with these settings:
23-
24-
* `transport``scp` for SCP/SFTP, or `ftp` for FTP
25-
* `hostname` — Remote host address
26-
* `port` - Remort port to connect on (typically 22 for SCP/SFTP, 21 for FTP)
27-
* `username` — Remote host username
28-
* `password` — Remote host password
29-
* `keyfile` — Absolute path to SSH key (only used for SCP)
30-
* `passphrase` — Passphrase for the SSH key (only used for SCP)
31-
* `useAgent` — Whether or not to use an agent process, default: false (only used for SCP)
32-
* `target` — Target directory on remote host
33-
* `source` — Source directory relative to project root
34-
* `ignore` — Array of [minimatch](https://github.com/isaacs/minimatch) patterns of files to ignore
35-
* `uploadOnSave` — Whether or not to upload the current file when saved, default: false
36-
* `useAtomicWrites` — Upload file using a temporary filename before moving to its final location (only used for SCP), default: false
37-
* `uploadMirrors` — transport mirror config array when upload
38-
* `deleteLocal` - whether or not to delete the local file / folder after remote delete
39-
* `saveOnUpload` - Whether or not to save a modified file before uploading, default: false
19+
- `transport` -- `scp` for SCP/SFTP, or `ftp` for FTP
20+
- `hostname` -- Remote host address
21+
- `port` - Remort port to connect on (typically 22 for SCP/SFTP, 21 for FTP)
22+
- `username` -- Remote host username
23+
- `password` -- Remote host password
24+
- `keyfile` -- Absolute path to SSH key (only used for SCP)
25+
- `passphrase` -- Passphrase for the SSH key (only used for SCP)
26+
- `useAgent` -- Whether or not to use an agent process, default: false (only used for SCP)
27+
- `target` -- Target directory on remote host
28+
- `source` -- Source directory relative to project root
29+
- `ignore` -- Array of [minimatch](https://github.com/isaacs/minimatch) patterns of files to ignore
30+
- `uploadOnSave` -- Whether or not to upload the current file when saved, default: false
31+
- `useAtomicWrites` -- Upload file using a temporary filename before moving to its final location (only used for SCP), default: false
32+
- `uploadMirrors` -- transport mirror config array when upload
33+
- `deleteLocal` - whether or not to delete the local file / folder after remote delete
34+
- `saveOnUpload` - Whether or not to save a modified file before uploading, default: false
4035

4136
SCP example:
37+
4238
```json
4339
{
4440
"transport": "scp",
@@ -57,6 +53,7 @@ SCP example:
5753
```
5854

5955
SCP `useAgent` example:
56+
6057
```json
6158
{
6259
"transport": "scp",
@@ -73,6 +70,7 @@ SCP `useAgent` example:
7370
```
7471

7572
FTP example:
73+
7674
```json
7775
{
7876
"transport": "ftp",
@@ -89,6 +87,7 @@ FTP example:
8987
```
9088

9189
Upload mirrors example:
90+
9291
```json
9392
{
9493
"transport": "scp",
@@ -114,7 +113,7 @@ Upload mirrors example:
114113
"passphrase": "your_passphrase",
115114
"target": "/home/vagrant/dirname/subdirname_one",
116115
"ignore": [
117-
".remote-sync.json",
116+
".remote-sync.json",
118117
".git/**"
119118
]
120119
},
@@ -126,7 +125,7 @@ Upload mirrors example:
126125
"password": "vagrant",
127126
"target": "/home/vagrant/dirname/subdirname_two",
128127
"ignore": [
129-
".remote-sync.json",
128+
".remote-sync.json",
130129
".git/**"
131130
]
132131
}
@@ -135,17 +134,14 @@ Upload mirrors example:
135134
```
136135

137136
## Usage example
138-
139137
### Existing project
140-
141138
1. Add a file named `.remote-sync.json` to your project, with the contents above
142139
2. Open the command palette by pressing cmd + shift + P on a Mac, or ctrl + shift + P on Linux/Windows
143140
3. Type in `remote sync reload config` and press enter
144141

145142
That's it!
146143

147144
### From scratch, with a remote server
148-
149145
1. Create a folder for your project, and create a file named `.remote-sync.json` in it with the contents above
150146
2. In the Atom editor, open the command palette by pressing cmd + shift + P on a Mac, or ctrl + shift + P on Linux/Windows
151147
3. Type in `remote sync reload config` and press enter
@@ -154,6 +150,5 @@ That's it!
154150

155151
The package will download all of the files from the remote server for you.
156152

157-
158-
#Make a donation via Paypal ![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)
153+
# Make a donation via Paypal ![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)
159154
Click 'Send Money' after login PayPal, and my PayPal account is: lx1988cyk#gmail.com

index.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ module.exports =
9595
'remote-sync:diff-file': (e)-> handleEvent(e, "diffFile")
9696
'remote-sync:diff-folder': (e)-> handleEvent(e, "diffFolder")
9797
'remote-sync:upload-git-change': (e)-> handleEvent(e, "uploadGitChange")
98+
'remote-sync:monitor-file': (e)-> handleEvent(e, "monitorFile")
9899
'remote-sync:configure': configure
99100
})
100101

lib/RemoteSync.coffee

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
path = require "path"
33
fs = require "fs-plus"
4+
chokidar = require "chokidar"
45

56
exec = null
67
minimatch = null
@@ -15,6 +16,10 @@ Host = null
1516
HostView = null
1617
EventEmitter = null
1718

19+
MonitoredFiles = []
20+
watcher = chokidar.watch()
21+
22+
1823
logger = null
1924
getLogger = ->
2025
if not logger
@@ -29,7 +34,7 @@ class RemoteSync
2934
@host = new Host(@configPath)
3035
@initIgnore(@host)
3136
@projectPath = path.join(@projectPath, @host.source) if @host.source
32-
37+
3338
initIgnore: (host)->
3439
ignore = host.ignore?.split(",")
3540
host.isIgnore = (filePath, relativizePath) =>
@@ -50,7 +55,7 @@ class RemoteSync
5055
inPath: (rootPath, localPath)->
5156
localPath = localPath + path.sep if fs.isDirectorySync(localPath)
5257
return localPath.indexOf(rootPath + path.sep) == 0
53-
58+
5459
dispose: ->
5560
if @transport
5661
@transport.dispose()
@@ -93,7 +98,7 @@ class RemoteSync
9398
if e.getPath() is filePath and e.isModified()
9499
e.save()
95100
return if @host.uploadOnSave
96-
101+
97102
uploadCmd.handleSave(filePath, @getTransport())
98103
for t in @getUploadMirrors()
99104
uploadCmd.handleSave(filePath, t)
@@ -102,6 +107,35 @@ class RemoteSync
102107
fs.traverseTree dirPath, @uploadFile.bind(@), =>
103108
return not @isIgnore(dirPath)
104109

110+
monitorFile: (dirPath)->
111+
if dirPath not in MonitoredFiles
112+
MonitoredFiles.push dirPath
113+
watcher.add(dirPath);
114+
_this = @
115+
watcher.on('change', (path) ->
116+
_this.uploadFile(path)
117+
).on 'unlink', (path) ->
118+
log 'File', path, 'has been removed'
119+
else
120+
watcher.unwatch(dirPath)
121+
index = MonitoredFiles.indexOf(dirPath);
122+
MonitoredFiles.splice(index, 1)
123+
@.monitorStyles()
124+
125+
monitorStyles: ()->
126+
monitorClass = 'file-monitoring'
127+
monitored = document.querySelectorAll '.'+monitorClass
128+
129+
if monitored != null and monitored.length != 0
130+
for item in monitored
131+
item.classList.remove monitorClass
132+
133+
for file in MonitoredFiles
134+
file_name = file.replace(/(['"])/g, "\\$1");
135+
icon_file = document.querySelector '[data-path="'+file_name+'"]'
136+
list_item = icon_file.parentNode
137+
list_item.classList.add monitorClass
138+
105139
uploadGitChange: (dirPath)->
106140
repos = atom.project.getRepositories()
107141
curRepo = null

menus/context.cson

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{label: 'Download File', command: 'remote-sync:download-file'}
77
{label: 'Diff File', command: 'remote-sync:diff-file'}
88
{label: 'Delete File', command: 'remote-sync:delete-file'}
9+
{label: 'Monitor File (Upload on External Save)', command: 'remote-sync:monitor-file'}
910
]
1011
]
1112

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
"atom": ">=0.78"
1010
},
1111
"dependencies": {
12-
"ssh2": "^0.2",
13-
"minimatch": "^0.2",
1412
"async": "^0.2",
15-
"mkdirp": "^0.3",
1613
"atom-message-panel": "^1.1.1",
1714
"atom-space-pen-views": "^2.0.3",
15+
"chokidar": "^1.4.3",
1816
"fs-plus": "^2.1",
19-
"ftp": "^0.3.7"
17+
"ftp": "^0.3.7",
18+
"minimatch": "^0.2",
19+
"mkdirp": "^0.3",
20+
"ssh2": "^0.2"
2021
}
2122
}

styles/monitor.less

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.file-monitoring{
2+
&:after{
3+
content: "M";
4+
width: 25px;
5+
height: 25px;
6+
color: orange;
7+
position: absolute;
8+
right: 0px;
9+
}
10+
}

0 commit comments

Comments
 (0)