diff --git a/bin/backup b/bin/backup index 74314c2..af26fa4 100755 --- a/bin/backup +++ b/bin/backup @@ -11,7 +11,7 @@ var dir = process.argv[3] || process.cwd(); var fileName = process.argv[2]; var fn = function(path) { - return path.indexOf('.DS_Store') === -1; + return path.lastIndexOf('.DS_Store') === -1; }; backup.backup(dir, fileName, function(err, path) { @@ -21,6 +21,6 @@ backup.backup(dir, fileName, function(err, path) { return; } - console.log('Backup complete: ' + path); + console.log('Backup completed: ' + path); }, fn); \ No newline at end of file diff --git a/bin/restore b/bin/restore index 3430b2f..2273376 100644 --- a/bin/restore +++ b/bin/restore @@ -17,6 +17,6 @@ backup.restore(fileName, dir, function(err, path) { return; } - console.log('Restore complete: ' + path); + console.log('Restore completed: ' + path); }); \ No newline at end of file diff --git a/index.js b/index.js index b7f72c7..05b3683 100644 --- a/index.js +++ b/index.js @@ -1,24 +1,3 @@ -// Copyright Peter Širka, Web Site Design s.r.o. (www.petersirka.sk) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - 'use strict'; var fs = require('fs'); @@ -291,7 +270,7 @@ Backup.prototype.restore = function(filename, path, callback, filter) { Backup.prototype.restoreFile = function(key, value) { var self = this; - if (!self.filter(key)) + if (typeof(self.filter) === 'function' && !self.filter(key)) return; if (value === '#') { @@ -338,7 +317,7 @@ Backup.prototype.createDirectory = function(path, root) { dir = '/' + dir; if (fs.existsSync(dir)) - return; + continue; fs.mkdirSync(dir); } @@ -447,4 +426,11 @@ exports.restore = function(filename, path, callback, filter) { }; exports.Walker = Walker; -exports.Backup = Backup; \ No newline at end of file +exports.Backup = Backup; + +if (typeof(String.prototype.padRight) === 'undefined') { + String.prototype.padRight = function(max, c) { + var self = this; + return self + new Array(Math.max(0, max - self.length + 1)).join(c || ' '); + }; +} \ No newline at end of file diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..a2382ca --- /dev/null +++ b/license.txt @@ -0,0 +1,22 @@ +The MIT License + +Copyright 2012-2014 (c) Peter Širka + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to permit +persons to whom the Software is furnished to do so, subject to the +following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/minify/minify.js b/minify/minify.js new file mode 100644 index 0000000..1f17f81 --- /dev/null +++ b/minify/minify.js @@ -0,0 +1,13 @@ +var fs = require('fs'); +var path = require('path'); +var dir = './node-backup/'; + +var license = '// Copyright 2012-2014 (c) Peter Širka \n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// "Software"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'; + +fs.readdirSync(dir).forEach(function(name) { + if (name.match(/\.js$/) === null) + return; + var filename = path.join(dir, name); + console.log('....... LINCENSE: ' + name); + fs.writeFileSync(filename, license + fs.readFileSync(filename, 'utf8'), 'utf8'); +}); \ No newline at end of file diff --git a/minify/minify.sh b/minify/minify.sh new file mode 100644 index 0000000..aabd52d --- /dev/null +++ b/minify/minify.sh @@ -0,0 +1,13 @@ +ECHO "[COMPILING]" +cd .. +ECHO "....... index.js" +uglifyjs index.js -o minify/node-backup/index.js + +cp readme.md minify/node-backup/readme.md +cp package.json minify/node-backup/package.json +cp license.txt minify/node-backup/license.txt +cp bin/backup minify/node-backup/bin/backup +cp bin/restore minify/node-backup/bin/restore + +cd minify +node minify.js \ No newline at end of file diff --git a/minify/node-backup/bin/backup b/minify/node-backup/bin/backup new file mode 100755 index 0000000..af26fa4 --- /dev/null +++ b/minify/node-backup/bin/backup @@ -0,0 +1,26 @@ +#!/usr/bin/env node + +var backup = require('backup'); + +if (process.argv.length !== 3) { + console.log('ERROR: You must specify a filename for write backup.'); + return; +} + +var dir = process.argv[3] || process.cwd(); +var fileName = process.argv[2]; + +var fn = function(path) { + return path.lastIndexOf('.DS_Store') === -1; +}; + +backup.backup(dir, fileName, function(err, path) { + + if (err) { + console.log(err); + return; + } + + console.log('Backup completed: ' + path); + +}, fn); \ No newline at end of file diff --git a/minify/node-backup/bin/restore b/minify/node-backup/bin/restore new file mode 100644 index 0000000..2273376 --- /dev/null +++ b/minify/node-backup/bin/restore @@ -0,0 +1,22 @@ +#!/usr/bin/env node + +var backup = require('backup'); + +if (process.argv.length < 3) { + console.log('ERROR: You must specify a backup file and restore path.'); + return; +} + +var fileName = process.argv[2]; +var dir = process.argv[3] || process.cwd(); + +backup.restore(fileName, dir, function(err, path) { + + if (err) { + console.log(err); + return; + } + + console.log('Restore completed: ' + path); + +}); \ No newline at end of file diff --git a/minify/node-backup/index.js b/minify/node-backup/index.js new file mode 100644 index 0000000..7015244 --- /dev/null +++ b/minify/node-backup/index.js @@ -0,0 +1,22 @@ +// Copyright 2012-2014 (c) Peter Širka +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +"use strict";var fs=require("fs");var ph=require("path");var zlib=require("zlib");var padding=120;function Backup(){this.file=[];this.directory=[];this.path="";this.fileName="";this.read={key:"",value:"",status:0};this.complete=function(){};this.filter=function(path){return true}}function Walker(){this.pending=[];this.pendingDirectory=[];this.directory=[];this.file=[];this.options={sort:true,addEmptyDirectory:false};this.onComplete=null;this.onFilter=null}Walker.prototype.reset=function(){var self=this;self.file=[];self.directory=[];self.pendingDirectory=[]};Walker.prototype.walk=function(path){var self=this;if(path instanceof Array){var length=path.length;for(var i=0;i0){var item=self.pending.shift();self.stat(item);return}if(self.pendingDirectory.length>0){var directory=self.pendingDirectory.shift();self.walk(directory);return}if(self.options.sort){self.file.sort(function(a,b){return a.localeCompare(b)})}self.onComplete(self.directory,self.file)};Backup.prototype.backup=function(path,fileName,callback,filter){if(fs.existsSync(fileName))fs.unlinkSync(fileName);var walker=new Walker;var self=this;self.fileName=fileName;self.path=path;if(callback)self.complete=callback;if(filter)self.filter=filter;walker.onComplete=function(directory,files){self.directory=directory;self.file=files;self.$compress()};walker.walk(path)};Backup.prototype.$compress=function(){var self=this;var length=self.path.length;var len=0;if(self.directory.length>0){len=self.directory.length;for(var i=0;i0)self.createDirectory(path)}var buffer=new Buffer(value,"base64");zlib.gunzip(buffer,function(err,data){fs.writeFileSync(ph.join(self.path,key),data);buffer=null})};Backup.prototype.createDirectory=function(path,root){if(path[0]==="/")path=path.substring(1);if(path[path.length-1]==="/")path=path.substring(0,path.length-1);var arr=path.split("/");var directory="";var self=this;var length=arr.length;for(var i=0;i0?"/":"")+name;var dir=ph.join(self.path,directory);if(root)dir="/"+dir;if(fs.existsSync(dir))continue;fs.mkdirSync(dir)}};Backup.prototype.clear=function(path,callback,filter){var self=this;var walker=new Walker;walker.options.addEmptyDirectory=true;if(callback)self.complete=callback;if(filter)self.filter=filter;walker.onComplete=function(directory,files){self.file=[];self.directory=[];if(typeof filter!=="function")filter=function(o){return true};var length=files.length;for(var i=0;i + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to permit +persons to whom the Software is furnished to do so, subject to the +following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/minify/node-backup/package.json b/minify/node-backup/package.json new file mode 100644 index 0000000..ac0564f --- /dev/null +++ b/minify/node-backup/package.json @@ -0,0 +1,25 @@ +{ + "name": "backup", + "version": "1.1.0", + "description": "Web Site backup & restore", + "main": "./index.js", + "keywords": ["backup", "restore", "project", "application", "files", "directories"], + "engines": { + "node": ">=0.8.0" + }, + "readmeFilename": "readme.md", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/petersirka/node-backup.git" + }, + "author": { + "name": "Peter Širka" + }, + "bin": { + "backup": "./bin/backup", + "restore": "./bin/restore" + } +} \ No newline at end of file diff --git a/minify/node-backup/readme.md b/minify/node-backup/readme.md new file mode 100644 index 0000000..a811265 --- /dev/null +++ b/minify/node-backup/readme.md @@ -0,0 +1,81 @@ +[![Backup & Restore](http://partialjs.com/exports/backup-logo.png)](https://github.com/petersirka/backup) + +node.js Backup & Restore +======================== + +Easy Backup & Restore web site project. All files and directories are written to one file (and files are compressed via GZIP). + +* Backup file is text file +* Supports backup and restore: files and directories +* Simple filtering files and directories +* Simple structure +* Easy manipulation +* Easy use in your project +* Executables *backup* and *restore* from terminal +* __No dependencies__ + +## Installation + +``` +$ sudo npm install -g backup + +// or + +$ npm install backup +``` + +## node.js + +```js +var backup = require('backup'); + +/* + Backup directory to file + + @directory {String} + @filename {String}, + @complete {Function} :: optional, param: @err {Error}, @filename {String} + @filter {Function} :: optional, param: @path {String} return TRUE | FALSE, if FALSE file or directory will be skipped +*/ +backup.backup('/path/to/directory/', '/users/petersirka/desktop/website.backup'); + +/* + Restore from file + + @filename {String}, + @directory {String} + @complete {Function} :: optional, param: @err {Error}, @path {String} + @filter {Function} :: optional, param: @path {String} return TRUE | FALSE, if FALSE file or directory will be skipped +*/ +backup.restore('/users/petersirka/desktop/website.backup', '/path/to/directory/'); +``` + +## BINARY + +``` +// backup current directory +// $ backup @filename +$ backup /users/petersirka/desktop/website.backup + +// restore backup file +// $ restore @filename @path +$ restore /users/petersirka/desktop/website.backup /users/petersirka/desktop/ +``` + +## The MIT License + +Copyright (c) 2012-2013 Peter Širka + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +## Recommend + +[partial.js web application framework](https://github.com/petersirka/partial.js) + +## Contact + +[www.petersirka.sk](http://www.petersirka.sk) \ No newline at end of file diff --git a/package.json b/package.json index e6bc5f6..ac0564f 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "backup", - "version": "1.0.1", + "version": "1.1.0", "description": "Web Site backup & restore", "main": "./index.js", - "keywords": ["backup", "restore", "website", "web", "project"], + "keywords": ["backup", "restore", "project", "application", "files", "directories"], "engines": { - "node": ">=0.6.0" + "node": ">=0.8.0" }, "readmeFilename": "readme.md", "scripts": { @@ -13,7 +13,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/petersirka/backup.git" + "url": "https://github.com/petersirka/node-backup.git" }, "author": { "name": "Peter Širka"