Skip to content
This repository has been archived by the owner on Mar 4, 2022. It is now read-only.

Commit

Permalink
Pass eslint internally.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-roemer committed Oct 24, 2015
1 parent 266ecf3 commit ec28e99
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .eslintrc-server
@@ -0,0 +1,3 @@
---
extends:
- "defaults/configurations/walmart/es5-node"
4 changes: 2 additions & 2 deletions bin/builder.js
@@ -1,6 +1,5 @@
#!/usr/bin/env node

var log = require("../lib/log");
"use strict";

// Set up environment
var Environment = require("../lib/environment");
Expand All @@ -15,5 +14,6 @@ var task = new Task();

// Run the task
task.execute(env, function (err) {
/*eslint-disable no-process-exit*/
process.exit(err ? err.code || 1 : 0);
});
13 changes: 10 additions & 3 deletions lib/environment.js
Expand Up @@ -14,12 +14,15 @@ var DELIM = process.platform.indexOf("win") === 0 ? ";" : ":";

// Node binary directories.
var CWD_BIN = path.join(process.cwd(), "node_modules/.bin");
var ARCHETYPE_BIN = path.join(__dirname, "../../builder-react-component/node_modules/.bin"); // TODO: ARCHETYPE
// TODO: EXTRACT TO ARCHETYPE INFERENCE
var ARCHETYPE_BIN = path.join(__dirname,
"../../builder-react-component/node_modules/.bin");

/**
* Environment wrapper.
*
* @param {Object} env Environment object to mutate (Default `process.env`)
* @returns {void}
*/
var Environment = module.exports = function (env) {
this.env = env || process.env;
Expand All @@ -40,11 +43,13 @@ var Environment = module.exports = function (env) {
* @returns {String} `PATH` environment variable (post-mutation)
*/
Environment.prototype.updatePath = function () {
return this.env.PATH = (this.env.PATH || "")
this.env.PATH = (this.env.PATH || "")
.split(DELIM)
.filter(function (x) { return x; }) // Remove empty strings
.concat([CWD_BIN, ARCHETYPE_BIN])
.join(DELIM);

return this.env.PATH;
};

/**
Expand All @@ -59,9 +64,11 @@ Environment.prototype.updatePath = function () {
Environment.prototype.updateNodePath = function () {
var paths = Array.prototype.slice.call(arguments);

return this.env.NODE_PATH = (this.env.NODE_PATH || "")
this.env.NODE_PATH = (this.env.NODE_PATH || "")
.split(DELIM)
.filter(function (x) { return x; }) // Remove empty strings
.concat(paths)
.join(DELIM);

return this.env.NODE_PATH;
};
4 changes: 2 additions & 2 deletions lib/log.js
Expand Up @@ -8,14 +8,14 @@ var cons = console;
// Wrap "type".
var wrapType = function (type) {
return "[builder" + (type ? ":" + type : "") + "]";
}
};

/**
* A super-small logger.
*/
module.exports = {
info: function (type, msg) {
cons.log([chalk.green(wrapType(type)), msg].join(" "))
cons.log([chalk.green(wrapType(type)), msg].join(" "));
},

error: function (type, msg) {
Expand Down
4 changes: 2 additions & 2 deletions lib/runner.js
Expand Up @@ -6,7 +6,7 @@ var log = require("../lib/log");

// Process runner.
var run = function (env, cmd, callback) {
log.info("proc:start", cmd)
log.info("proc:start", cmd);
var proc = exec(cmd, {
env: env.env
}, function (err) {
Expand All @@ -17,7 +17,7 @@ var run = function (env, cmd, callback) {
log.error("proc:error", "Code: " + code + ", Command: " + cmd);
}

log.info("proc:end:" + code, cmd)
log.info("proc:end:" + code, cmd);
callback(err);
});

Expand Down
7 changes: 5 additions & 2 deletions lib/scripts.js
Expand Up @@ -5,12 +5,15 @@ var chalk = require("chalk");
var _ = require("lodash");

// Load local `package.json`.
/*eslint-disable global-require*/
// TODO: Protect on import error.
var CWD_PKG = (require(path.join(process.cwd(), "package.json")) || {}).scripts || {};
// TODO: HACK -- Import archetypes
var ARCH_PKG = (require(path.join(process.cwd(), "node_modules/builder-react-component/package.json")) || {}).scripts || {};
var ARCH_PKG = (require(path.join(process.cwd(),
"node_modules/builder-react-component/package.json")) || {}).scripts || {};
/*eslint-enable global-require*/

var scripts = module.exports = {
module.exports = {
cwd: CWD_PKG,
archetype: ARCH_PKG,

Expand Down
3 changes: 3 additions & 0 deletions lib/task.js
Expand Up @@ -11,6 +11,7 @@ var log = require("./log");
* Task wrapper.
*
* @param {Array} argv Arguments array (Default: `process.argv`)
* @returns {void}
*/
var Task = module.exports = function (argv) {
argv = argv || process.argv;
Expand Down Expand Up @@ -84,7 +85,9 @@ Task.prototype.getCommand = function (cmd) {
/**
* Execute task or tasks.
*
* @param {Object} env Environment object
* @param {Function} callback Callback function `(err)`
* @returns {void}
*/
Task.prototype.execute = function (env, callback) {
if (!env) {
Expand Down
20 changes: 20 additions & 0 deletions package.json
Expand Up @@ -2,12 +2,32 @@
"name": "builder",
"version": "0.0.1",
"description": "An NPM-based task runner",
"repository": {
"type": "git",
"url": "https://github.com/FormidableLabs/builder.git"
},
"author": "Ryan Roemer <ryan.roemer@formidablelabs.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/FormidableLabs/builder/issues"
},
"homepage": "https://github.com/FormidableLabs/builder",
"scripts": {
"builder:lint-server": "eslint --color -c .eslintrc-server lib bin",
"builder:lint": "npm run builder:lint-server",
"builder:check": "npm run builder:lint"
},
"bin": {
"builder": "bin/builder.js"
},
"dependencies": {
"async": "^1.4.2",
"chalk": "^1.1.1",
"lodash": "^3.10.1"
},
"devDependencies": {
"eslint": "^1.7.3",
"eslint-config-defaults": "^7.0.1",
"eslint-plugin-filenames": "^0.1.2"
}
}

0 comments on commit ec28e99

Please sign in to comment.