Skip to content

Commit

Permalink
Merge pull request #6 from serkanyersen/v2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
serkanyersen authored Nov 3, 2016
2 parents ef869bd + f22c301 commit 204174b
Show file tree
Hide file tree
Showing 24 changed files with 4,122 additions and 518 deletions.
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": ["es2015"],
"compact": false,
"comments": false
}
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ lib-cov
*.pid
*.gz

.idea

pids
logs
results

node_modules
npm-debug.log

config.json
config.json
dist

sync-config.json
14 changes: 0 additions & 14 deletions .jshintrc

This file was deleted.

43 changes: 43 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
"configurations": [
{
"request": "launch",
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch sync.js",
// Type of configuration.
"type": "node",
// Workspace relative or absolute path to the program.
"program": "${workspaceRoot}/bin/syncjs",
// Automatically stop program after launch.
"stopOnEntry": false,
// Command line arguments passed to the program.
"args": ["-c", "config_example.json", "--no-color"],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": "${workspaceRoot}",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Optional arguments passed to the runtime executable.
"runtimeArgs": ["--nolazy"],
// Environment variables passed to the program.
"env": {
"NODE_ENV": "development"
},
// Use JavaScript source maps (if they exist).
"sourceMaps": true,
// If JavaScript source maps are enabled, the generated code is expected in this directory.
"outDir": "${workspaceRoot}/dist/"
},
{
"request": "attach",
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
// "address": "localhost",
// Port to attach to.
"port": 5858,
"sourceMaps": true
}
]
}
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.trimTrailingWhitespace": true,
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/dist": true,
"**/typings": true
},
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.DS_Store": true,
"**/dist/*": true
}
,
"typescript.tsdk": "./node_modules/typescript/lib"
}
25 changes: 25 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"showOutput": "always",
"suppressTaskName": true,
"tasks": [
{
"taskName": "install",
"args": ["install"]
},
{
"taskName": "build",
"args": ["run", "build"],
"isWatching": true,
"isBuildCommand": true
},
{
"taskName": "test",
"args": ["run", "test"]
}
]
}
95 changes: 39 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,62 @@
## Sync.js - Upload changed local files to remote server
sync.js let's you keep your remote files in sync with your local copy. Whenever you make a change on your local project, sync.js uploads the changed files to remote server using `scp` command.
Syncjs - Upload changed local files to remote server
----------------------------------------------------

When configured correctly, it works really fast because sync.js leverages [openSSH master connection settings](http://protempore.net/~calvins/howto/ssh-connection-sharing/). That means instead of creating new connections for each upload, sync.js keeps one connection open and uses it for all uploads.
Syncjs is an easy to use command line tool for uploading your local changes to a remote server.

![How it works](http://i.imgur.com/weaaKqh.gif "How it works")
It's useful in situations where your application needs to be on a remote server to run (dev machines, pubdev environments, etc.) but you still want to use your local environment for development. You can simply map you local copy of the project to the remote version and syncjs will do the rest.

### Why did I do this? Aren't there already tools doing the same exact thing?
Yes there are. However, none of them fulfills my needs. I use Sublime Text 2 and occasionally VIM. ST2 has `SFTP` plugin
~~but it doesn't have ST3 support yet~~, also it doesn't upload files when they changed via other editors.
![Syncjs in use](http://i.imgur.com/rLNUErv.gif, "syncjs")

I tried `unison` but it kills the CPU and syncs remote to local too. Configuration was too complex and it was not really customizable. As soon as I started `unison` it filled my computer with all the compressed scripts and tmp files from the server.
This example shows usage with Visual Studio Code but since it's an external script, you can use it with any editor you want.

Other options were mostly either not working or doing so many other things that I don't need. I only want to upload files to remote server when they are changed. That's it.
![Vim Example](http://i.imgur.com/drnEET1.gif, "syncjs")

### Features
Features
--------
- Easy to setup
- Fast and reliable
- Runs independently from your toolchain so you can use it with anyting
- Runs on windows, osx and linux
- detects and handles changes on folders
- can run multiple instances at the same time

- Fast and reliable change detection
- Very light weight, doesn't use excessive CPU power
- Internal command line to control the script while it's working
- Doesn't depend on any editor, so you can use it with any application
- It's very simplistic and customizable, you can alter the script however you like
- Colorful and interactive output.
- And many more

### Installation
Just clone this repository `anywhere` on your computer
Installation
------------

```
git clone git@github.com:serkanyersen/sync.git
```
Go inside `sync ` folder and install dependencies

```
cd sync
npm install
```
Create a config file using the example file
Syncjs is easy to install, just execute the following

```
cp config_example.json config.json
```
The config file is very self explanatory, just open it and add your own information

```json
{
"host": "username@ssh.yourhost.com",
"interval_duration": 1.5,
"local_path": "/path/to/local/folder",
"remote_path": "/path/to/remote/folder"
}
npm install -g syncjs
```
To leverage the openSSH master connection feature, just open `~/.ssh/config` file
and put the following in it (unless you don't have it already):

```
Host *
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p
```
Now you are ready to go, start the script by calling sync.js with either `./sync.js` or `nodejs sync.js`
After this you'll have `syncjs` binary available to you.

That's it.
Configuration
-------------

### Bonus
If you are on OSX and using `iTerm` or any other terminal other than the default `Terminal.app`, you can install [TotalTerminal](http://totalterminal.binaryage.com/) formerly known as `Visor` and start `sync.js` from it. And if you add this line to `config.json`
Syncjs comes with an init script and sets itself up for you. All you need to do is to `cd` into your projects directory and run `syncjs init` it will ask few simple questions and create the config file called `sync-config.json` make sure you include this file in your `.gitignore` because this file might contain passwords or secrets depending on your preferences.

```
"visorSupport": true
cd /my/project/folder
syncjs init
```
sync.js will pop visor terminal on the screen for a second and hide it again, so that you'll understand script is currently uploading your change.
![Configuration](http://i.imgur.com/3VnNDc5.gif, "syncjs init")

It works better when you place the visor at the bottom of the screen and reduce the row count.

### Questions on config
- **Username**: your username that you use to connect to remote machine
- **Auth method**:
- **Password in config**: This the least secure version of auth. It will keep your password in the config file **as plain text** do not use this please
- **Ask during connect**: This option will ask your password again every time you start `syncjs` your password will not be stored anywhere.
- **Private Key**: Most secure option, just provide the path for your key file and syncjs will do the rest

- **Hostname or IP of the server**: Tell syncjs where to connect
- **Port to connect**: defaults to `22` this usually is what you want
- **Local path**: syncjs will automatically detect this as the root of your project, but if you only want to sync one specific folder, **provide it here as full path**
- **Remote path**: This is where copy of your local folder lives in the remote server. Make sure you type full path here as well.

## License
MIT, Go Crazy

License
-------
MIT
5 changes: 5 additions & 0 deletions bin/syncjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node
var path = require('path');
var Sync = require(path.resolve(__dirname, '../dist/index.js')).default;

new Sync();
6 changes: 0 additions & 6 deletions config_example.json

This file was deleted.

21 changes: 21 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var gulp = require("gulp");
var ts = require("gulp-typescript");
var babel = require("gulp-babel");
var rename = require("gulp-rename");

gulp.task("build", function () {
var tsProject = ts.createProject(__dirname + "/tsconfig.json");
return tsProject.src()
.pipe(tsProject())
.pipe(babel())
.pipe(rename(function (path) {
path.extname = ".js";
}))
.pipe(gulp.dest("./dist"));
});

gulp.task("watch", function() {
gulp.watch("./src/**/*.ts", ["build"]);
});

gulp.task("default", ["build", "watch"])
66 changes: 60 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,64 @@
{
"name": "sync.js",
"version": "0.0.1",
"name": "syncjs",
"version": "2.0.0",
"main": "dist/index.js",
"preferGlobal": true,
"scripts": {
"start": "gulp",
"build": "gulp build",
"postinstall": "gulp build"
},
"bin": {
"syncjs": "bin/syncjs"
},
"dependencies": {
"moment": "latest",
"cli-color": "latest",
"underscore.string": "latest"
"chalk": "^1.1.3",
"chokidar": "^1.6.1",
"inquirer": "^1.1.2",
"jsonplus": "^1.2.1",
"minimist": "^1.2.0",
"observatory": "^1.0.0",
"prompt": "^1.0.0",
"scp2": "^0.5.0",
"upath": "^0.2.0"
},
"description": "sync.js let's you keep your remote files in sync with your local copy. Whenever you make a change on your local project, sync.js uploads the changed files to remote server using `scp` command.",
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-preset-es2015": "^6.18.0",
"babel-runtime": "^6.18.0",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-rename": "^1.2.2",
"gulp-typescript": "^3.1.2",
"typescript": "^2.0.6",
"@types/chalk": "^0.4.31",
"@types/chokidar": "^1.4.29",
"@types/inquirer": "^0.0.30",
"@types/minimist": "^1.1.29",
"@types/node": "^6.0.46"
},
"repository": {
"type": "git",
"url": "git+https://github.com/serkanyersen/sync.git"
},
"keywords": [
"SFTP",
"sync",
"rsync",
"scp",
"ftp",
"upload",
"project",
"typescript",
"developer",
"tools",
"tooling"
],
"author": "Serkan Yersen",
"license": "MIT",
"bugs": {
"url": "https://github.com/serkanyersen/sync/issues"
},
"license": "MIT"
"homepage": "https://github.com/serkanyersen/sync#readme"
}
Loading

0 comments on commit 204174b

Please sign in to comment.