Skip to content

Commit

Permalink
ready for release
Browse files Browse the repository at this point in the history
  • Loading branch information
charliedowler committed Sep 22, 2014
1 parent 0148d32 commit 8792355
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.idea/
.idea/
warning
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Type: `Number`
Set the year

## Release History
- 2014-09-21 v0.1.0 Initial release
- 2014-09-22 v0.1.0 Initial release

[travis-url]: http://travis-ci.org/charliedowler/cal
[travis-image]: https://secure.travis-ci.org/charliedowler/cal.png?branch=master
83 changes: 48 additions & 35 deletions cli.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,46 +1,59 @@
#!/usr/bin/env node
var argv = require('minimist')(process.argv.slice(2));
var Cal = require('./');
var table = require('text-table');
var _ = require('underscore');
var cal = new Cal();
var fs = require('fs');
var colors = require('colors');

if (argv.m && typeof argv.m == 'number') {
cal.setMonth(argv.m);
}
else if (argv.y && typeof argv.y == 'number') {
cal.setYear(argv.y);
}
fs.exists('./warning', function(exists) {
if (!exists && !argv.i) {
console.log('======================================'.yellow);
console.log('| This overwrote the existing cal |'.yellow);
console.log('| command type npm uninstall -g |'.yellow);
console.log('| to undo this change. |'.yellow);
console.log('======================================'.yellow);
fs.writeFile('./warning');
}
if (argv.m && typeof argv.m == 'number') {
cal.setMonth(argv.m);
}
else if (argv.y && typeof argv.y == 'number') {
cal.setYear(argv.y);
}

var days = cal.daysOfWeek.map(function(day) {
return day.substring(0, 2);
});
var firstDay = cal.getFirstDayOfMonth().substring(0, 2);
var days = cal.daysOfWeek.map(function(day) {
return day.substring(0, 2);
});
var firstDay = cal.getFirstDayOfMonth().substring(0, 2);

var header = table([[' ', cal.getMonth() + ' ' + cal.getYear(), ' ']], { align: [ 'c' ] });
var c = function() {
var startDay = 0;
var arr = [];
for (var day = 1; day <= cal.getDaysThisMonth(); day++) {
arr.push(day);
}
_.filter(days, function(day, index) {
if (day == firstDay) {
startDay = index;
var header = table([[ ' ', cal.getMonth() + ' ' + cal.getYear(), ' ']], { align: [ 'c', 'c', 'c'] });
var c = function() {
var startDay = 0;
var arr = [];
for (var day = 1; day <= cal.getDaysThisMonth(); day++) {
arr.push(day);
}
});
for(var i =0;i<startDay;i++) {
arr.unshift(' ');
_.filter(days, function(day, index) {
if (day == firstDay) {
startDay = index;
}
});
for(var i =0;i<startDay;i++) {
arr.unshift(' ');
}
var lists = _.groupBy(arr, function(element, index){
return Math.floor(index/7);
});
return _.toArray(lists);
}();
var calendar = [days];
for (var i in c) {
calendar.push(c[i]);
}
var lists = _.groupBy(arr, function(element, index){
return Math.floor(index/7);
});
return _.toArray(lists);
}();
var calendar = [days];
for (var i in c) {
calendar.push(c[i]);
}
calendar = table(calendar, { hsep: ' ', align: ['r', 'r', 'r', 'r', 'r', 'r', 'r'] });
calendar = table(calendar, { hsep: ' ', align: ['r', 'r', 'r', 'r', 'r', 'r', 'r'] });

console.log(header);
console.log(calendar)
console.log(header);
console.log(calendar);
});
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cal",
"version": "0.1.0",
"description": "Better version of cal",
"version": "0.0.1",
"description": "Better version of cal (WIP)",
"main": "index.js",
"scripts": {
"test": "node test/main"
Expand All @@ -20,9 +20,13 @@
"minimist": "~0.2.0",
"text-table": "~0.2.0",
"minimist": "~1.1.0",
"underscore": "~1.7.0"
"underscore": "~1.7.0",
"colors": "~0.6.2"
},
"devDependencies": {
"tap": "~0.4.12"
},
"bin": {
"cal": "./cli.js"
}
}
2 changes: 1 addition & 1 deletion test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('cal', function (runner) {
runner.equal(cal.getMonth(), 'August', 'cal.getMonth() returns August');
cal.setMonth(9);
runner.equal(cal.getMonth(), 'September', 'cal.setMonth(9) sets month to September');
exec('node ./cli', function (err, stdout, stderr) {
exec('node ./cli -i', function (err, stdout, stderr) {
stdout = stdout.replace('September 2014\n', '');
stdout = stdout.trim();
runner.equal(stdout, table([
Expand Down

0 comments on commit 8792355

Please sign in to comment.