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

This commit is contained in:
dcodeIO 2017-01-05 01:16:37 +01:00
parent 44f6357557
commit e88d13ca7e
7 changed files with 30 additions and 30 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
*.log
npm-debug.*
node_modules/
cli/node_modules/
docs/
coverage/
sandbox/

View File

@ -3,6 +3,7 @@
*.log
npm-debug.*
node_modules/
cli/node_modules/
docs/
coverage/
sandbox/

1
cli/package.json Normal file
View File

@ -0,0 +1 @@
{}

View File

@ -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"),

View File

@ -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"),

View File

@ -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"
});
};

View File

@ -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" ]
}