mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-18 14:17:30 +00:00
fix: cli options should override package.json options
The first priority from CLI(from user) settings then package.json. Fixed #845
This commit is contained in:
parent
dccb15160d
commit
ecf16bdaa0
@ -10,7 +10,30 @@ test('bad config', async function() {
|
||||
}
|
||||
});
|
||||
|
||||
test('nc(mergeConfig)', function(done) {
|
||||
test('right merging package configuration', async function() {
|
||||
// Omit configuration from output, for simplicity
|
||||
var nc = _.curryRight(_.omit, 2)([
|
||||
'config',
|
||||
'no-package',
|
||||
'parseExtension',
|
||||
'project-homepage',
|
||||
'project-version'
|
||||
]);
|
||||
return mergeConfig({
|
||||
config: path.join(__dirname, '../config_fixture/config.json'),
|
||||
'no-package': true,
|
||||
'project-name': 'cool Documentation'
|
||||
})
|
||||
.then(nc)
|
||||
.then(res => {
|
||||
expect(res).toEqual({
|
||||
'project-name': 'cool Documentation',
|
||||
foo: 'bar'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('nc(mergeConfig)', async function() {
|
||||
// Omit configuration from output, for simplicity
|
||||
var nc = _.curryRight(_.omit, 2)([
|
||||
'config',
|
||||
@ -21,7 +44,7 @@ test('nc(mergeConfig)', function(done) {
|
||||
'project-version'
|
||||
]);
|
||||
|
||||
Promise.all(
|
||||
return Promise.all(
|
||||
[
|
||||
[
|
||||
{ config: path.join(__dirname, '../config_fixture/config.json') },
|
||||
@ -74,7 +97,5 @@ test('nc(mergeConfig)', function(done) {
|
||||
expect(res).toEqual(pair[1]);
|
||||
})
|
||||
)
|
||||
).then(res => {
|
||||
done();
|
||||
});
|
||||
);
|
||||
});
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
var yaml = require('js-yaml'),
|
||||
fs = require('fs'),
|
||||
pify = require('pify'),
|
||||
_ = require('lodash'),
|
||||
readPkgUp = require('read-pkg-up'),
|
||||
path = require('path'),
|
||||
stripComments = require('strip-json-comments');
|
||||
@ -29,7 +28,7 @@ function processToc(config: DocumentationConfig, absFilePath: string) {
|
||||
* values of `name` and `version` config.
|
||||
*
|
||||
* @param {Object} config the user-provided config, usually via argv
|
||||
* @returns {Object} configuration with inferred parameters
|
||||
* @returns {Promise<Object>} configuration with inferred parameters
|
||||
* @throws {Error} if the file cannot be read.
|
||||
*/
|
||||
function mergePackage(config: Object): Promise<Object> {
|
||||
@ -38,16 +37,12 @@ function mergePackage(config: Object): Promise<Object> {
|
||||
}
|
||||
return (
|
||||
readPkgUp()
|
||||
.then(pkg =>
|
||||
_.defaults(
|
||||
{},
|
||||
_.mapKeys(
|
||||
_.pick(pkg.pkg, ['name', 'homepage', 'version']),
|
||||
(val, key) => `project-${key}`
|
||||
),
|
||||
config
|
||||
)
|
||||
)
|
||||
.then(pkg => {
|
||||
['name', 'homepage', 'version'].forEach(key => {
|
||||
config[`project-${key}`] = config[`project-${key}`] || pkg.pkg[key];
|
||||
});
|
||||
return config;
|
||||
})
|
||||
// Allow this to fail: this inference is not required.
|
||||
.catch(() => config)
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user