-
Notifications
You must be signed in to change notification settings - Fork 121
/
Makefile.js
144 lines (117 loc) · 3.16 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
* @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 main --tags');
}
//------------------------------------------------------------------------------
// Data
//------------------------------------------------------------------------------
var MOCHA_BINARY = './node_modules/.bin/_mocha',
// Directories
JS_DIR = './src/',
// 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'))
.filter((file) => !file.includes('integration_test/'))
.join(' ');
//------------------------------------------------------------------------------
// Tasks
//------------------------------------------------------------------------------
target.all = function () {
target.test();
};
target.build = function () {
var code = 0;
echo('Compiling TypeScript code');
code += nodeCLI.exec('./node_modules/.bin/tsc').code;
return code;
};
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, './tests').code;
return code;
};
target.test = function () {
var code = target.build();
code += target.lint();
code += nodeCLI.exec(
'nyc',
MOCHA_BINARY,
'-c',
'-R spec',
'--exit',
TEST_FILES
).code;
if (code) {
exit(code);
}
};
target.docs = function () {
echo('Generating documentation');
nodeCLI.exec('jsdoc', '-r', '-c ./jsdoc.json', '-d ./docs/jsdoc ', JS_DIR);
};
target.docsDev = function () {
echo('Generating dev documentation');
nodeCLI.exec(
'jsdoc',
'-p',
'-r',
'-c ./jsdoc.json',
'-d ./docs/jsdoc-dev ',
JS_DIR
);
};
target.patch = function () {
release('patch');
};
target.minor = function () {
release('minor');
};
target.major = function () {
release('major');
};