Skip to content

Commit

Permalink
Wip (#6)
Browse files Browse the repository at this point in the history
* adding red on major revision change

* add dependency status

* add coverage for dokuwiki
  • Loading branch information
cizer committed May 18, 2016
1 parent e45156a commit 2e34f8d
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 113 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![npm stable version](https://img.shields.io/npm/v/ncu-report.svg?label=npm)](https://npmjs.org/package/ncu-report)
[![Build Status](https://travis-ci.org/cizer/ncu-report.svg?branch=master)](https://travis-ci.org/cizer/ncu-report)
[![Dependency Status](https://david-dm.org/cizer/ncu-report.svg)](https://david-dm.org/cizer/ncu-report)

# ncu-report
A report generator that produces a table showing which packages require updating. The report is generated in markdown (and optionally dokuwiki) format and can be integrated into your build.
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var reportService = require('./reportService');
var vm = require('npm-check-updates/lib/versionmanager');

program
.version('0.0.8')
.version('0.1.0')
.option('-m, --packageManager <name>', 'npm (default) | bower', 'npm')
.option('-o, --outputFile <filename>', '.\/ncu-report\/ncu-report.md (default)')
.option('-f, --format <name>', 'markdown (default) | dokuwiki', 'markdown')
Expand Down
131 changes: 70 additions & 61 deletions lib/tableGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,91 @@ var dateformat = require('dateformat');

var format = function(packageList, format) {

var table = [];
if (!packageList || packageList.length === 0) {
table.push("No data.");
return table;
}

switch (format) {
case 'dokuwiki':
return formatDokuWiki(packageList);
default: //markdown
return formatMarkdown(packageList);
}
var table = [];
if (!packageList || packageList.length === 0) {
table.push("No data.");
return table;
}

switch (format) {
case 'dokuwiki':
return formatDokuWiki(packageList);
default: //markdown
return formatMarkdown(packageList);
}
}

function formatMarkdown(packageList) {

var table = [];
table.push("| Package | Current | Installed | Latest | Status |");
table.push("| :------ | ------: | --------: | -----: | :----: |");

packageList.forEach(function(package) {
package.status = "OUTDATED";
if (isLatestPackage(package.version.installed, package.version.new)) {
package.status = "OK";
package.version.new = package.version.current;
}

table.push("| " + package.name + " | " +
package.version.current + " | " +
package.version.installed + " | " +
package.version.new + " | " +
package.status + " |");

});
table.push('<sup><sub>Report generated on: ' + Date() + '<sub><sup>');
return table;
var table = [];
table.push("| Package | Current | Installed | Latest | Status |");
table.push("| :------ | ------: | --------: | -----: | :----: |");

packageList.forEach(function(package) {
package.status = "OUTDATED";
if (isLatestPackage(package.version.installed, package.version.new)) {
package.status = "OK";
package.version.new = package.version.current;
}

table.push("| " + package.name + " | " +
package.version.current + " | " +
package.version.installed + " | " +
package.version.new + " | " +
package.status + " |");

});
table.push('<sup><sub>Report generated on: ' + Date() + '<sub><sup>');
return table;
}

function formatDokuWiki(packageList) {
var table = [];
table.push("| Package ^ Current ^ Installed ^ Latest ^ Status ^");

packageList.forEach(function(package) {
var installedColor;
package.status = "OUTDATED";
if (isLatestPackage(package.version.installed, package.version.new)) {
package.status = "OK";
installedColor = '@green:';
package.version.new = package.version.current;
} else if (isMajorUpdate(package.version.installed, package.version.new)) {
installedColor = '@red:';
} else {
installedColor = '@orange:';
}

table.push("^ " + escapeCarat(package.name + " | " +
package.version.current + " | " +
installedColor + package.version.installed + " | " +
package.version.new + " | " + package.status + " |"));

});

table.push('^ Report generated on: ' + Date() + '|||||');
return table;

var table = [];
table.push("| Package ^ Current ^ Installed ^ Latest ^ Status ^");

packageList.forEach(function(package) {
var installedColor;
if (isLatestPackage(package.version.installed, package.version.new)) {
package.status = "OK";
installedColor = '@green:';
package.version.new = package.version.current;
} else {
package.status = "OUTDATED";
installedColor = '@orange:';
}

table.push("^ " + escapeCarat(package.name + " | " +
package.version.current + " | " +
installedColor + package.version.installed + " | " +
package.version.new + " | " + package.status + " |"));

});
};

table.push('^ Report generated on: ' + Date() + '|||||');
function isLatestPackage(installedVersion, newVersion) {
return !newVersion || newVersion === installedVersion;
}

return table;
function escapeCarat(version) {
return version.toString().replace(/\^/g, "%%^%%");
}

};
function isMajorUpdate(installedVersion, newVersion) {
var installedMajorVersion = installedVersion.split('.')[0]
.toString().replace('^', '');

function isLatestPackage(installedVersion, newVersion){
return !newVersion || newVersion === installedVersion;
}
var newMajorVersion = newVersion.split('.')[0]
.toString().replace('^', '');

function escapeCarat(version){
return version.toString().replace(/\^/g, "%%^%%");
return (newMajorVersion > installedMajorVersion);
}

module.exports = {
format: format
format: format
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "ncu-report",
"version": "0.0.11",
"version": "0.1.0",
"description": "A utility that formats the output of ncu in markdown format",
"main": "./lib/index.js",
"scripts": {
"test": "./node_modules/jasmine-node/bin/jasmine-node spec"
"test": "istanbul cover --include-all-sources jasmine-node spec"
},
"bin": {
"ncu-report": "./lib/index.js"
Expand All @@ -18,6 +18,7 @@
"path": "^0.12.7"
},
"devDependencies": {
"istanbul": "^0.4.3",
"jasmine-node": "^1.14.5",
"proxyquire": "^1.7.4"
}
Expand Down
142 changes: 93 additions & 49 deletions spec/tableGenerator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,109 @@

describe("format", function() {

var generator = require("../lib/tableGenerator"),
result;
var service = require('../lib/tableGenerator'),
result, testPackageList;

describe("when called with invalid data", function() {
describe("when called with invalid data", function() {

it("no params", function() {
result = generator.format();
expect(result[0]).toBe("No data.");
});
it("no params", function() {
result = service.format();
expect(result[0]).toBe("No data.");
});

it("empty array", function() {
result = generator.format([]);
expect(result[0]).toBe("No data.");
it("empty array", function() {
result = service.format([]);
expect(result[0]).toBe("No data.");
});
});

});

describe("when called with valid list", function() {

beforeEach(function() {

result = generator.format([{
name: "outdated1",
version: {
current: 1,
installed: 1.5,
new: 2
}
}, {
name: "outdated2",
version: {
current: 2,
installed: 2.5,
new: 3
}
}, {
name: "ok1",
version: {
current: '^4',
installed: 4
}
}]);
});
describe("when called with valid list", function() {

it("return table header", function() {
expect(result[0]).toBe("| Package | Current | Installed | Latest | Status |");
});
beforeEach(function() {
testPackageList = [{
name: "outdated1",
version: {
current: '1.0',
installed: '1.5',
new: '2.0'
}
}, {
name: "outdated2",
version: {
current: '2.0',
installed: '2.5',
new: '3.0'
}
}, {
name: "ok1",
version: {
current: '^4.0',
installed: '4.0'
}
}];
result = service.format(testPackageList);
});

it("returns valid formatted table item (line1)", function() {
expect(result[2]).toBe("| outdated1 | 1 | 1.5 | 2 | OUTDATED |");
});
it("return table header", function() {
expect(result[0]).toBe("| Package | Current | Installed | Latest | Status |");
});

it("returns valid formatted table item (line1)", function() {
expect(result[2]).toBe("| outdated1 | 1.0 | 1.5 | 2.0 | OUTDATED |");
});

it("returns valid formatted table item (line2)", function() {
expect(result[3]).toBe("| outdated2 | 2.0 | 2.5 | 3.0 | OUTDATED |");
});

it("returns valid formatted table item (line2)", function() {
expect(result[3]).toBe("| outdated2 | 2 | 2.5 | 3 | OUTDATED |");
it("returns valid formatted table item (line3)", function() {
expect(result[4]).toBe("| ok1 | ^4.0 | 4.0 | ^4.0 | OK |");
});
});

it("returns valid formatted table item (line3)", function() {
expect(result[4]).toBe("| ok1 | ^4 | 4 | ^4 | OK |");

describe("when called with valid list and docuwiki format", function() {

beforeEach(function() {
testPackageList = [{
name: "outdated1",
version: {
current: '1.0',
installed: '1.5',
new: '2.0'
}
}, {
name: "outdated2",
version: {
current: '2.0',
installed: '2.5',
new: '3.0'
}
}, {
name: "ok1",
version: {
current: '^4.0',
installed: '4.0'
}
}];
result = service.format(testPackageList, 'dokuwiki');
});

it("return table header", function() {
expect(result[0]).toBe("| Package ^ Current ^ Installed ^ Latest ^ Status ^");
});

it("returns valid formatted table item (line1)", function() {
expect(result[1]).toBe("^ outdated1 | 1.0 | @red:1.5 | 2.0 | OUTDATED |");
});

it("returns valid formatted table item (line2)", function() {
expect(result[2]).toBe("^ outdated2 | 2.0 | @red:2.5 | 3.0 | OUTDATED |");
});

it("returns valid formatted table item (line3)", function() {
expect(result[3]).toBe("^ ok1 | %%^%%4.0 | @green:4.0 | %%^%%4.0 | OK |");
});
});
});

});

0 comments on commit 2e34f8d

Please sign in to comment.