-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbin.js
More file actions
76 lines (62 loc) · 1.58 KB
/
Copy pathbin.js
File metadata and controls
76 lines (62 loc) · 1.58 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
'use strict';
const fs = require('fs');
const path = require('path');
const utils = require('../utils');
const merge = require('../merge');
module.exports = function(bin, key, config, schema) {
merge(config, schema);
if (schema.checked[key]) {
return bin;
}
const opts = utils.merge({}, schema.options);
if (opts.bin === false) {
bin = schema.data.get('bin') || config.bin || bin;
if (typeof bin === 'string') {
schema.union('files', config, bin);
}
schema.checked[key] = true;
return bin;
}
if (typeof bin === 'string') {
schema.union('files', config, bin);
schema.checked[key] = true;
return bin;
}
if (typeof bin === 'undefined') {
bin = {};
}
// ensure `name` is defined before continuing
schema.update('name', config);
const obj = {};
let num = 0;
if (utils.isObject(bin)) {
for (var prop in bin) {
if (utils.exists(bin[prop])) {
obj[prop] = bin[prop];
num++;
}
}
bin = obj;
}
// add cli.js or "bin/" if they exist
const dir = path.resolve(process.cwd(), 'bin');
if (num === 0 && utils.exists(dir)) {
fs.readdirSync(dir).forEach(function(fp) {
bin[config.name] = path.relative(process.cwd(), path.join(dir, fp));
num++;
});
}
if (num === 0 && utils.exists(path.resolve(process.cwd(), 'cli.js'))) {
bin[config.name] = 'cli.js';
}
if (!utils.isEmpty(bin)) {
if (typeof bin === 'string') {
schema.union('files', config, bin);
}
config[key] = bin;
schema.checked[key] = true;
return bin;
}
schema.omit(key);
return;
};