Permalink
Browse files

CLI: Revised automatic setup of cli dependencies, see #618

  • Loading branch information...
dcodeIO committed Jan 4, 2017
1 parent f2ffa07 commit 44f6357557ab3d881310024342bcc1e0d336a20c
Showing with 50 additions and 35 deletions.
  1. +1 −0 .npmignore
  2. +12 −4 cli/pbjs.js
  3. +15 −10 cli/pbts.js
  4. +2 −3 cli/targets/static.js
  5. +20 −18 cli/util.js
@@ -17,3 +17,4 @@ src/util/inquire/
src/util/path/
src/util/pool/
src/util/utf8/
pbjs.png
@@ -1,14 +1,22 @@
"use strict";
var path = require("path"),
fs = require("fs"),
pkg = require(path.join(__dirname, "..", "package.json")),
util = require("./util");
var minimist = util.require("minimist", pkg.devDependencies.minimist),
chalk = util.require("chalk", pkg.devDependencies.chalk),
glob = util.require("glob", pkg.devDependencies.glob);
util.setup([
"minimist",
"chalk",
"glob",
"uglify-js"
], pkg.devDependencies);
var protobuf = require(".."),
targets = util.requireAll("./targets");
minimist = require("minimist"),
chalk = require("chalk"),
glob = require("glob");
var targets = util.requireAll("./targets");
/**
* Runs pbjs programmatically.
@@ -1,17 +1,22 @@
var path = require("path"),
"use strict";
var child_process = require("child_process"),
path = require("path"),
fs = require("fs"),
pkg = require(path.join(__dirname, "..", "package.json")),
util = require("./util");
var child_process = require("child_process");
var minimist = util.require("minimist", pkg.devDependencies.minimist),
chalk = util.require("chalk", pkg.devDependencies.chalk),
glob = util.require("glob", pkg.devDependencies.glob),
tmp = util.require("tmp", pkg.devDependencies.tmp);
var jsdoc = util.require("jsdoc/package.json", pkg.devDependencies.jsdoc);
var protobuf = require("..");
util.setup([
"minimist",
"chalk",
"glob",
"tmp",
"jsdoc"
], pkg.devDependencies);
var minimist = require("minimist"),
chalk = require("chalk"),
glob = require("glob"),
tmp = require("tmp");
/**
* Runs pbts programmatically.
@@ -2,9 +2,8 @@
module.exports = static_target;
var protobuf = require("../.."),
cliUtil = require("../util");
var UglifyJS = cliUtil.require("uglify-js", require(require("path").join(__dirname, "..", "..", "package.json")).devDependencies["uglify-js"]);
cliUtil = require("../util"),
UglifyJS = require("uglify-js");
var Type = protobuf.Type,
Service = protobuf.Service,
@@ -69,25 +69,27 @@ exports.inspect = function inspect(object, indent) {
return sb.join("\n");
};
exports.require = function(name, version) {
var sub = "";
var p = name.indexOf("/");
if (p > -1) {
sub = name.substring(p);
name = name.substring(0, p);
exports.setup = function(modules, versions) {
for (var i = 0; i < modules.length;) {
try {
// do not feed the cache
require.resolve(path.join(modules[i], "package.json"));
modules.splice(i, 1);
} catch (e) {
++i;
}
}
var cwd = path.join(__dirname, "..");
var dir = path.join(cwd, "node_modules", name);
try {
// do not feed the cache
require.resolve(path.join(dir, "package.json"));
} catch (e) {
console.error("installing " + name + "@" + version + " ...");
child_process.execSync("npm --silent install " + name + "@" + version, {
cwd: cwd
});
}
return require(name + sub);
if (!modules.length)
return;
modules = modules.map(function(name) {
return name + "@" + versions[name];
});
var cmd = "npm --silent --only=prod install " + modules.join(" ");
process.stderr.write("setting up " + modules.join(", ") + " ...\n");
child_process.execSync(cmd, {
cwd: path.join(__dirname, ".."),
stdio: "ignore"
});
};
exports.wrap = function(OUTPUT, options) {

0 comments on commit 44f6357

Please sign in to comment.