diff --git a/makefile.shade b/makefile.shade index f3b955467b..912f2497c7 100644 --- a/makefile.shade +++ b/makefile.shade @@ -1,6 +1,83 @@ +use namespace="System.Net" + var VERSION='0.1' var FULL_VERSION='0.1' var AUTHORS='Microsoft' use-standard-lifecycle -k-standard-goals \ No newline at end of file +k-standard-goals + +#install-node + var binDir = '${Path.Combine(Directory.GetCurrentDirectory(), "bin")}' + var nodeDir = '${Path.Combine(binDir, "node")}' + + -// Check if node is already installed locally + var nodeVer = '0.10.28' + var nodeMsi = 'node-v${nodeVer}-x86.msi' + var nodeUrl = 'http://nodejs.org/dist/v${nodeVer}/${nodeMsi}' + var nodeMsiPath = '${Path.Combine(binDir, nodeMsi)}' + var nodeInstalled = '${Directory.Exists(nodeDir)}' + @{ + Directory.CreateDirectory(nodeDir); + if (!nodeInstalled) { + // Download node installer msi + var wc = new WebClient(); + wc.DownloadFile(nodeUrl, nodeMsiPath); + } + } + + -// Extract it to local dir using msiexec: + exec program='msiexec' commandline='/a ${nodeMsiPath} /qb TARGETDIR=${nodeDir}' if='!nodeInstalled' + +#restore-npm-modules .install-node + var currentDir = '${Directory.GetCurrentDirectory()}' + var npmCmd = '${Path.Combine(currentDir, "bin", "node", "nodejs", "npm.cmd")}' + var sep = '${Path.DirectorySeparatorChar}' + @{ + // Find all dirs that contain a package.json file that aren't installed node modules + var npmDirs = Directory.GetFiles(currentDir, "package.json", SearchOption.AllDirectories) + .Where(p => p.IndexOf(sep + "node_modules" + sep) < 0 && + p.IndexOf(sep + "bower_components" + sep) < 0) + .Select(p => Path.GetDirectoryName(p)) + .Distinct(); + } + + exec program='${npmCmd}' commandline='install' workingdir='${dir}' each='var dir in npmDirs' + +#restore-bower-components .install-node + var currentDir = '${Directory.GetCurrentDirectory()}' + var nodeDir = '${Path.Combine(currentDir, "bin", "node", "nodejs")}' + var nodeExe = '${Path.Combine(nodeDir, "node.exe")}' + var npmCmd = '${Path.Combine(nodeDir, "npm.cmd")}' + var bowerInstalled = '${Directory.Exists(Path.Combine(nodeDir, "node_modules", "bower"))}' + var sep = '${Path.DirectorySeparatorChar}' + @{ + // Find all dirs that contain a bower.json file + var bowerDirs = Directory.GetFiles(currentDir, "bower.json", SearchOption.AllDirectories) + .Where(p => p.IndexOf(sep + "node_modules" + sep) < 0 && + p.IndexOf(sep + "bower_components" + sep) < 0) + .Select(p => Path.GetDirectoryName(p)) + .Distinct(); + } + + exec program='${npmCmd}' commandline='install --prefix ${nodeDir} bower' workingdir='${currentDir}' if='!bowerInstalled' + exec program='${nodeExe}' commandline='${Path.Combine(nodeDir, "node_modules", "bower", "bin", "bower")} install' workingdir='${dir}' each='var dir in bowerDirs' + +#run-grunt .restore-npm-modules .restore-bower-components target='compile' + var currentDir = '${Directory.GetCurrentDirectory()}' + var nodeDir = '${Path.Combine(currentDir, "bin", "node", "nodejs")}' + var nodeExe = '${Path.Combine(nodeDir, "node.exe")}' + var npmCmd = '${Path.Combine(nodeDir, "npm.cmd")}' + var gruntCliInstalled = '${Directory.Exists(Path.Combine(nodeDir, "node_modules", "grunt-cli"))}' + var sep = '${Path.DirectorySeparatorChar}' + @{ + // Find all dirs that contain a gruntfile.js file + var gruntDirs = Directory.GetFiles(currentDir, "gruntfile.js", SearchOption.AllDirectories) + .Where(p => p.IndexOf(sep + "node_modules" + sep) < 0 && + p.IndexOf(sep + "bower_components" + sep) < 0) + .Select(p => Path.GetDirectoryName(p)) + .Distinct(); + } + + exec program='${npmCmd}' commandline='install --prefix ${nodeDir} grunt-cli' workingdir='${currentDir}' if='!gruntCliInstalled' + exec program='${nodeExe}' commandline='${Path.Combine(nodeDir, "node_modules", "grunt-cli", "bin", "grunt")}' workingdir='${dir}' each='var dir in gruntDirs' \ No newline at end of file