Permalink
Browse files

CLI: Additional workarounds for on demand CLI dependencies, see #618

  • Loading branch information...
dcodeIO committed Jan 5, 2017
1 parent 44f6357 commit e88d13ca7ee971451b57d056f747215f37dfd3d7
Showing with 30 additions and 30 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 .npmignore
  3. +1 −0 cli/package.json
  4. +1 −6 cli/pbjs.js
  5. +1 −7 cli/pbts.js
  6. +23 −16 cli/util.js
  7. +2 −1 package.json
@@ -1,6 +1,7 @@
*.log
npm-debug.*
node_modules/
cli/node_modules/
docs/
coverage/
sandbox/
@@ -3,6 +3,7 @@
*.log
npm-debug.*
node_modules/
cli/node_modules/
docs/
coverage/
sandbox/
@@ -0,0 +1 @@
{}
@@ -4,12 +4,7 @@ var path = require("path"),
pkg = require(path.join(__dirname, "..", "package.json")),
util = require("./util");
util.setup([
"minimist",
"chalk",
"glob",
"uglify-js"
], pkg.devDependencies);
util.setup();
var protobuf = require(".."),
minimist = require("minimist"),
@@ -5,13 +5,7 @@ var child_process = require("child_process"),
pkg = require(path.join(__dirname, "..", "package.json")),
util = require("./util");
util.setup([
"minimist",
"chalk",
"glob",
"tmp",
"jsdoc"
], pkg.devDependencies);
util.setup();
var minimist = require("minimist"),
chalk = require("chalk"),
@@ -1,6 +1,8 @@
"use strict";
var fs = require("fs"),
path = require("path"),
child_process = require("child_process");
child_process = require("child_process"),
Module = require("module");
var protobuf = require("..");
@@ -69,25 +71,30 @@ exports.inspect = function inspect(object, indent) {
return sb.join("\n");
};
exports.setup = function(modules, versions) {
for (var i = 0; i < modules.length;) {
exports.setup = function() {
// this one is important. without it, this folder won't be searched anymore.
try { fs.mkdirSync(path.join(__dirname, "node_modules")); } catch (e) {}
// find out which modules are missing
var pkg = require(path.join(__dirname, "..", "package.json"));
var install = [];
pkg.cliDependencies.forEach(function(name) {
try {
// do not feed the cache
require.resolve(path.join(modules[i], "package.json"));
modules.splice(i, 1);
require.resolve(name + "/package.json"); // jsdoc has no main file
} catch (e) {
++i;
var version = pkg.dependencies[name] || pkg.devDependencies[name];
install.push(version ? name + "@" + version : name);
}
}
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, ".."),
if (!install.length) {
try { fs.rmdirSync(path.join(__dirname, "node_modules")); } catch (e) {}
return;
}
// if any are missing, install them. this relies on an empty package.json in cli/.
process.stderr.write("installing CLI dependencies: " + install.join(", ") + "\n");
child_process.execSync("npm --silent install " + install.join(" "), {
cwd: __dirname,
stdio: "ignore"
});
};
@@ -88,5 +88,6 @@
"vinyl-source-stream": "^1.1.0",
"zuul": "^3.11.1",
"zuul-ngrok": "^4.0.0"
}
},
"cliDependencies": [ "chalk", "glob", "jsdoc", "minimist", "tmp", "uglify-js" ]
}

0 comments on commit e88d13c

Please sign in to comment.