Skip to content

Commit

Permalink
feat(release): First release
Browse files Browse the repository at this point in the history
First release of the standalone Jenkins plugin compatible sloccount for web projects
  • Loading branch information
asciidisco committed Mar 15, 2016
1 parent 8230738 commit 0893140
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "standard",
"plugins": [
"standard"
]
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ node_modules

# Optional REPL history
.node_repl_history

# test putput data
stats
8 changes: 8 additions & 0 deletions .jscsrc
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
}
20 changes: 20 additions & 0 deletions .travis.yml
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+$/"
23 changes: 23 additions & 0 deletions cli.js
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})
82 changes: 82 additions & 0 deletions index.js
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
}
56 changes: 56 additions & 0 deletions package.json
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"
}
}
}
35 changes: 35 additions & 0 deletions test.js
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)
})

0 comments on commit 0893140

Please sign in to comment.