This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile.js
129 lines (102 loc) · 3.68 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
/**
* @fileoverview Build file
* @author nzakas
*/
/*global target, exec, echo, find, cat, rm, mv*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
require("shelljs/make");
var path = require("path"),
dateformat = require("dateformat");
//------------------------------------------------------------------------------
// Data
//------------------------------------------------------------------------------
var NODE = "node ", // intentional extra space
NODE_MODULES = "./node_modules/",
TEMP_DIR = "./tmp/",
// Utilities - intentional extra space at the end of each string
ISTANBUL = NODE + NODE_MODULES + "istanbul/lib/cli.js ",
MOCHA = NODE_MODULES + "mocha/bin/_mocha ",
ESLINT = NODE + " bin/eslint.js ",
// Files
JS_FILES = find("lib/").filter(fileType("js")).join(" "),
// JSON_FILES = find("conf/").filter(fileType("json")).join(" ") + " .eslintrc",
TEST_FILES = find("tests/lib/").filter(fileType("js")).join(" ");
//------------------------------------------------------------------------------
// 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);
target.changelog();
exec("git push origin master --tags");
exec("npm publish");
}
//------------------------------------------------------------------------------
// Tasks
//------------------------------------------------------------------------------
target.all = function() {
target.test();
};
target.lint = function() {
// echo("Validating JavaScript files");
// exec(ESLINT + JS_FILES);
};
target.test = function() {
target.lint();
exec(ISTANBUL + " cover " + MOCHA + "-- -c " + TEST_FILES);
exec(ISTANBUL + "check-coverage --statement 95 --branch 70 --function 95 --lines 95");
};
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");
};