Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ cortexJson.read('/path/to/your/repo', function(err, json){
});
```

### cortexJson.extra(cwd, callback)
### cortexJson.extra(cwd, [options,] callback)

This method is different from `cortexJson.read()` that it will validate some stuff and flavors the object with some default values which cortex registry needs.

If `options.file` is provided, it will be used as `cortex.json` directly.

### cortexJson.clean(cwd, json, callback)

Cleans and validate the `json`.
Expand Down
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,17 @@ exports.read = function(cwd, callback, use_inherits) {
};


exports.extra = function (cwd, callback) {
exports.extra = function (cwd, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}

if (options.file) {
// just read this file as `cortex.json`
read(options.file, callback);
return;
}
exports._extra(cwd, callback);
};

Expand Down
35 changes: 35 additions & 0 deletions test/fixtures/mycortex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "myfoo",
"version": "1.0.0",
"description": "test package",
"keywords": [
"cortex",
"commonjs",
"dev",
"development",
"package",
"manager",
"web",
"server",
"scaffold"
],
"author": "kael",
"dependencies": {
"bar": "~2.0.0"
},
"engines": {
},
"bin": {
"cortex": "bin/cortex-cli.js"
},
"devDependencies": {
},
"scripts": {
"prebuild": "grunt"
},
"repository": {
"type": "git",
"url": "git@github.com:kaelzhang/cortex.git"
},
"license": "MIT"
}
12 changes: 12 additions & 0 deletions test/read-cortex-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ describe("helper.read(cwd)", function() {
});


describe("helper.extra(cwd)", function() {
it("will use options.file if provided", function(done) {
var dir = make(['mycortex.json']);

helper.extra(dir, {file: node_path.join(dir, 'mycortex.json')}, function(err, helper) {
expect(helper.name).to.equal('myfoo');
done();
});
});
});


describe("helper.save(cwd, json)", function() {
var new_version = '10.3.4';

Expand Down