Permalink
Browse files

implement timer and options

  • Loading branch information...
1 parent 26b47b5 commit 2779f84149b576fa649743bb775aa33f551e184f @jamesbloomer committed Aug 26, 2012
Showing with 78 additions and 46 deletions.
  1. +22 −0 LICENCE
  2. +3 −1 README.md
  3. +16 −34 flashfreeze.js
  4. +25 −0 lib/flashfreeze.js
  5. +1 −1 package.json
  6. +11 −10 test/flashfreeze_test.js
View
22 LICENCE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2012 James Bloomer <https://github.com/jamesbloomer>
+
+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.
View
4 README.md
@@ -1,2 +1,4 @@
flashfreeze
-===========
+===========
+
+....not ready to use yet.
View
50 flashfreeze.js
@@ -1,34 +1,16 @@
-var watcher = require('directory-tree-watcher');
-
-var flashfreeze = {};
-
-flashfreeze.start = function(folder) {
-
- console.log(folder);
-
- // TODO check folder is a git repo
-
- flashfreeze.watch(folder, function(evt, file) {
- return console.log("watcher:", evt, file);
- });
-
- // Must be a better way to hang around than this?
- // Note that SIGINT doesn't work on Windows
- var readline = require('readline'),
- rl = readline.createInterface(process.stdin, process.stdout);
- rl.setPrompt('Running...');
- rl.prompt();
-
- rl.on('close', function() {
- console.log('Closing...');
- process.exit(0);
- });
-};
-
-flashfreeze.watch = function(folder, callback) {
- watcher(folder, callback);
-};
-
-flashfreeze.start(process.argv[2]);
-
-module.exports = flashfreeze;
+var program = require('commander'),
+ flashfreeze = require('./lib/flashfreeze.js');
+
+program
+ .version('0.0.1')
+ .option('-f, --folder <folder>', 'Folder to commit')
+ .option('-i, --interval <interval>', 'Interval at which to commit in minutes [15]', Number, 15)
+ .parse(process.argv);
+
+// Can commander do this for free?
+if(!program.folder) {
+ console.log('Must provide a folder');
+ process.exit(0);
+}
+
+flashfreeze.start(program.folder, program.interval);
View
25 lib/flashfreeze.js
@@ -0,0 +1,25 @@
+var program = require('commander');
+
+var flashfreeze = {};
+
+flashfreeze.start = function(folder, interval) {
+
+ console.log('will commit folder ' + folder + ' every ' + interval + ' minutes');
+
+ // TODO check folder is valid
+
+ setInterval(flashfreeze.commit, interval * 60 * 1000);
+};
+
+flashfreeze.commit = function(folder) {
+ // TODO do the commit
+ console.log('commit');
+};
+
+program
+ .version('0.0.1')
+ .option('-f, --folder <folder>', 'Folder to commit')
+ .option('-i, --interval <interval>', 'Interval at which to commit in minutes [15]', Number, 15)
+ .parse(process.argv);
+
+module.exports = flashfreeze;
View
2 package.json
@@ -13,7 +13,7 @@
},
"keywords": [""],
"dependencies": {
- "directory-tree-watcher" : "0.1.0"
+ "commander": "1.0.2"
},
"devDependencies" : {
"mocha" : "x.x.x",
View
21 test/flashfreeze_test.js
@@ -1,26 +1,27 @@
var assert = require('assert'),
- flashfreeze = require('../flashfreeze.js'),
+ flashfreeze = require('../lib/flashfreeze.js'),
mocha = require('mocha'),
- watcher = require('directory-tree-watcher'),
sinon = require('sinon');
describe('flashfreeze', function() {
describe('#start()', function() {
+ var clock;
beforeEach(function(){
- sinon.stub(flashfreeze, 'watch').yields('EVENT', 'FILE');
+ sinon.stub(flashfreeze, 'commit');
+ clock = sinon.useFakeTimers();
});
afterEach(function(){
- flashfreeze.watch.restore();
+ flashfreeze.commit.restore();
+ clock.restore();
});
- it('should start watching the folder passed in', function(done) {
- flashfreeze.start('FOLDER', function() {
- // TODO need to stop the readline
- assert(flashfreeze.watch.calledOnce());
- done();
- });
+ it('should call commit once timer has elapsed', function(done) {
+ flashfreeze.start('FOLDER', 1);
+ clock.tick(60 * 1000);
+ assert(flashfreeze.commit.calledOnce);
+ done();
});
});
});

0 comments on commit 2779f84

Please sign in to comment.