Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Chore: Cleanup Makefile #221

Merged
merged 1 commit into from
Apr 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 3 additions & 131 deletions Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @copyright jQuery Foundation and other contributors, https://jquery.org/
* MIT License
*/
/* global cat, cp, echo, exec, exit, find, mkdir, mv, rm, target, test */
/* global echo, exit, find, target */

"use strict";

Expand All @@ -16,9 +16,7 @@
require("shelljs/make");

var checker = require("npm-license"),
dateformat = require("dateformat"),
nodeCLI = require("shelljs-nodecli"),
semver = require("semver");
nodeCLI = require("shelljs-nodecli");

//------------------------------------------------------------------------------
// Settings
Expand All @@ -33,16 +31,14 @@ var OPEN_SOURCE_LICENSES = [
//------------------------------------------------------------------------------

var NODE_MODULES = "./node_modules/",
TEMP_DIR = "./tmp/",
BUILD_DIR = "./build/",

// 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(" ") + " espree.js",
JS_FILES = find("lib/").filter(fileType("js")).join(" ") + " parser.js",
TEST_FILES = find("tests/lib/").filter(fileType("js")).join(" ");
/* eslint-enable no-use-before-define */

Expand All @@ -62,64 +58,6 @@ function fileType(extension) {
};
}

/**
* Executes a command and returns the output instead of printing it to stdout.
* @param {string} cmd The command string to execute.
* @returns {string} The result of the executed command.
*/
function execSilent(cmd) {
return exec(cmd, { silent: true }).output;
}

/**
* 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) {
var newVersion;

target.test();
newVersion = execSilent("npm version " + type).trim();
target.changelog();

// add changelog to commit
exec("git add CHANGELOG.md");
exec("git commit --amend --no-edit");

// replace existing tag
exec("git tag -f " + newVersion);

// push all the things
exec("git push origin master --tags");
exec("npm publish");
}


/**
* Splits a command result to separate lines.
* @param {string} result The command result string.
* @returns {array} The separated lines.
*/
function splitCommandResultToLines(result) {
return result.trim().split("\n");
}

/**
* Returns a list of sorted, valid semtantic-verisioning git tags
* @returns {string[]} The version tags
*/
function getVersionTags() {
var tags = splitCommandResultToLines(exec("git tag", { silent: true }).output);

return tags.reduce(function(list, tag) {
if (semver.valid(tag)) {
list.push(tag);
}
return list;
}, []).sort(semver.compare);
}

//------------------------------------------------------------------------------
// Tasks
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -180,60 +118,6 @@ target.docs = function() {
echo("Documentation has been output to /jsdoc");
};

target.browserify = function() {

// 1. create temp and build directory
if (!test("-d", TEMP_DIR)) {
mkdir(TEMP_DIR);
mkdir(TEMP_DIR + "/lib");
}

if (!test("-d", BUILD_DIR)) {
mkdir(BUILD_DIR);
}

// 2. copy files into temp directory
cp("-r", "lib/*", TEMP_DIR + "/lib");
cp("espree.js", TEMP_DIR);
cp("package.json", TEMP_DIR);


// 3. browserify the temp directory
nodeCLI.exec("browserify", TEMP_DIR + "espree.js", "-o", BUILD_DIR + "espree.js", "-s espree");

// 4. remove temp directory
rm("-r", TEMP_DIR);
};

target.changelog = function() {

// get most recent two tags
var tags = getVersionTags(),
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");
};

target.checkLicenses = function() {

/**
Expand Down Expand Up @@ -283,15 +167,3 @@ target.checkLicenses = function() {
}
});
};

target.patch = function() {
release("patch");
};

target.minor = function() {
release("minor");
};

target.major = function() {
release("major");
};