Skip to content

Commit

Permalink
Merge pull request #242 from eslint/releasetool
Browse files Browse the repository at this point in the history
Build: Switch to eslint-release
  • Loading branch information
nzakas committed Jan 20, 2016
2 parents 15af2a1 + 34d195b commit 8a9d305
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 171 deletions.
166 changes: 2 additions & 164 deletions Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @fileoverview Build file
* @author nzakas
*/
/* global cat, cp, echo, exec, exit, find, mkdir, mv, rm, target, test */
/* global cp, echo, exit, find, mkdir, rm, target, test */

"use strict";

Expand All @@ -13,18 +13,7 @@

require("shelljs/make");

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

//------------------------------------------------------------------------------
// Settings
//------------------------------------------------------------------------------

var OPEN_SOURCE_LICENSES = [
/MIT/, /BSD/, /Apache/, /ISC/, /WTF/, /Public Domain/
];
var nodeCLI = require("shelljs-nodecli");

//------------------------------------------------------------------------------
// Data
Expand Down Expand Up @@ -60,64 +49,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");
}

/**
* Gets an array of tags that represent versions.
* @returns {string[]} The array of 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 @@ -168,8 +99,6 @@ target.test = function() {
if (errors) {
exit(1);
}

// target.checkLicenses();
};

target.docs = function() {
Expand Down Expand Up @@ -202,94 +131,3 @@ target.browserify = function() {
// 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() {

/**
* Determines if a given dependency is permissible based on its license.
* @param {Object} dependency The dependency to check
* @returns {boolean} True if the dependency is ok, false if not.
*/
function isPermissible(dependency) {
var licenses = dependency.licenses;

if (Array.isArray(licenses)) {
return licenses.some(function(license) {
return isPermissible({
name: dependency.name,
licenses: license
});
});
}

return OPEN_SOURCE_LICENSES.some(function(license) {
return license.test(licenses);
});
}

echo("Validating licenses");

checker.init({
start: __dirname
}, function(deps) {
var impermissible = Object.keys(deps).map(function(dependency) {
return {
name: dependency,
licenses: deps[dependency].licenses
};
}).filter(function(dependency) {
return !isPermissible(dependency);
});

if (impermissible.length) {
impermissible.forEach(function(dependency) {
console.error("%s license for %s is impermissible.",
dependency.licenses,
dependency.name
);
});
exit(1);
}
});
};

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

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

target.major = function() {
release("major");
};
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,17 @@
"devDependencies": {
"browserify": "^7.0.0",
"chai": "^1.10.0",
"complexity-report": "~0.6.1",
"dateformat": "^1.0.11",
"eslint": "^2.0.0-beta.1",
"eslint-config-eslint": "^2.0.0",
"eslint-release": "^0.1.2",
"esprima": "git://github.com/jquery/esprima",
"esprima-fb": "^8001.2001.0-dev-harmony-fb",
"istanbul": "~0.2.6",
"json-diff": "~0.3.1",
"leche": "^1.0.1",
"mocha": "^2.0.1",
"npm-license": "^0.2.3",
"optimist": "~0.6.0",
"regenerate": "~0.5.4",
"semver": "^4.1.1",
"shelljs": "^0.3.0",
"shelljs-nodecli": "^0.1.1",
"unicode-6.3.0": "~0.1.0"
Expand All @@ -57,9 +54,7 @@
"generate-regex": "node tools/generate-identifier-regex.js",
"test": "npm run-script lint && node Makefile.js test",
"lint": "node Makefile.js lint",
"patch": "node Makefile.js patch",
"minor": "node Makefile.js minor",
"major": "node Makefile.js major",
"release": "eslint-release",
"browserify": "node Makefile.js browserify"
}
}

0 comments on commit 8a9d305

Please sign in to comment.