projit 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rbenv-gemsets ADDED
@@ -0,0 +1 @@
1
+ projit global
data/.rvmrc ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.2-p180@projit"
8
+
9
+ echo "loading $environment_id"
10
+ #
11
+ # First we attempt to load the desired environment directly from the environment
12
+ # file. This is very fast and efficicent compared to running through the entire
13
+ # CLI and selector. If you want feedback on which environment was used then
14
+ # insert the word 'use' after --create as this triggers verbose mode.
15
+ #
16
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
17
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
18
+ then
19
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
20
+
21
+ if [[ -s "$rvm_path/hooks/after_use" ]]
22
+ then
23
+ . "$rvm_path/hooks/after_use"
24
+ fi
25
+ else
26
+ # If the environment file has not yet been created, use the RVM CLI to select.
27
+ if ! rvm --create "$environment_id"
28
+ then
29
+ echo "Failed to create RVM environment ''."
30
+ fi
31
+ fi
32
+
33
+ #
34
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
35
+ # it be automatically loaded. Uncomment the following and adjust the filename if
36
+ # necessary.
37
+ #
38
+ # filename=".gems"
39
+ # if [[ -s "$filename" ]] ; then
40
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
41
+ # fi
42
+
43
+ #
44
+ # If you use bundler and would like to run bundle each time you enter the
45
+ # directory, you can uncomment the following code.
46
+ #
47
+ # # Ensure that Bundler is installed. Install it if it is not.
48
+ # if ! command -v bundle >/dev/null; then
49
+ # printf "The rubygem 'bundler' is not installed. Installing it now.\n"
50
+ # gem install bundler
51
+ # fi
52
+ #
53
+ # # Bundle while reducing excess noise.
54
+ # printf "Bundling your gems. This may take a few minutes on a fresh clone.\n"
55
+ # bundle | grep -v '^Using ' | grep -v ' is complete' | sed '/^$/d'
56
+ #
57
+
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'projit', path: '.'
4
+ # Specify your gem's dependencies in projit.gemspec
5
+ gemspec
data/README.markdown ADDED
@@ -0,0 +1,34 @@
1
+ # A clean ~ keeps a development environment together
2
+
3
+ Projit is a utility to specify directory structures for the different types of projects you work on and consistently generate them. It very nicely supports creating directories and files, copying directories and files, symlinking to dropbox and cloning source code directly from any git repository.
4
+
5
+ ## Installation
6
+
7
+ gem install projit
8
+
9
+ If you don't use Ruby on a regular basis you may want to hold off until I get a chance to create some package manager recipes.
10
+
11
+ ## Usage
12
+
13
+ projit new personal/projit
14
+
15
+ This will run the recipe you have installed in `~/.projit/template.rb`. To get the generator that I use for web applications download [this gist][template].
16
+
17
+ projit new personal/projit --git joefiorini/projit
18
+
19
+ This will run the same recipe but also clone the specified git repository (assuming you have `clone_from_git` in your recipe).
20
+
21
+ projit new personal/projit\_demo --type screencast
22
+
23
+ Runs the recipe stored in `~/.projit/screencast.rb` to setup a directory structure for screencasting. To get the generator that I use for screencasting download [this gist][screencasting] (structure stolen from @topfunky).
24
+
25
+ ## Contributions
26
+
27
+ Contributions are encouraged, but given the very personal nature of workflows don't be suprised if I prefer creating recipes over adding to projit itself. Feel free to send pull requests though, it's the only way for me to see how other people use this. I will not accept Ruby code without spec coverage.
28
+
29
+ I would especially welcome package manager packages/tips. I don't want to require Rubygems for others to use this, but I have never packaged anything for distribution to brew/apt/emerge/port/etc.
30
+
31
+ Now, go get your home directory organized!
32
+
33
+ [template]: https://gist.github.com/1336554
34
+ [screencasting]: https://gist.github.com/1336563
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/projit ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'projit/cli'
4
+ Projit::CLI.start
data/lib/projit/cli.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'thor'
2
+ require 'projit'
3
+
4
+ module Projit
5
+ class CLI < Thor
6
+
7
+ desc "new NAME", "Create project named NAME under current directory or CLIENT if specified"
8
+ class_options dropbox: false, git: nil, type: nil
9
+ def new(name)
10
+ args = ARGV.reject { |a| a == "new" }
11
+ Projit::ProjectGenerator.start args
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,49 @@
1
+ module Projit
2
+
3
+ class Config
4
+
5
+ def projects_home
6
+ config_dir(read_config(:projects_home) || defaults[:projects_home])
7
+ end
8
+
9
+ def read_config(config)
10
+ return nil unless read_config_file
11
+ read_config_file[config.to_s]
12
+ end
13
+
14
+ def dropbox_configured?
15
+ !dropbox_home.nil?
16
+ end
17
+
18
+ def dropbox_home
19
+ config_dir(read_config(:dropbox_home) || defaults[:dropbox_home])
20
+ end
21
+
22
+ private
23
+
24
+ def read_config_file
25
+ begin
26
+ YAML.load_file(projit_config)
27
+ rescue
28
+ {}
29
+ end
30
+ end
31
+
32
+ def projit_config
33
+ File.expand_path("~/.projit/config")
34
+ end
35
+
36
+ def config_dir(dir)
37
+ return if dir.nil?
38
+ File.expand_path(dir)
39
+ end
40
+
41
+ def defaults
42
+ {
43
+ projects_home: "~/Projects",
44
+ dropbox_home: nil
45
+ }
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,110 @@
1
+ require 'thor/group'
2
+ require 'pathname'
3
+ require 'projit'
4
+
5
+ module Projit
6
+
7
+ class ProjectGenerator < Thor::Group
8
+ include Thor::Actions
9
+
10
+ source_root "~/.projit"
11
+
12
+ argument :project
13
+ class_options dropbox: false, git: nil
14
+ class_option :type, default: "template"
15
+
16
+ def new
17
+ apply projit_template
18
+ end
19
+
20
+
21
+ protected
22
+
23
+ def projit_template
24
+ "#{options[:type]}.rb"
25
+ end
26
+
27
+ def in_project_root(&block)
28
+ inside projects_home.to_s, &block
29
+ end
30
+
31
+ def in_project_directory(&block)
32
+ inside projects_home_path.join(project), &block
33
+ end
34
+
35
+ def create_link_in_dropbox(name)
36
+ return unless options[:dropbox]
37
+ unless dropbox_configured?
38
+ say "How can I create a link to your Dropbox if you haven't told me where in your Dropbox to create it? Please add a value for 'dropbox_home' to ~/.projit/config."
39
+ return
40
+ end
41
+ create_link dropbox_path_to(name), project_full_path
42
+ end
43
+
44
+ def clone_from_git_into(name)
45
+ return unless options[:git]
46
+
47
+ git = 'git clone'
48
+
49
+ if !hub_installed? && git_path =~ /github/
50
+ say "Did you know you that the `hub` command gives you secret GitHub powers? Install it with Homebrew using 'brew install hub'. Not using Homebrew? Ditch MacPorts and Fink and get it now! https://github.com/mxcl/homebrew"
51
+ elsif hub_installed?
52
+ git = 'hub clone -p'
53
+ end
54
+
55
+ say_status :clone, git_path
56
+ `#{git} #{git_path} #{project_full_path.join(name)}`
57
+ end
58
+
59
+ def project_path
60
+ Pathname.new project
61
+ end
62
+
63
+ def project_full_path
64
+ projects_home_path.join(project)
65
+ end
66
+
67
+ def project_base
68
+ project_path.basename.to_s
69
+ end
70
+
71
+ def projects_home_path
72
+ Pathname.new(projects_home)
73
+ end
74
+
75
+ def projects_home
76
+ config.projects_home
77
+ end
78
+
79
+ def git_path
80
+ options[:git]
81
+ end
82
+
83
+ def dropbox_path
84
+ Pathname.new dropbox_home
85
+ end
86
+
87
+ def dropbox_path_to(path)
88
+ dropbox_path.join(path).to_s
89
+ end
90
+
91
+ def dropbox_home
92
+ Projit.config.dropbox_home
93
+ end
94
+
95
+ def dropbox_configured?
96
+ config.dropbox_configured?
97
+ end
98
+
99
+ def config
100
+ Projit.config
101
+ end
102
+
103
+ def hub_installed?
104
+ `which hub`
105
+ $?.success?
106
+ end
107
+
108
+ end
109
+
110
+ end
@@ -0,0 +1,3 @@
1
+ module Projit
2
+ VERSION = "0.4.0"
3
+ end
data/lib/projit.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "projit/version"
2
+ require 'yaml'
3
+
4
+ module Projit
5
+
6
+ autoload :CLI, 'projit/cli'
7
+ autoload :Config, 'projit/config'
8
+ autoload :ProjectGenerator, 'projit/project_generator'
9
+
10
+ def self.config
11
+ @config ||= load_config!
12
+ @config
13
+ end
14
+
15
+ def self.load_config!
16
+ Config.new
17
+ end
18
+
19
+ end
data/projit.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "projit/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "projit"
7
+ s.version = Projit::VERSION
8
+ s.authors = ["Joe Fiorini"]
9
+ s.email = ["joe@joefiorini.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Generate project directory structure based on a switchable template.}
12
+ s.description = %q{Generate project directory structure based on a switchable template.}
13
+
14
+ s.rubyforge_project = "projit"
15
+
16
+ s.add_dependency 'thor'
17
+
18
+ s.add_development_dependency 'rspec'
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
@@ -0,0 +1,59 @@
1
+ require 'projit/config'
2
+
3
+ describe Projit::Config do
4
+
5
+ context "projit settings" do
6
+
7
+ before do
8
+ (subject.stub :read_config_file).and_return({ "projects_home" => "~/Testing" })
9
+ end
10
+
11
+ its(:projit_config) { should == "/Users/joe/.projit/config" }
12
+ its(:projects_home) { should == "/Users/joe/Testing" }
13
+
14
+ end
15
+
16
+ context "setting defaults" do
17
+
18
+ before do
19
+ (subject.stub :read_config_file).and_return(nil)
20
+ end
21
+
22
+ its(:projects_home) { should == "/Users/joe/Projects" }
23
+ its(:dropbox_home) { should be_nil }
24
+
25
+ end
26
+
27
+ context "reading config settings" do
28
+
29
+ before do
30
+ (subject.stub :read_config_file).and_return(nil)
31
+ end
32
+
33
+ it "doesn't crash for non-existant config" do
34
+ expect { subject.read_config(:blah) }.to_not raise_error
35
+ end
36
+
37
+ end
38
+
39
+ context "without dropbox configured" do
40
+
41
+ before do
42
+ (subject.stub :read_config_file).and_return "dropbox_home" => nil
43
+ end
44
+
45
+ its(:dropbox_configured?) { should be_false }
46
+
47
+ end
48
+
49
+ context "with dropbox configured" do
50
+
51
+ before do
52
+ (subject.stub :read_config_file).and_return "dropbox_home" => "/Users/joe/Dropbox/home"
53
+ end
54
+
55
+ its(:dropbox_home) { should == "/Users/joe/Dropbox/home" }
56
+ its(:dropbox_configured?) { should be_true }
57
+ end
58
+
59
+ end
@@ -0,0 +1,117 @@
1
+ require 'projit/project_generator'
2
+
3
+ describe Projit::ProjectGenerator do
4
+
5
+ subject { Projit::ProjectGenerator.new ["blah"] }
6
+
7
+ it "Loads projects_home from config settings" do
8
+ ((Projit.stub :config).and_return stub projects_home: "~/Projects")
9
+ (subject.send :projects_home).should == "~/Projects"
10
+ end
11
+
12
+ it "Loads dropbox_home from config settings" do
13
+ ((Projit.stub :config).and_return stub dropbox_home: "~/Dropbox/personal")
14
+ (subject.send :dropbox_home).should == "~/Dropbox/personal"
15
+ end
16
+
17
+ context "Dropbox integration" do
18
+
19
+ before do
20
+ subject.stub :create_link
21
+ end
22
+
23
+ it "Skips linking with Dropbox when option is not supplied" do
24
+ (subject.stub :options).and_return dropbox: false
25
+ subject.should_not_receive :create_link
26
+ subject.send :create_link_in_dropbox, "test"
27
+ end
28
+
29
+ context "with Dropbox configured" do
30
+
31
+ before do
32
+ subject.stub dropbox_configured?: true
33
+ subject.stub dropbox_path_to: "~/Dropbox/home/test"
34
+ (subject.stub :options).and_return dropbox: true
35
+ end
36
+
37
+ it "Symlinks the project to Dropbox" do
38
+ (subject.should_receive :create_link).with "~/Dropbox/home/test", anything
39
+ subject.send :create_link_in_dropbox, "test"
40
+ end
41
+
42
+ it "Loads Dropbox path from config" do
43
+ (subject.should_receive :dropbox_path_to).with 'test'
44
+ subject.send :create_link_in_dropbox, "test"
45
+ end
46
+
47
+ end
48
+
49
+ context "without Dropbox configured" do
50
+
51
+ before do
52
+ subject.stub dropbox_configured?: false
53
+ (subject.stub :options).and_return dropbox: true
54
+ end
55
+
56
+ it "Prints a warning" do
57
+ subject.should_receive :say
58
+ subject.send :create_link_in_dropbox, "test"
59
+ end
60
+
61
+ end
62
+
63
+ it "Gives access to the basename of the project directory" do
64
+ ((subject.stub :project_path).and_return Pathname.new "~/Projects/personal/test")
65
+ (subject.send :project_base).should == "test"
66
+ end
67
+
68
+ it "Provides helper for generating dropbox paths" do
69
+ subject.stub dropbox_path: (Pathname.new "~/Dropbox/home")
70
+ (subject.send :dropbox_path_to, "test").should == "~/Dropbox/home/test"
71
+ end
72
+
73
+ end
74
+
75
+ context "git integration" do
76
+
77
+ before do
78
+ subject.stub hub_installed?: true
79
+ subject.stub options: { git: 'test/blah' },
80
+ git_path: 'test/blah'
81
+ end
82
+
83
+ it "Doesn't clone from Git when option is not supplied" do
84
+ subject.stub options: {}
85
+ subject.should_not_receive :`
86
+ subject.send :clone_from_git_into, 'source'
87
+ end
88
+
89
+ it "Clones a repository from Git into specified directory" do
90
+ (subject.should_receive :`).with "hub clone -p test/blah /Users/joe/Projects/blah/source"
91
+ subject.send :clone_from_git_into, 'source'
92
+ end
93
+
94
+ it "Prints a warning if hub isn't installed" do
95
+ subject.stub :`
96
+ subject.stub(:git_path) { "http://github.com/blah/diddy" }
97
+ subject.stub hub_installed?: false
98
+ subject.should_receive :say
99
+ subject.send :clone_from_git_into, 'source'
100
+ end
101
+
102
+ it "uses git if hub is not installed" do
103
+ subject.stub hub_installed?: false
104
+ subject.should_receive(:`).with /^git clone test\/blah/
105
+ subject.send :clone_from_git_into, 'source'
106
+ end
107
+
108
+ end
109
+
110
+ context "support project types" do
111
+ it "uses type parameter to find the template script" do
112
+ subject.stub(options: { type: "web_application" })
113
+ subject.send(:projit_template).should eq "web_application.rb"
114
+ end
115
+ end
116
+
117
+ end
@@ -0,0 +1,15 @@
1
+ require 'projit'
2
+
3
+ describe Projit do
4
+
5
+ context "when retrieving config" do
6
+
7
+ it "loads config if not already set" do
8
+ Projit.instance_variable_set("@config", nil)
9
+ Projit.should_receive(:load_config!)
10
+ Projit.config
11
+ end
12
+
13
+ end
14
+
15
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: projit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joe Fiorini
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-03 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: &70287568473380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70287568473380
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70287568472960 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70287568472960
36
+ description: Generate project directory structure based on a switchable template.
37
+ email:
38
+ - joe@joefiorini.com
39
+ executables:
40
+ - projit
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - .rbenv-gemsets
46
+ - .rvmrc
47
+ - Gemfile
48
+ - README.markdown
49
+ - Rakefile
50
+ - bin/projit
51
+ - lib/projit.rb
52
+ - lib/projit/cli.rb
53
+ - lib/projit/config.rb
54
+ - lib/projit/project_generator.rb
55
+ - lib/projit/version.rb
56
+ - projit.gemspec
57
+ - spec/projit/config_spec.rb
58
+ - spec/projit/project_generator_spec.rb
59
+ - spec/projit_spec.rb
60
+ homepage: ''
61
+ licenses: []
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project: projit
80
+ rubygems_version: 1.8.10
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Generate project directory structure based on a switchable template.
84
+ test_files:
85
+ - spec/projit/config_spec.rb
86
+ - spec/projit/project_generator_spec.rb
87
+ - spec/projit_spec.rb