forked from jonschlinkert/normalize-pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.js
More file actions
133 lines (114 loc) · 3.13 KB
/
schema.js
File metadata and controls
133 lines (114 loc) · 3.13 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'use strict';
const Schema = require('map-schema');
const normalizers = require('./normalizers');
const validators = require('./validators');
const utils = require('./utils');
const keys = require('./keys');
/**
* Normalize package.json using a schema.
*/
module.exports = options => {
const opts = Object.assign({}, options);
const omit = utils.arrayify(opts.omit);
const config = Object.assign({}, opts, { keys: keys, omit: omit });
const schema = new Schema(config)
.field('name', ['string'], {
validate: validators.name,
normalize: normalizers.name,
required: true
})
.field('private', 'boolean')
.field('description', 'string')
.field('version', 'string', {
validate: validators.version,
default: '0.1.0',
required: true
})
.field('homepage', 'string', {
normalize: normalizers.homepage
})
/**
* Person fields
*/
.field('author', ['object', 'string'], { normalize: normalizers.person })
.field('authors', 'array', { normalize: normalizers.person })
.field('maintainers', 'array', { normalize: normalizers.person })
.field('contributors', 'array', { normalize: normalizers.person })
.field('collaborators', 'array', { normalize: normalizers.person })
/**
* Bugs, repo and license
*/
.field('bugs', ['object', 'string'], {
normalize: normalizers.bugs
})
.field('repository', ['object', 'string'], {
normalize: normalizers.repository
})
.field('license', 'string', {
normalize: normalizers.license,
default: 'MIT'
})
.field('licenses', ['array', 'object'], {
normalize: normalizers.licenses,
validate: validators.licenses
})
/**
* Files, main
*/
.field('files', 'array', {
normalize: normalizers.files
})
.field('main', 'string', {
normalize: normalizers.main,
validate: function(filepath) {
return utils.exists(filepath);
}
})
.field('types', 'string', {
normalize: normalizers.typings
})
.field('typings', 'string', {
normalize: normalizers.typings
})
/**
* Scripts, binaries and related
*/
.field('preferGlobal', 'boolean', {
validate: validators.preferGlobal
})
.field('bin', ['object', 'string'], {
normalize: normalizers.bin
})
.field('scripts', 'object', {
normalize: normalizers.scripts
})
/**
* Engine
*/
.field('engines', 'object', {
default: { node: '>= 0.10.0' }
})
.field('engine-strict', 'boolean', {
validate: validators['engine-strict']
})
.field('engineStrict', 'boolean', {
normalize: normalizers.engineStrict
})
/**
* Dependencies
*/
.field('dependencies', 'object')
.field('devDependencies', 'object')
.field('peerDependencies', 'object')
.field('optionalDependencies', 'object')
/**
* Project metadata
*/
.field('man', ['array', 'string'])
.field('keywords', 'array', {
normalize: normalizers.keywords
});
// Add fields defined on `options.fields`
schema.addFields(opts);
return schema;
};