forked from box/box-node-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.js
110 lines (84 loc) · 2.76 KB
/
Makefile.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
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
/**
* @fileoverview Build file
*/
/*global target, exec, echo, find*/
'use strict';
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
require('shelljs/make');
var nodeCLI = require('shelljs-nodecli');
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**
* Generates a function that matches files with a particular extension.
* @param {string} extension The file extension (i.e. 'js')
* @returns {Function} The function to pass into a filter method.
* @private
*/
function fileType(extension) {
return function(filename) {
return filename.substring(filename.lastIndexOf('.') + 1) === extension;
};
}
/**
* Creates a release version tag and pushes to origin.
* @param {string} type The type of release to do (patch, minor, major)
* @returns {void}
*/
function release(type) {
target.test();
exec('npm version ' + type);
exec('git add package.json');
exec('git commit --amend --no-edit');
// ...and publish
exec('git push origin master --tags');
}
//------------------------------------------------------------------------------
// Data
//------------------------------------------------------------------------------
var MOCHA_BINARY = './node_modules/.bin/_mocha',
// Directories
JS_DIR = './lib/',
// Files
JS_FILES = find(JS_DIR).filter(fileType('js')).join(" "),
JSON_FILES = find('config/').filter(fileType('json')).join(" ") + ' .eslintrc',
TEST_FILES = find('tests/').filter(fileType('js')).join(" ");
//------------------------------------------------------------------------------
// Tasks
//------------------------------------------------------------------------------
target.all = function() {
target.test();
};
target.lint = function() {
var code = 0;
echo('Validating JSON Files');
code += nodeCLI.exec('jsonlint', '-q', '-c', JSON_FILES).code;
echo('Validating package.json');
code += nodeCLI.exec('jsonlint', 'package.json', '-q', '-V ./config/package.schema.json').code;
echo('Validating JavaScript files');
code += nodeCLI.exec('eslint', '--fix', JS_FILES).code;
code += nodeCLI.exec('eslint', '--fix', './tests').code;
return code;
};
target.test = function() {
var code = target.lint();
code += nodeCLI.exec('istanbul', 'cover', MOCHA_BINARY, '--', '-c', '-R nyan', TEST_FILES).code;
if (code) {
exit(code);
}
};
target.docs = function() {
echo('Generating documentation');
nodeCLI.exec('jsdoc', '-r', '-d ./docs/jsdoc ', JS_DIR);
};
target.patch = function() {
release('patch');
};
target.minor = function() {
release('minor');
};
target.major = function() {
release('major');
};