-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
59 lines (49 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
var utils = require('./lib/utils');
/**
* Sync properties from package.json to bower.json.
*
* @param {String} `patterns` Glob patterns for matching keys.
* @param {Object} `options`
* @return {Object}
*/
function sync(pkg, bower, options) {
var defaults = {remove: utils.remove, omitEmpty: true, knownOnly: true};
var opts = utils.extend(defaults, options);
var config = utils.extend({}, bower, pkg);
// pre-process `author` so we can use the built-in
// author normalizer in `normalize-pkg`
authors(config);
// add custom fields to the schema
var normalizer = new utils.Normalizer(opts)
.field('private', 'boolean')
.field('ignore', ['array', 'string'], {
default: utils.ignore,
normalize: function(val, key, config) {
return utils.arrayify(val);
}
})
.field('main', ['array', 'string'], {
normalize: function(val, key, config) {
return utils.arrayify(val);
}
});
normalizer.schema.omit('engines');
normalizer.schema.omit('scripts');
normalizer.schema.omit('author');
var res = normalizer.normalize(config);
return utils.omit(res, utils.remove);
};
function authors(config) {
if (typeof config.authors === 'undefined') {
config.authors = utils.arrayify(config.author);
delete config.author;
}
}
sync.bower = function() {
return sync.apply(null, arguments);
};
/**
* Expose `sync`
*/
module.exports = sync;