This repository has been archived by the owner on Nov 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathMakefile.js
154 lines (122 loc) · 4.26 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
150
151
152
153
154
/**
* @fileoverview Build file
* @author nzakas
*/
/*global cat, echo, exec, exit, find, mv, rm, target*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
require("shelljs/make");
var dateformat = require("dateformat"),
nodeCLI = require("shelljs-nodecli");
//------------------------------------------------------------------------------
// Data
//------------------------------------------------------------------------------
var NODE_MODULES = "./node_modules/",
// Utilities - intentional extra space at the end of each string
MOCHA = NODE_MODULES + "mocha/bin/_mocha ",
// Files
MAKEFILE = "./Makefile.js",
/*eslint-disable no-use-before-define */
JS_FILES = find("lib/").filter(fileType("js")).join(" "),
TEST_FILES = find("tests/lib/").filter(fileType("js")).join(" ");
/*eslint-enable no-use-before-define */
//------------------------------------------------------------------------------
// 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;
};
}
/**
* Executes a Node command and exits if the exit code isn't 0.
* @returns {void}
* @private
*/
function nodeExec() {
var exitCode = nodeCLI.exec.apply(nodeCLI, arguments).code;
if (exitCode > 0) {
exit(1);
}
}
/**
* 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);
target.changelog();
exec("git push origin master --tags");
exec("npm publish");
}
//------------------------------------------------------------------------------
// Tasks
//------------------------------------------------------------------------------
target.all = function() {
target.test();
};
target.lint = function() {
echo("Validating Makefile.js");
nodeExec("eslint", MAKEFILE);
echo("Validating JavaScript files");
nodeExec("eslint", JS_FILES);
echo("Validating JavaScript test files");
nodeExec("eslint", TEST_FILES);
};
target.test = function() {
target.lint();
// exec(ISTANBUL + " cover " + MOCHA + "-- -c " + TEST_FILES);
nodeExec("istanbul", "cover", MOCHA, "-- -c", TEST_FILES);
// exec(ISTANBUL + "check-coverage --statement 99 --branch 98 --function 99 --lines 99");
nodeExec("istanbul", "check-coverage", "--statement 90 --branch 80 --function 100 --lines 90");
};
target.docs = function() {
echo("Generating documentation");
nodeCLI.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 = dateformat(now, "mmmm d, yyyy");
// 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");
};