diff --git a/.babelrc b/.babelrc index 426d1b3..321ce7e 100644 --- a/.babelrc +++ b/.babelrc @@ -1,5 +1,5 @@ { - "presets": ["es2015"], + "presets": ["@babel/env"], "compact": false, "comments": false -} \ No newline at end of file +} diff --git a/.gitignore b/.gitignore index e43ab00..a3f5d46 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,4 @@ npm-debug.log config.json dist -sync-config.json \ No newline at end of file +sync-config.json diff --git a/README.md b/README.md index 0ee8593..d8e7b4b 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Installation Syncjs is easy to install, just execute the following ``` -npm install -g syncjs +npm install -g sync ``` After this you'll have `syncjs` binary available to you. @@ -57,6 +57,8 @@ syncjs init - **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. +[11:37] Silas Köhler +- **ignores**: An array of strings for files you want to ignore. You can can define strings for absolute paths or regular expression. Default ignores: /node_modules/, /.git/, /.svn/, /bower_components/, /sync-config.json/ License @@ -65,4 +67,4 @@ MIT ## License -[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fserkanyersen%2Fsync.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fserkanyersen%2Fsync?ref=badge_large) \ No newline at end of file +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fserkanyersen%2Fsync.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fserkanyersen%2Fsync?ref=badge_large) diff --git a/gulpfile.js b/gulpfile.js index b6a90b6..27e17cd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,21 +1,22 @@ -var gulp = require("gulp"); -var ts = require("gulp-typescript"); -var babel = require("gulp-babel"); -var rename = require("gulp-rename"); +const { watch, series, src, dest } = require('gulp') +const ts = require("gulp-typescript") +const babel = require("gulp-babel"); +const 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")); -}); +function buildTask () { + var tsProject = ts.createProject(__dirname + "/tsconfig.json"); + return tsProject.src() + .pipe(tsProject()) + .pipe(babel()) + .pipe(rename(function (path) { + path.extname = ".js"; + })) + .pipe(dest("./dist")); +} -gulp.task("watch", function() { - gulp.watch("./src/**/*.ts", ["build"]); -}); +function watchTask () { + watch("./src/**/*.ts", buildTask); +} -gulp.task("default", ["build", "watch"]) \ No newline at end of file +exports.build = buildTask; +exports.default = series(buildTask, watchTask); diff --git a/package.json b/package.json index 5af7b5d..c2adee8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "syncjs", - "version": "2.0.2", + "version": "2.1.1", "main": "dist/index.js", "preferGlobal": true, "scripts": { @@ -12,31 +12,30 @@ "syncjs": "bin/syncjs" }, "dependencies": { - "chalk": "^1.1.3", - "chokidar": "^1.6.1", - "inquirer": "^1.1.2", + "chalk": "^4.1.0", + "chokidar": "^3.4.3", + "inquirer": "^7.3.3", "jsonplus": "^1.2.1", "minimist": "^1.2.0", "observatory": "^1.0.0", "prompt": "^1.0.0", "scp2": "^0.5.0", - "upath": "^0.2.0" + "upath": "^2.0.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/core": "^7.12.3", + "@babel/preset-env": "^7.12.1", + "@types/inquirer": "^7.3.1", + "@types/minimist": "^1.1.29", + "@types/node": "^14.14.2", "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" + "gulp": "^4.0.2", + "gulp-babel": "^8.0.0", + "gulp-rename": "^2.0.0", + "gulp-typescript": "^6.0.0-alpha.1", + "typescript": "^4.0.3" }, "repository": { "type": "git", diff --git a/src/classes/CLI.ts b/src/classes/CLI.ts index ba7b64c..dfaa160 100644 --- a/src/classes/CLI.ts +++ b/src/classes/CLI.ts @@ -1,4 +1,4 @@ -import * as chalk from "chalk"; +import chalk = require("chalk"); import * as minimist from "minimist"; import inquirer = require("inquirer"); @@ -30,7 +30,7 @@ export default class CLI { private lastRun: number; private timeDiff: number; private args: minimist.ParsedArgs; - private ui: inquirer.ui.Prompt[] = []; + private ui: any[] = []; // inquirer.ui.Prompt private activePrompt; private pauseEvents: Function[] = []; public paused: boolean; @@ -79,7 +79,7 @@ export default class CLI { /** * Write something to terminal */ - write(msg: string | chalk.ChalkChain): boolean { + write(msg: string): boolean { return process.stdout.write.bind(process.stdout)(msg); } @@ -89,12 +89,12 @@ export default class CLI { // this.showPrompt(); } - read(question: any, hidden = false): Promise { - let scheme = { + read(question: string, hidden = false): Promise { + let scheme = ["questions", { type: hidden? "password" : "input", message: question, - name: "response" - }; + name: "response", + }]; // Bad type definition let promise = inquirer.prompt(scheme); diff --git a/src/classes/InitConfig.ts b/src/classes/InitConfig.ts index 7813ed1..2095a65 100644 --- a/src/classes/InitConfig.ts +++ b/src/classes/InitConfig.ts @@ -16,7 +16,7 @@ export default class InitConfig2 { console.log("Existing config found."); } catch(e) {} - let questions: inquirer.Questions = [ + let questions: inquirer.QuestionCollection = [ { type: "input", name: "username", @@ -37,7 +37,7 @@ export default class InitConfig2 { "Password in config", "Ask password during connection", "Private key" - ] + ], }, { type: "password", diff --git a/src/classes/Watcher.ts b/src/classes/Watcher.ts index 5f10668..6b9f923 100644 --- a/src/classes/Watcher.ts +++ b/src/classes/Watcher.ts @@ -17,17 +17,32 @@ export default class Watcher { private base: string = config.localPath ) { - let defaultIgnores: Array = [/node_modules/, /.git/, /.svn/, /bower_components/]; + let defaultIgnores: Array = [/node_modules/, /.git/, /.svn/, /bower_components/, /sync-config.json/]; + + let configIgnored: Array = []; + + // Create regular expressions if possible + if(this.config.ignores) { + configIgnored = this.config.ignores.map(ignoreItem => { + console.log(ignoreItem); + try { + return new RegExp(ignoreItem); + } catch(e) { + return ignoreItem; + } + }); + } this.files = chokidar.watch(base, { - ignored: defaultIgnores.concat(this.config.ignores), + ignored: defaultIgnores.concat(configIgnored), ignoreInitial: true }); // Attach events ["all", "add", "change", "unlink", "unlinkDir"].forEach(method => { - this.files.on(method, this.handler(method)); + this.files.on(method, this.handler(method).bind(this)); }); + } ready(): Promise { @@ -44,7 +59,9 @@ export default class Watcher { }; private handler(method: string): Function { + return (...args: string[]) => { + let path: string, event = method;