From 95d8ea7e0c1c2311999a021e6e319a120b816b99 Mon Sep 17 00:00:00 2001 From: chinesedfan Date: Fri, 29 Apr 2016 16:14:37 +0800 Subject: [PATCH 1/2] support to specify another file as `cortex.json` --- README.md | 4 +++- index.js | 12 +++++++++++- test/fixtures/mycortex.json | 35 +++++++++++++++++++++++++++++++++++ test/read-cortex-json.js | 12 ++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/mycortex.json diff --git a/README.md b/README.md index 9f16cf1..f804cc9 100644 --- a/README.md +++ b/README.md @@ -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 use as `cortex.json` directly. + ### cortexJson.clean(cwd, json, callback) Cleans and validate the `json`. diff --git a/index.js b/index.js index 0a49cd4..f710ffa 100644 --- a/index.js +++ b/index.js @@ -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); }; diff --git a/test/fixtures/mycortex.json b/test/fixtures/mycortex.json new file mode 100644 index 0000000..fa6a668 --- /dev/null +++ b/test/fixtures/mycortex.json @@ -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" +} diff --git a/test/read-cortex-json.js b/test/read-cortex-json.js index 4bd230f..dd199dc 100644 --- a/test/read-cortex-json.js +++ b/test/read-cortex-json.js @@ -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'; From 011f023bef3fd1b60984809e7a7acc2bd58fec99 Mon Sep 17 00:00:00 2001 From: chinesedfan Date: Fri, 29 Apr 2016 16:43:37 +0800 Subject: [PATCH 2/2] fix the grammer --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f804cc9..e7c3f1a 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ cortexJson.read('/path/to/your/repo', function(err, json){ 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 use as `cortex.json` directly. +If `options.file` is provided, it will be used as `cortex.json` directly. ### cortexJson.clean(cwd, json, callback)