-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First release of the standalone Jenkins plugin compatible sloccount for web projects
- Loading branch information
1 parent
8230738
commit 0893140
Showing
8 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "standard", | ||
"plugins": [ | ||
"standard" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,6 @@ node_modules | |
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# test putput data | ||
stats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"preset": "node-style-guide", | ||
"requireCurlyBraces": null, | ||
"maximumLineLength": null, | ||
"requireCapitalizedComments": null, | ||
"disallowSpacesInFunction": null, | ||
"requireTrailingComma": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
sudo: false | ||
language: node_js | ||
cache: | ||
directories: | ||
- node_modules | ||
notifications: | ||
email: false | ||
node_js: | ||
- '4' | ||
before_install: | ||
- npm i -g npm@^2.0.0 | ||
before_script: | ||
- npm prune | ||
script: | ||
- npm test | ||
after_success: | ||
- npm run semantic-release | ||
branches: | ||
except: | ||
- "/^v\\d+\\.\\d+\\.\\d+$/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env node | ||
'use strict' | ||
var meow = require('meow') | ||
var sloccount = require('./') | ||
|
||
var cli = meow('\n' + | ||
'Usage\n' + | ||
' $ sloccount <src> <reportPath>\n' + | ||
'\n' + | ||
'Options\n' + | ||
' -c, --comments Exclude comments\n' + | ||
' -v, --verbose Verbose output\n' + | ||
'\n' + | ||
' Examples\n' + | ||
' $ sloccount *.js report.sc --comments\n' + | ||
'', { | ||
alias: { | ||
c: 'comments', | ||
v: 'verbose' | ||
} | ||
}) | ||
|
||
sloccount({src: cli.input[0], reportPath: cli.input[1], comments: !!cli.flags.c, verbose: !!cli.flags.v}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* grunt-sloccount | ||
* https://github.com/asciidisco/sloccount | ||
* | ||
* Copyright (c) 2016 Sebastian Golasch | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
'use strict' | ||
|
||
var path = require('path') | ||
var fs = require('fs') | ||
var sloc = require('sloc') | ||
var glob = require('glob') | ||
var mkdirp = require('mkdirp') | ||
|
||
module.exports = function (options) { | ||
options = options || {} | ||
// check for src directories | ||
if (!options.src) { | ||
throw Error('Please configure one or more src directories!') | ||
} | ||
|
||
var filesToMatch = glob.sync(options.src) | ||
var folders = [] | ||
// generate flat list of folders | ||
var map = {} | ||
filesToMatch.forEach(function (currentValue) { | ||
var cv = path.dirname(currentValue) | ||
if (!map[cv]) { | ||
map[cv] = true | ||
folders.push(cv) | ||
} | ||
}) | ||
|
||
// check if path fpr report file is given & exists | ||
if (options.reportPath) mkdirp.sync(path.dirname(options.reportPath)) | ||
|
||
// clear file | ||
if (options.reportPath) fs.writeFileSync(options.reportPath, '') | ||
|
||
// write (dynamic) intro for file | ||
folders.forEach(function (folder) { | ||
if (folder === '.') folder = process.cwd() | ||
var startLine = 'Creating filelist for ' + folder | ||
if (options.reportPath) fs.appendFileSync(options.reportPath, startLine + '\n', 'utf8') | ||
if (!options.reportPath || options.verbose) console.log(startLine) | ||
}) | ||
|
||
// write (static) intro for file | ||
var sndTrail = 'Categorizing files.' | ||
var thrdTrail = 'Computing results.' | ||
var fourthTrail = '\n' | ||
if (options.reportPath) fs.appendFileSync(options.reportPath, sndTrail + '\n', 'utf8') | ||
if (options.reportPath) fs.appendFileSync(options.reportPath, thrdTrail + '\n', 'utf8') | ||
if (options.reportPath) fs.appendFileSync(options.reportPath, fourthTrail + '\n', 'utf8') | ||
if (!options.reportPath || options.verbose) console.log(sndTrail) | ||
if (!options.reportPath || options.verbose) console.log(thrdTrail) | ||
if (!options.reportPath || options.verbose) console.log(fourthTrail) | ||
|
||
var fileContents, stats, extname | ||
filesToMatch.forEach(function (file) { | ||
extname = path.extname(file).replace('.', '') | ||
fileContents = fs.readFileSync(file, 'utf8') | ||
if (extname === 'js' || extname === 'css' || extname === 'scss' || extname === 'html') { | ||
stats = sloc(fileContents, extname) | ||
var fileStats = stats.source + '\t' + extname + '\t' + (path.dirname(file) === '.' ? process.cwd() : path.dirname(file)) + '\t' + fs.realpathSync(file) | ||
if (options.reportPath) fs.appendFileSync(options.reportPath, fileStats + '\n', 'utf8') | ||
if (!options.reportPath || options.verbose) console.log(fileStats) | ||
|
||
// check if comments should be tracked seperatly | ||
if (options.comments !== false) { | ||
var commentStats = stats.comment + '\t' + extname + 'cm' + '\t' + (path.dirname(file) === '.' ? process.cwd() : path.dirname(file)) + '\t' + fs.realpathSync(file) + '.cm' | ||
if (options.reportPath) fs.appendFileSync(options.reportPath, commentStats + '\n', 'utf8') | ||
if (!options.reportPath || options.verbose) console.log(commentStats) | ||
} | ||
} | ||
}) | ||
|
||
if (options.reportPath && options.verbose) console.log('Report File: ' + options.reportPath + ' written!') | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"name": "sloccount", | ||
"version": "0.0.0-semantically-released", | ||
"description": "Counts lines of code of HTML, CSS & JS - Outputs them in a Jenkins compatible format", | ||
"main": "index.js", | ||
"bin": { | ||
"sloccount": "./cli.js" | ||
}, | ||
"preferGlobal": true, | ||
"scripts": { | ||
"test": "istanbul cover -x test.js tape -- test.js && rimraf stats", | ||
"lint": "eslint ./*.js && jscs ./*.js", | ||
"pretest": "npm run lint", | ||
"precommit": "npm test", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/asciidisco/sloccount.git" | ||
}, | ||
"keywords": [ | ||
"sloc", | ||
"sloccount" | ||
], | ||
"author": "Sebastian Golasch", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/asciidisco/sloccount/issues" | ||
}, | ||
"homepage": "https://github.com/asciidisco/sloccount#readme", | ||
"dependencies": { | ||
"glob": "7.0.3", | ||
"meow": "3.7.0", | ||
"mkdirp": "0.5.1", | ||
"sloc": "0.1.10" | ||
}, | ||
"devDependencies": { | ||
"commitizen": "2.7.2", | ||
"cz-conventional-changelog": "1.1.5", | ||
"eslint": "2.4.0", | ||
"eslint-config-standard": "5.1.0", | ||
"eslint-plugin-standard": "1.3.2", | ||
"husky": "0.11.3", | ||
"istanbul": "0.4.2", | ||
"jscs": "2.11.0", | ||
"rimraf": "2.5.2", | ||
"standard": "6.0.8", | ||
"tape": "4.5.1", | ||
"semantic-release": "^4.3.5" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict' | ||
var test = require('tape') | ||
var sloccount = require('./') | ||
var fs = require('fs') | ||
|
||
test('can count get lines of the index.js file (without comments)', function (t) { | ||
t.plan(4) | ||
sloccount({src: './index.js', reportPath: 'stats/report.sc', comments: false, verbose: false}) | ||
|
||
var contents = fs.readFileSync('stats/report.sc', 'utf-8') | ||
t.equal(contents.indexOf('Categorizing files.') !== -1, true) | ||
t.equal(contents.indexOf('Computing results.') !== -1, true) | ||
t.equal(contents.indexOf('57 js') !== -1, true) | ||
t.equal(contents.indexOf('sloccount/index.js') !== -1, true) | ||
}) | ||
|
||
test('can count get lines of the index.js file (with comments)', function (t) { | ||
t.plan(6) | ||
sloccount({src: './index.js', reportPath: 'stats/report.sc', comments: true, verbose: false}) | ||
|
||
var contents = fs.readFileSync('stats/report.sc', 'utf-8') | ||
t.equal(contents.indexOf('Categorizing files.') !== -1, true) | ||
t.equal(contents.indexOf('Computing results.') !== -1, true) | ||
t.equal(contents.indexOf('57 js') !== -1, true) | ||
t.equal(contents.indexOf('sloccount/index.js') !== -1, true) | ||
t.equal(contents.indexOf('14 jscm') !== -1, true) | ||
t.equal(contents.indexOf('sloccount/index.js.cm') !== -1, true) | ||
}) | ||
|
||
test('throws if no source directory is given', function (t) { | ||
t.plan(1) | ||
t.throws(function () { | ||
sloccount() | ||
}, Error) | ||
}) |