forked from eslint/eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.js
149 lines (121 loc) · 4.22 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
145
146
147
148
149
/**
* @fileoverview Build file
* @author nzakas
*/
/*global target, exec, echo, find, cat, rm, mv*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
require("shelljs/make");
//------------------------------------------------------------------------------
// 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) {
exec("npm version " + type);
exec("git push origin master --tags");
target.changelog();
}
//------------------------------------------------------------------------------
// Data
//------------------------------------------------------------------------------
var NODE = "node ", // intentional extra space
NODE_MODULES = "./node_modules/",
// Utilities - intentional extra space at the end of each string
JSON_LINT = NODE + NODE_MODULES + "jsonlint/lib/cli.js ",
ISTANBUL = NODE + NODE_MODULES + "istanbul/lib/cli.js ",
MOCHA = NODE_MODULES + "mocha/bin/_mocha ",
JSDOC = NODE + NODE_MODULES + "jsdoc/jsdoc.js ",
JSHINT = NODE + NODE_MODULES + "jshint/bin/jshint ",
ESLINT = NODE + " bin/eslint.js ",
// Files
JS_FILES = find("lib/").filter(fileType("js")).join(" "),
JSON_FILES = find("conf/").filter(fileType("json")).join(" ") + " .eslintrc .jshintrc",
TEST_FILES = find("tests/lib/").filter(fileType("js")).join(" "),
MONTHS = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];
//------------------------------------------------------------------------------
// Tasks
//------------------------------------------------------------------------------
target.all = function() {
target.test();
};
target.lint = function() {
echo("Validating JSON Files");
exec(JSON_LINT + "-q -c " + JSON_FILES);
echo("Validating JavaScript files");
exec(JSHINT + " " + JS_FILES);
};
target.test = function() {
target.lint();
exec(ISTANBUL + " cover " + MOCHA + TEST_FILES);
exec(ISTANBUL + "check-coverage --statement 95 --branch 95 --function 95 --lines 95");
};
target.docs = function() {
echo("Generating documentation");
exec(JSDOC + "-d jsdoc lib");
echo("Documentation has been output to /jsdoc");
};
target.changelog = function() {
// get most recent two tags
var tags = exec("git tag", { silent: true }).output.trim().split(/\s/g),
rangeTags = tags.slice(tags.length - 2),
now = new Date(),
timestamp = MONTHS[now.getMonth()] + " " + now.getDate() + ", " + now.getFullYear();
// output header
(rangeTags[1] + " - " + timestamp + "\n").to("CHANGELOG.tmp");
// get log statements
var logs = exec("git log --pretty=format:\"* %s (%an)\" " + rangeTags.join(".."), {silent:true}).output.split(/\n/g);
logs = logs.filter(function(line) {
return line.indexOf("Merge pull request") === -1 && line.indexOf("Merge branch") === -1;
});
logs.push(""); // to create empty lines
logs.unshift("");
// output log statements
logs.join("\n").toEnd("CHANGELOG.tmp");
// switch-o change-o
cat("CHANGELOG.tmp", "CHANGELOG.md").to("CHANGELOG.md.tmp");
rm("CHANGELOG.tmp");
rm("CHANGELOG.md");
mv("CHANGELOG.md.tmp", "CHANGELOG.md");
// add into commit
exec("git add CHANGELOG.md");
exec("git commit --amend --no-edit");
};
target.patch = function() {
release("patch");
};
target.minor = function() {
release("minor");
};
target.major = function() {
release("major");
};