diff --git a/build/_bower.shade b/build/_bower.shade index e8392184be..a273dc631d 100644 --- a/build/_bower.shade +++ b/build/_bower.shade @@ -1,9 +1,13 @@ default currentDir = '${Directory.GetCurrentDirectory()}' default nodeDir = '${Path.Combine(currentDir, "bin", "nodejs")}' -var bowerInstalled = '${Directory.Exists(Path.Combine(nodeDir, "node_modules", "bower"))}' -- // Install bower locally -npm npmCommand='install --prefix ${nodeDir} bower' if='!bowerInstalled' once='installBower' +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") }' + +- // Install bower locally if not already installed either globally or locally +npm npmCommand='install --prefix ${nodeDir} bower' if='!(bowerGloballyInstalled || bowerInstalled)' once='installBower' - // Run bower -node nodeCommand='${Path.Combine(nodeDir, "node_modules", "bower", "bin", "bower")} ${bowerCommand}' workingdir='${bowerDir}' \ No newline at end of file +exec program='${bowerCmd}' commandline='${bowerCommand}' if='bowerGloballyInstalled' +node nodeCommand='${bowerCmd} ${bowerCommand}' workingdir='${bowerDir}' if='!bowerGloballyInstalled' \ No newline at end of file diff --git a/build/_k-standard-goals.shade b/build/_k-standard-goals.shade index 88c744ceed..75d46a4f74 100644 --- a/build/_k-standard-goals.shade +++ b/build/_k-standard-goals.shade @@ -115,6 +115,33 @@ functions @{ .Select(p => Path.GetDirectoryName(p)) .Distinct(); } + bool TestCommand(string program, string commandline = null) { + // 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, + }; + 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"); + return true; + } + else { + Log.Warn(" command not found"); + return false; + } + } + catch (Exception) { + Log.Warn(" command not found"); + return false; + } + } } macro name='Exec' program='string' commandline='string' diff --git a/build/_node-install.shade b/build/_node-install.shade index 609d0b1cd6..c966ab8465 100644 --- a/build/_node-install.shade +++ b/build/_node-install.shade @@ -10,13 +10,14 @@ default nodeVer = '0.10.28' default npmVer = '1.4.9' default nodeExeSha = '628FFD6C3577068C00CEC9F6F897F0EC8F5212D9' default nodeInstallDir = '${Path.Combine(binDir, "nodejs")}' +default nodeGloballyInstalled = '${TestCommand("node --version")}' var nodeExe = 'node.exe' var npmZip = 'npm-${npmVer}.zip' var nodeDist = 'http://nodejs.org/dist/' var nodeUrl = '${nodeDist}v${nodeVer}/${nodeExe}' var npmUrl = '${nodeDist}npm/${npmZip}' -var doInstall = '${!File.Exists(nodeInstallDir)}' +var doInstall = '${!nodeGloballyInstalled && !Directory.Exists(nodeInstallDir)}' var nodeInstallExePath = '${Path.Combine(nodeInstallDir, nodeExe)}' var npmInstallZipPath = '${Path.Combine(nodeInstallDir, npmZip)}' diff --git a/build/_node.shade b/build/_node.shade index 1e4af244f7..323abd0b0d 100644 --- a/build/_node.shade +++ b/build/_node.shade @@ -1,6 +1,8 @@ default currentDir = '${Directory.GetCurrentDirectory()}' default nodeDir = '${Path.Combine(currentDir, "bin", "node")}' -var nodeExePath = '${Path.Combine(nodeDir, "node.exe")}' +default nodeGloballyInstalled = '${TestCommand("node --version")}' + +var nodeExePath = '${ nodeGloballyInstalled ? "node" : Path.Combine(nodeDir, "node.exe") }' node-install once='installNode' exec program='${nodeExePath}' commandline='${nodeCommand}' \ No newline at end of file diff --git a/build/_npm.shade b/build/_npm.shade index 68daf9793e..389a6107b1 100644 --- a/build/_npm.shade +++ b/build/_npm.shade @@ -1,7 +1,9 @@ default currentDir = '${Directory.GetCurrentDirectory()}' default nodeDir = '${Path.Combine(currentDir, "bin", "nodejs")}' default npmDir = '${currentDir}' -var npmCmd = '${Path.Combine(nodeDir, "npm.cmd")}' + +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