Skip to content

Commit

Permalink
added sidekick
Browse files Browse the repository at this point in the history
  • Loading branch information
amirrajan committed Aug 5, 2012
1 parent 625c6e1 commit aa1f71b
Show file tree
Hide file tree
Showing 18 changed files with 284 additions and 105 deletions.
Binary file modified __NAME__.suo
Binary file not shown.
2 changes: 1 addition & 1 deletion __NAME__/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<packages>
<package id="oak-edge" version="1.3.9" targetFramework="net40" />
<package id="rake-dot-net" version="1.2.3" />
<package id="specwatchr" version="1.6.1" />
<package id="specwatchr" version="1.6.4" targetFramework="net40" />
</packages>
83 changes: 52 additions & 31 deletions dotnet.watchr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,40 +161,37 @@
if you have the nuget package rake-dot-net installed you can use the following lines to build and deploy mvc applications everytime you save a web specific file
make sure to set your builder to :RakeBuilder
=end
watch ('(.*.cshtml)|(.*.js)|(.*.css)$') do |md|
if(@dw.config[:builder] == :RakeBuilder && File.exists?("RakeDotNet")) #make sure that the configuration is set to RakeBuilder and RakeDotNet is installed
failed = false #variable to determine if the file sync failed

if(md[0].match /App_Code/) #run the rake command if a web file in App_Code changed
@dw.sh.execute RakeBuilder.rake_command
else
output = @dw.sh.execute "rake sync[\"#{ md[0] }\"]" #run rake-dot-net's file sync command if any other web file changed

failed = true if output =~ /rake aborted!/ #set failed equal to true if the sync failed
end

@dw.notifier.execute "website deployed", "deployed", "green" unless failed #growl

#notify the dev that the version of rake they are using may be incorrect
@dw.notifier.execute "sync failed",
"it looks like the sync failed, this usually happens if the version of rake you are running is NOT 0.8.7. Please ensure you are running version 0.8.7 of rake. To see the gem versions that are installed, run the command 'gem list' in a command prompt that supports ruby.",
"red" if failed
else
puts "A web file was encountered, but it looks like you don't have rake-dot-net installed. I would auto deploy if you did."
end
end

#everything after this is specwatchr specific, feel free to dig into this, the source code for specwatchr is located in watcher_dot_net.rb
def handle filename
@dw.consider filename
end

def reload file
@dw.notifier.execute "reloading", "Reloading SpecWatchr because #{file} changed.", "green"
FileUtils.touch "dotnet.watchr.rb"
def handle_webfile filename
if(@dw.config[:builder] == :RakeBuilder && File.exists?("RakeDotNet")) #make sure that the configuration is set to RakeBuilder and RakeDotNet is installed
failed = false #variable to determine if the file sync failed

if(filename.match /App_Code/) #run the rake command if a web file in App_Code changed
@dw.sh.execute RakeBuilder.rake_command
else
output = @dw.sh.execute "rake sync[\"#{ filename }\"]" #run rake-dot-net's file sync command if any other web file changed

failed = true if output =~ /rake aborted!/ #set failed equal to true if the sync failed
end

@dw.notifier.execute "website deployed", "deployed", "green" unless failed #growl

#notify the dev that the version of rake they are using may be incorrect
@dw.notifier.execute "sync failed",
"it looks like the sync failed, this usually happens if the version of rake you are running is NOT 0.8.7. Please ensure you are running version 0.8.7 of rake. To see the gem versions that are installed, run the command 'gem list' in a command prompt that supports ruby.",
"red" if failed
else
puts "A web file was encountered, but it looks like you don't have rake-dot-net installed. I would auto deploy if you did."
end
end

def tutorial
@dw.notifier.execute "specwatchr", "feedback loop engaged", "green"
puts "======================== SpecWatcher has started ==========================\n\n"
puts "TEST RUNNER: #{@dw.test_runner.class}\n\n"
puts "(you can change your test runner in dotnet.watchr.rb...)\n\n"
Expand Down Expand Up @@ -223,13 +220,37 @@ def tutorial
puts @dw.test_runner.usage
end

tutorial
def file_changed full_path
if full_path =~ /.*.\.cs$/
handle full_path
end

#this is how the watchr gem determines files to run through spec watchr
watch ('.*.\.cs$') do |md|
handle md[0]
if full_path =~ /(.*.cshtml)|(.*.js)|(.*.css)$/
handle_webfile full_path
end
end

watch ('(.*.csproj$)|(.*.sln$)') do |md|
reload md[0]
method_to_run = ARGV[0] #get the first argument from the command line and act accordingly

case method_to_run
when "tutorial"
tutorial
when "file_changed"
file_changed ARGV[1].gsub("\\", "\/")[1..-1] #run the file_changed routine giving it a shell compatible file name
else
puts "I dont know how to run: " + method_to_run
end


#this is how the watchr gem determines files to run through spec watchr
#watch ('.*.\.cs$') do |md|
# handle md[0]
#end

#watch ('(.*.csproj$)|(.*.sln$)') do |md|
# reload md[0]
#end

#watch ('(.*.cshtml)|(.*.js)|(.*.css)$') do |md|

#end
22 changes: 0 additions & 22 deletions packages/specwatchr.1.6.1/tools/install.ps1

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -161,40 +161,37 @@
if you have the nuget package rake-dot-net installed you can use the following lines to build and deploy mvc applications everytime you save a web specific file
make sure to set your builder to :RakeBuilder
=end
watch ('(.*.cshtml)|(.*.js)|(.*.css)$') do |md|
if(@dw.config[:builder] == :RakeBuilder && File.exists?("RakeDotNet")) #make sure that the configuration is set to RakeBuilder and RakeDotNet is installed
failed = false #variable to determine if the file sync failed

if(md[0].match /App_Code/) #run the rake command if a web file in App_Code changed
@dw.sh.execute RakeBuilder.rake_command
else
output = @dw.sh.execute "rake sync[\"#{ md[0] }\"]" #run rake-dot-net's file sync command if any other web file changed

failed = true if output =~ /rake aborted!/ #set failed equal to true if the sync failed
end

@dw.notifier.execute "website deployed", "deployed", "green" unless failed #growl

#notify the dev that the version of rake they are using may be incorrect
@dw.notifier.execute "sync failed",
"it looks like the sync failed, this usually happens if the version of rake you are running is NOT 0.8.7. Please ensure you are running version 0.8.7 of rake. To see the gem versions that are installed, run the command 'gem list' in a command prompt that supports ruby.",
"red" if failed
else
puts "A web file was encountered, but it looks like you don't have rake-dot-net installed. I would auto deploy if you did."
end
end

#everything after this is specwatchr specific, feel free to dig into this, the source code for specwatchr is located in watcher_dot_net.rb
def handle filename
@dw.consider filename
end

def reload file
@dw.notifier.execute "reloading", "Reloading SpecWatchr because #{file} changed.", "green"
FileUtils.touch "dotnet.watchr.rb"
def handle_webfile filename
if(@dw.config[:builder] == :RakeBuilder && File.exists?("RakeDotNet")) #make sure that the configuration is set to RakeBuilder and RakeDotNet is installed
failed = false #variable to determine if the file sync failed

if(filename.match /App_Code/) #run the rake command if a web file in App_Code changed
@dw.sh.execute RakeBuilder.rake_command
else
output = @dw.sh.execute "rake sync[\"#{ filename }\"]" #run rake-dot-net's file sync command if any other web file changed

failed = true if output =~ /rake aborted!/ #set failed equal to true if the sync failed
end

@dw.notifier.execute "website deployed", "deployed", "green" unless failed #growl

#notify the dev that the version of rake they are using may be incorrect
@dw.notifier.execute "sync failed",
"it looks like the sync failed, this usually happens if the version of rake you are running is NOT 0.8.7. Please ensure you are running version 0.8.7 of rake. To see the gem versions that are installed, run the command 'gem list' in a command prompt that supports ruby.",
"red" if failed
else
puts "A web file was encountered, but it looks like you don't have rake-dot-net installed. I would auto deploy if you did."
end
end

def tutorial
@dw.notifier.execute "specwatchr", "feedback loop engaged", "green"
puts "======================== SpecWatcher has started ==========================\n\n"
puts "TEST RUNNER: #{@dw.test_runner.class}\n\n"
puts "(you can change your test runner in dotnet.watchr.rb...)\n\n"
Expand Down Expand Up @@ -223,13 +220,37 @@ def tutorial
puts @dw.test_runner.usage
end

tutorial
def file_changed full_path
if full_path =~ /.*.\.cs$/
handle full_path
end

#this is how the watchr gem determines files to run through spec watchr
watch ('.*.\.cs$') do |md|
handle md[0]
if full_path =~ /(.*.cshtml)|(.*.js)|(.*.css)$/
handle_webfile full_path
end
end

watch ('(.*.csproj$)|(.*.sln$)') do |md|
reload md[0]
method_to_run = ARGV[0] #get the first argument from the command line and act accordingly

case method_to_run
when "tutorial"
tutorial
when "file_changed"
file_changed ARGV[1].gsub("\\", "\/")[1..-1] #run the file_changed routine giving it a shell compatible file name
else
puts "I dont know how to run: " + method_to_run
end


#this is how the watchr gem determines files to run through spec watchr
#watch ('.*.\.cs$') do |md|
# handle md[0]
#end

#watch ('(.*.csproj$)|(.*.sln$)') do |md|
# reload md[0]
#end

#watch ('(.*.cshtml)|(.*.js)|(.*.css)$') do |md|

#end
File renamed without changes
File renamed without changes
3 changes: 3 additions & 0 deletions packages/specwatchr.1.6.4/src/sidekick.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ECHO ON
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe sidekickapp.cs
sidekickapp.exe
59 changes: 59 additions & 0 deletions packages/specwatchr.1.6.4/src/sidekickapp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace SyncDeploy
{
class Program
{
static string path = null;
static FileSystemWatcher watcher;

static void Main(string[] args)
{
path = Directory.GetCurrentDirectory();
watcher = new FileSystemWatcher(path, "*.*");
watcher.IncludeSubdirectories = true;
watcher.EnableRaisingEvents = true;
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
watcher.Created += new FileSystemEventHandler(watcher_Changed);
Console.WriteLine("Watching " + path + " for changes, press Enter to stop...");
Shell("tutorial");
Console.ReadLine();

}

static void Shell(params string[] args)
{
ProcessStartInfo processStartInfo = new ProcessStartInfo("ruby", "dotnet.watchr.rb " + string.Join(" ", args));
processStartInfo.UseShellExecute = false;
processStartInfo.ErrorDialog = false;
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;
Process process = new Process();
process.StartInfo = processStartInfo;
bool processStarted = process.Start();

StreamWriter inputWriter = process.StandardInput;
StreamReader outputReader = process.StandardOutput;
StreamReader errorReader = process.StandardError;
process.WaitForExit();
System.Console.Write(outputReader.ReadToEnd());
System.Console.Write(errorReader.ReadToEnd());
}

static void watcher_Changed(object sender, FileSystemEventArgs e)
{
watcher.EnableRaisingEvents = false;
var relativeFile = e.FullPath.Replace(Directory.GetCurrentDirectory(), "");
System.Console.WriteLine("Changed: " + relativeFile);
Shell("file_changed", relativeFile);
watcher.EnableRaisingEvents = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,6 @@ def consider file
@notifier.execute "specwatchr", "The solution structure you have is unsupported by specwatchr. CS Projects need to be in their own directories (as opposed to .csproj's existing at the same level as the .sln file). If this is a new project, go back and recreate it...but this time make sure that the \"Create directory for solution\" check box is checked.", "red"
return
end

if(@first_run)
@notifier.execute "specwatchr", "feedback loop engaged", "green"
@first_run = false
end

puts "====================== changed: #{file} ===================="
puts "====================== excluded ============================" if false == require_build(file)
Expand All @@ -758,20 +753,17 @@ def consider file
end

build_output = @builder.execute

puts build_output

@notifier.execute "build failed", build_output.each_line.first, 'red' if @builder.failed
@notifier.execute "build failed", build_output, 'red' if @builder.failed

if @builder.failed
puts "===================== done consider ========================"
return
end

if @test_runner.test_dlls.count == 0
@notifier.execute "build done", "didn't find any tests though...see console", "green"

puts "specwatchr didn't find any test dll's. specwatchr looks for a .csproj that ends in Test, Tests, Spec, or Specs. If you do have that, stop specwatchr, rebuild your solution and start specwatchr back up. If you want to explicitly specify the test dll's, you can do so via dotnet.watchr.rb."
@notifier.execute "discovery", "specwatchr didn't find any test dll's. specwatchr looks for a .csproj that ends in Test, Tests, Spec, or Specs. If you do have that, stop specwatchr, rebuild your solution and start specwatchr back up. If you want to explicitly specify the test dll's, you can do so via dotnet.watchr.rb.", "red"

puts "===================== done consider ========================"
return
Expand Down
6 changes: 6 additions & 0 deletions packages/specwatchr.1.6.4/src/watchr.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
echo OFF
echo ==========================================================
echo ==========================================================
echo The "watchr" command is deprecated. Just type: sidekick
echo ==========================================================
echo ==========================================================
39 changes: 39 additions & 0 deletions packages/specwatchr.1.6.4/tools/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
param($rootPath, $toolsPath, $package, $project)

$configFileFrom = $toolsPath + "\..\src\dotnet.watchr.rb"
$configFileTo = "dotnet.watchr.rb"

$watchrFileFrom = $toolsPath + "\..\src\watcher_dot_net.rb"
$watchrFileTo = "watcher_dot_net.rb"

$redFileFrom = $toolsPath + "\..\src\red.png"
$redFileTo = "red.png"

$greenFileFrom = $toolsPath + "\..\src\green.png"
$greenFileTo = "green.png"

$sidekickbatFileFrom = $toolsPath + "\..\src\sidekick.bat"
$sidekickbatFileTo = "sidekick.bat"

$watchrbatFileFrom = $toolsPath + "\..\src\watchr.bat"
$watchrbatFileTo = "watchr.bat"

$sidekickcsFileFrom = $toolsPath + "\..\src\sidekickapp.cs"
$sidekickcdFileTo = "sidekickapp.cs"

if(!(Test-Path $configFileTo))
{
Copy-Item $configFileFrom $configFileTo
Copy-Item $watchrFileFrom $watchrFileTo
Copy-Item $redFileFrom $redFileTo
Copy-Item $greenFileFrom $greenFileTo
Copy-Item $sidekickcsFileFrom $sidekickcsFileTo
Copy-Item $sidekickbatFileFrom $sidekickbatFileTo
Copy-Item $watchrbatFileFrom $watchrbatFileTo
}
else
{
Write-Host ""
Write-Host "files were not copied to root directory, because it looks like they already exist, go to the package directory and copy all the files from " $toolsPath "\..\src to the root directory (unless you've changed them of course)"
}

3 changes: 3 additions & 0 deletions sidekick.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ECHO ON
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe sidekickapp.cs
sidekickapp.exe
Loading

0 comments on commit aa1f71b

Please sign in to comment.