forked from box/box-node-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.js
101 lines (79 loc) · 2.59 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
/**
* @fileoverview Build file
* @author mwiller
*/
/*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() {
echo('Validating JSON Files');
nodeCLI.exec('jsonlint', '-q', '-c', JSON_FILES);
echo('Validating package.json');
nodeCLI.exec('jsonlint', 'package.json', '-q', '-V ./config/package.schema.json');
echo('Validating JavaScript files');
nodeCLI.exec('eslint', '--fix', JS_FILES);
};
target.test = function() {
target.lint();
nodeCLI.exec('istanbul', 'cover', MOCHA_BINARY, '--', '-c', '-R nyan', TEST_FILES);
};
target.docs = function() {
echo('Generating documentation');
nodeCLI.exec('jsdoc', '-r', '-d ./ ', JS_DIR);
};
target.patch = function() {
release('patch');
};
target.minor = function() {
release('minor');
};
target.major = function() {
release('major');
};