From 79111650f0903b9071470eb0200d9c639d5abad1 Mon Sep 17 00:00:00 2001 From: DamianEdwards Date: Tue, 8 Jul 2014 13:42:47 -0700 Subject: [PATCH] Fixed node/npm/grunt tasks to use global install if available --- build/_bower.shade | 4 ++-- build/_grunt.shade | 8 ++++++-- build/_k-standard-goals.shade | 14 +++++++------- build/_node-install.shade | 2 +- build/_node.shade | 2 +- build/_npm.shade | 4 ++-- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/build/_bower.shade b/build/_bower.shade index a273dc631d..3fc52cd796 100644 --- a/build/_bower.shade +++ b/build/_bower.shade @@ -1,7 +1,7 @@ default currentDir = '${Directory.GetCurrentDirectory()}' default nodeDir = '${Path.Combine(currentDir, "bin", "nodejs")}' -var bowerGloballyInstalled = '${TestCommand("bower --version")}' +var bowerGloballyInstalled = '${TestCommand("bower", "--version")}' var bowerInstalled = '${Directory.Exists(Path.Combine(nodeDir, "node_modules", "bower"))}' var bowerCmd = '${ bowerGloballyInstalled ? "bower" : Path.Combine(nodeDir, "node_modules", "bower", "bin", "bower") }' @@ -9,5 +9,5 @@ var bowerCmd = '${ bowerGloballyInstalled ? "bower" : Path.Combine(nodeDir, "nod npm npmCommand='install --prefix ${nodeDir} bower' if='!(bowerGloballyInstalled || bowerInstalled)' once='installBower' - // Run bower -exec program='${bowerCmd}' commandline='${bowerCommand}' if='bowerGloballyInstalled' +exec program='cmd' commandline='/C ${bowerCmd} ${bowerCommand}' workingdir='${bowerDir}' if='bowerGloballyInstalled' node nodeCommand='${bowerCmd} ${bowerCommand}' workingdir='${bowerDir}' if='!bowerGloballyInstalled' \ No newline at end of file diff --git a/build/_grunt.shade b/build/_grunt.shade index 05f892ab95..a760008be5 100644 --- a/build/_grunt.shade +++ b/build/_grunt.shade @@ -1,9 +1,13 @@ default currentDir = '${Directory.GetCurrentDirectory()}' default nodeDir = '${Path.Combine(currentDir, "bin", "nodejs")}' + +var gruntCliGloballyInstalled = '${TestCommand("grunt", "--version")}' var gruntCliInstalled = '${Directory.Exists(Path.Combine(nodeDir, "node_modules", "grunt-cli"))}' +var gruntCmd = '${ gruntCliGloballyInstalled ? "grunt" : Path.Combine(nodeDir, "node_modules", "grunt-cli") }' -// Install grunt-cli locally -npm npmCommand='install --prefix ${nodeDir} grunt-cli' if='!gruntCliInstalled' once='installGruntCli' +npm npmCommand='install --prefix ${nodeDir} grunt-cli' if='!(gruntCliGloballyInstalled || gruntCliInstalled)' once='installGruntCli' -// Run grunt -node nodeCommand='${Path.Combine(nodeDir, "node_modules", "grunt-cli", "bin", "grunt")}' workingdir='${gruntDir}' \ No newline at end of file +exec program='cmd' commandline='/C ${gruntCmd}' workingdir='${gruntDir}' if='gruntCliGloballyInstalled' +node nodeCommand='${Path.Combine(nodeDir, "node_modules", "grunt-cli", "bin", "grunt")}' workingdir='${gruntDir}' if='!gruntCliGloballyInstalled' \ No newline at end of file diff --git a/build/_k-standard-goals.shade b/build/_k-standard-goals.shade index 75d46a4f74..dc6aacc86e 100644 --- a/build/_k-standard-goals.shade +++ b/build/_k-standard-goals.shade @@ -115,29 +115,29 @@ functions @{ .Select(p => Path.GetDirectoryName(p)) .Distinct(); } - bool TestCommand(string program, string commandline = null) { + bool TestCommand(string program, string commandline) { // Tests whether a given command succeeds at the command line. // Useful for testing whether a given command is installed and on the path, e.g. node var processStartInfo = new ProcessStartInfo { UseShellExecute = false, - WorkingDirectory = Directory.GetCurrentDirectory(), - FileName = program, - Arguments = commandline, + FileName = "cmd", + Arguments = "/C " + program + " " + commandline, }; try { Log.Info(string.Format("Testing for command: {0} {1}", program, commandline)); var process = Process.Start(processStartInfo); process.WaitForExit(); if (process.ExitCode == 0) { - Log.Info(" command found"); + Log.Info(" command found (0 exit code)"); return true; } else { - Log.Warn(" command not found"); + Log.Warn(" command not found (non-0 exit code)"); return false; } } - catch (Exception) { + catch (Exception ex) { + Log.Warn(" command exception: " + ex.ToString()); Log.Warn(" command not found"); return false; } diff --git a/build/_node-install.shade b/build/_node-install.shade index c966ab8465..94359bb84f 100644 --- a/build/_node-install.shade +++ b/build/_node-install.shade @@ -10,7 +10,7 @@ default nodeVer = '0.10.28' default npmVer = '1.4.9' default nodeExeSha = '628FFD6C3577068C00CEC9F6F897F0EC8F5212D9' default nodeInstallDir = '${Path.Combine(binDir, "nodejs")}' -default nodeGloballyInstalled = '${TestCommand("node --version")}' +default nodeGloballyInstalled = '${TestCommand("node" , "--version")}' var nodeExe = 'node.exe' var npmZip = 'npm-${npmVer}.zip' diff --git a/build/_node.shade b/build/_node.shade index 323abd0b0d..acfb908850 100644 --- a/build/_node.shade +++ b/build/_node.shade @@ -1,6 +1,6 @@ default currentDir = '${Directory.GetCurrentDirectory()}' default nodeDir = '${Path.Combine(currentDir, "bin", "node")}' -default nodeGloballyInstalled = '${TestCommand("node --version")}' +default nodeGloballyInstalled = '${TestCommand("node", "--version")}' var nodeExePath = '${ nodeGloballyInstalled ? "node" : Path.Combine(nodeDir, "node.exe") }' diff --git a/build/_npm.shade b/build/_npm.shade index 389a6107b1..3b58d40ea3 100644 --- a/build/_npm.shade +++ b/build/_npm.shade @@ -2,8 +2,8 @@ default currentDir = '${Directory.GetCurrentDirectory()}' default nodeDir = '${Path.Combine(currentDir, "bin", "nodejs")}' default npmDir = '${currentDir}' -var npmGloballyInstalled = '${TestCommand("npm --version")}' +var npmGloballyInstalled = '${TestCommand("npm" , "--version")}' var npmCmd = '${ npmGloballyInstalled ? "npm" : Path.Combine(nodeDir, "npm.cmd") }' node-install once='installNode' -exec program='${npmCmd}' commandline='${npmCommand}' workingdir='${npmDir}' \ No newline at end of file +exec program='cmd' commandline='/C ${npmCmd} ${npmCommand}' workingdir='${npmDir}' \ No newline at end of file