Skip to content

Commit 63808b3

Browse files
committed
first commit
0 parents  commit 63808b3

File tree

11 files changed

+157
-0
lines changed

11 files changed

+157
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
coverage.*

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
test:
2+
@node node_modules/lab/bin/lab
3+
test-cov:
4+
@node node_modules/lab/bin/lab -t 100
5+
test-cov-html:
6+
@node node_modules/lab/bin/lab -r html -o coverage.html
7+
8+
.PHONY: test test-cov test-cov-html

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib');

lib/index.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Load modules
2+
3+
var Fs = require('fs');
4+
var Path = require('path');
5+
var Cp = require('child_process');
6+
7+
8+
// Declare internals
9+
10+
var internals = {};
11+
12+
13+
exports.registerHook = function (filename) {
14+
};
15+
16+
17+
exports.addFile = function (filename, path) {
18+
};
19+
20+
21+
exports.deleteFile = function (filename, path) {
22+
};
23+
24+
25+
exports.findGitRoot = function (callback) {
26+
27+
Cp.exec('git rev-parse --show-toplevel', function (err, stderr) {
28+
29+
callback(err, stderr.trim());
30+
});
31+
};
32+
33+
34+
exports.findProjectRoot = function (callback) {
35+
36+
var path = __dirname.slice(0, __dirname.indexOf('node_modules'));
37+
callback(null, path);
38+
};
39+
40+
41+
internals.isDir = function (path) {
42+
43+
var stat = Fs.statSync(path);
44+
return stat.isDirectory();
45+
};
46+
47+
48+
exports.findProjects = function (root, depth) {
49+
50+
depth = depth || 0;
51+
++depth;
52+
53+
if (depth > 4 ||
54+
// !internals.isDir(root)) {
55+
!internals.isDir(root) ||
56+
root.indexOf('node_modules') !== -1) {
57+
58+
return [];
59+
}
60+
61+
var dirs = Fs.readdirSync(root);
62+
var projects = [];
63+
64+
for (var i = 0, il = dirs.length; i < il; ++i) {
65+
var dir = dirs[i];
66+
var path = Path.join(root, dir);
67+
68+
if (Fs.existsSync(Path.join(path, 'package.json'))) {
69+
projects.push(path);
70+
}
71+
else {
72+
projects = projects.concat(exports.findProjects(path, depth));
73+
}
74+
}
75+
76+
return projects;
77+
};

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "commit-thingy",
3+
"version": "0.0.0",
4+
"description": "the extensible core of precommit-hook",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "make test-cov"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git://github.com/nlf/commit-thingy.git"
12+
},
13+
"keywords": [
14+
"precommit",
15+
"pre-commit",
16+
"git",
17+
"hook"
18+
],
19+
"author": "Nathan LaFreniere <[email protected]>",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/nlf/commit-thingy/issues"
23+
},
24+
"homepage": "https://github.com/nlf/commit-thingy",
25+
"devDependencies": {
26+
"lab": "^3.2.3"
27+
}
28+
}

test/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var Hook = require('../');
2+
var Path = require('path');
3+
4+
var Lab = require('lab');
5+
6+
var lab = exports.lab = Lab.script();
7+
var expect = Lab.expect;
8+
var describe = lab.experiment;
9+
var it = lab.test;
10+
11+
describe('exports', function () {
12+
13+
it('can find a git root', function (done) {
14+
15+
Hook.findGitRoot(function (err, root) {
16+
17+
expect(err).to.not.exist;
18+
expect(root).to.be.a('string');
19+
done();
20+
});
21+
});
22+
23+
it('can find a project root', function (done) {
24+
25+
Hook.findProjectRoot(function (err, root) {
26+
27+
expect(err).to.not.exist;
28+
expect(root).to.be.a('string');
29+
done();
30+
});
31+
});
32+
33+
it('can find projects', function (done) {
34+
35+
var projects = Hook.findProjects(Path.join(__dirname, 'projects'));
36+
37+
expect(projects).to.be.an('array');
38+
expect(projects).to.have.length(4);
39+
done();
40+
});
41+
});

test/projects/project1/package.json

Whitespace-only changes.

test/projects/project2/package.json

Whitespace-only changes.

test/projects/project3/api/package.json

Whitespace-only changes.

test/projects/project4/even/deeper/thing/package.json

Whitespace-only changes.

test/projects/project5/should/never/be/found/because/depth/package.json

Whitespace-only changes.

0 commit comments

Comments
 (0)