createproj 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 045cb71760b3a2dce81a177942026b9cea4b5e39
4
+ data.tar.gz: d66ea03637d889ea2ba2572c9a13ec4cab4de875
5
+ SHA512:
6
+ metadata.gz: ec84be874c255c02bdd44cdf03b33362e505a034b74eabb65a1bdb54d6f6e6f015269b2743d96cbb88a6aa317be8b41f18e112c63992b75116f8244e88b71c41
7
+ data.tar.gz: cae892efe39e517d58013fe9854b8ea657ff7ac71e7da6a9ebc4b437084bc3816dd38c4ee8a38ff1c285640148e62e5d46919458752d38f2cd782eaf157bb664
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # CreateProj
2
+
3
+ ## Description
4
+ Quickly create a new project with git respotitory, post commit hooks, and dependencies indended to be included for all projects.
5
+
6
+ Read more on my [blog](http://mattjmcnaughton.com/createproject).
7
+
8
+ ##
9
+
10
+ ## Steps for building/publish gem
11
+ - From `createproj` directory, run:
12
+ - `rake gem:build` to build the gem
13
+ - `rake gem:publish` to publish the gem
14
+
15
+ ## Development
16
+ - Code is linted using rubocop
17
+ - Code is documented using Yardoc
18
+
19
+ ## Assumptions
20
+ I built this largely for my personal use so there are a couple of assumptions made.
21
+ The first is that RVM and Cabal are installed.
22
+
23
+ ## Todo
24
+ - Setup Travis CI
25
+ - Setup test coverage metric and add test
26
+ - Integrate with one of the libraries for git pre-commit hooks?
27
+ - Multiple pre-commit hooks. Lint and test.
28
+ - Add other languages/frameworks (starting w/ Rails)
29
+
data/bin/createproj ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # make the load path include ../lib so can require createproj
4
+ $LOAD_PATH.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib')
5
+
6
+ require 'createproj'
7
+
8
+ # calls start command of Thor
9
+ CreateProj::CLI.start(ARGV)
@@ -0,0 +1,50 @@
1
+ # Namespace for CreateProj
2
+ module CreateProj
3
+ # Base class for CLI. Provides three project creation methods
4
+ # dependent on language type.
5
+ class CLI < Thor
6
+ # @todo use metaprogramming to simplify this?
7
+
8
+ # Command line input option for creating haskell project.
9
+ #
10
+ # @param [String] names the project
11
+ #
12
+ # @example Call from command line
13
+ # $ ./createproj haskell newproj #=> creates haskell proj called new proj
14
+ #
15
+ # @return Nothing
16
+ desc 'haskell NAME', 'create a haskell project called NAME'
17
+ def haskell(name)
18
+ CreateProj::Creator::HaskellCreator.new(name, options).run
19
+ end
20
+
21
+ # Command line input option for creating rails project.
22
+ #
23
+ # @param [String] names the project
24
+ #
25
+ # @example Call from command line
26
+ # $ ./createproj haskell newproj #=> creates rails proj called new proj
27
+ #
28
+ # @return Nothing
29
+ desc 'rails NAME', 'create a rails project called NAME'
30
+ method_option :database, aliases: '-d', desc: 'database to use'
31
+ method_option :javascript, aliases: '-j', desc: 'javascript library'
32
+ method_option :skip_test_unit, aliases: '-T', desc: 'skip test unit'
33
+ def rails(name)
34
+ CreateProj::Creator::RailsCreator.new(name, options).run
35
+ end
36
+
37
+ # Command line input option for creating ruby project.
38
+ #
39
+ # @param [String] names the project
40
+ #
41
+ # @example Call from command line
42
+ # $ ./createproj ruby newproj #=> creates ruby proj called new proj
43
+ #
44
+ # @return Nothing
45
+ desc 'ruby NAME', 'create a ruby project called NAME'
46
+ def ruby(name)
47
+ CreateProj::Creator::RubyCreator.new(name, options).run
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,100 @@
1
+ module CreateProj
2
+ module Creator
3
+ # Base class for all Creators.
4
+ #
5
+ # @attr_reader [String] name description of attributes name
6
+ # @attr_reader [Hash] options hash of options from command line input
7
+ class Creator
8
+ attr_reader :name
9
+ attr_reader :options
10
+
11
+ # Initialize method for class
12
+ #
13
+ # @param [String] name projects name
14
+ # @param [Hash] options command line options for the project
15
+ #
16
+ # @return instance of Creator
17
+ def initialize(name, options)
18
+ @name = name
19
+ @options = options
20
+ end
21
+
22
+ # Run instance of creator to create a project with the
23
+ # name and specified options.
24
+ #
25
+ # A subclass of creator can overwrite any of the methods called
26
+ # in this method if they wish to define a custom behavior
27
+ #
28
+ # @example Run an instance of the Creator class
29
+ # ruby_creator.run #=> ruby project will be created
30
+ #
31
+ # @return nothing but has side effects
32
+ def run
33
+ dir_name = create_directory(@name)
34
+
35
+ # all remaining ruby commands done from newly created directory
36
+ Dir.chdir(dir_name) do
37
+ init_git_repository
38
+ add_pre_commit_hook(@precommit_template, @precommit_options)
39
+ install_sandbox
40
+ install_dependencies
41
+ extra_setup
42
+ end
43
+ end
44
+
45
+ # Create a new directory with the given name
46
+ #
47
+ # @param [String] name the directory name
48
+ #
49
+ # @example Create a new directory
50
+ # create_directory("proj") #=> 'proj' (and dir called proj created)
51
+ #
52
+ # @return name of directory just created
53
+ def create_directory(name)
54
+ Dir.mkdir name
55
+ # To give flexibility to subclasses
56
+ name
57
+ end
58
+
59
+ # Initialize a new Git repository in the project directory
60
+ #
61
+ # @example Create a Git repository
62
+ # init_git_repository #=> git repository created
63
+ #
64
+ # @return Git base class (that will not be used)
65
+ def init_git_repository
66
+ Git.init
67
+ end
68
+
69
+ # Add a precommit hook based on a template
70
+ #
71
+ # @example Add a linting pre commit hook
72
+ # add_pre_commit_hook('lint-pre-commit',
73
+ # { linter: 'rubocop', file_ext: '.rb'} )
74
+ #
75
+ # @return nothing.
76
+ def add_pre_commit_hook(template, options)
77
+ template_path = File.join('../../templates', template)
78
+ hook = Mustache.render(File.read(template_path), options)
79
+ path_to_git = '.git/hooks/pre-commit'
80
+
81
+ # overwrite precommit hook with templated file
82
+ File.open(path_to_git, 'w+') do |f|
83
+ f.write(hook)
84
+ end
85
+ end
86
+
87
+ # overwrite in class
88
+ def install_sandbox
89
+ end
90
+
91
+ # overwrite in subclass
92
+ def install_dependencies
93
+ end
94
+
95
+ # intended to be overwritten per class
96
+ def extra_setup
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,38 @@
1
+ module CreateProj
2
+ module Creator
3
+ # Class for creating Haskell project
4
+ class HaskellCreator < Creator
5
+ def initialize(*args)
6
+ super(*args)
7
+ @precommit_template = 'lint-pre-commit'
8
+ @precommit_options = { linter: 'hlint', file_ext: '.hs' }
9
+ end
10
+
11
+ # Create an Haskell sandbox
12
+ #
13
+ # @example Create rvm sandbox for project named test
14
+ # install_sandbox #=> Executes `cabal sandbox init`
15
+ #
16
+ # @return Nothing
17
+ def install_sandbox
18
+ system('cabal sandbox init')
19
+ end
20
+
21
+ # Installs dependencies in the new cabal sandbox
22
+ #
23
+ # @example Installs rubocop in the gemset sandbox
24
+ # install_dependencies #=> happy & hlint installed in the gemset
25
+ #
26
+ # @return Nothing
27
+ def install_dependencies
28
+ cabals_to_install = %w(happy hlint)
29
+
30
+ system('cabal update')
31
+
32
+ cabals_to_install.each do |g|
33
+ system("cabal install #{g}")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,17 @@
1
+ module CreateProj
2
+ module Creator
3
+ # Class for creating Rails project
4
+ class RailsCreator < RubyCreator
5
+ def initialize
6
+ super
7
+ @precommit_template = 'lint-pre-commit'
8
+ @precommit_options = { linter: 'rubocop', file_ext: '.rb' }
9
+ end
10
+
11
+ # @todo - write for rails
12
+ def run
13
+ puts 'Coming soon!'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,44 @@
1
+ module CreateProj
2
+ module Creator
3
+ # Class for creating Ruby project
4
+ class RubyCreator < Creator
5
+ def initialize(*args)
6
+ super(*args)
7
+ @precommit_template = 'lint-pre-commit'
8
+ @precommit_options = { linter: 'rubocop', file_ext: '.rb' }
9
+ end
10
+
11
+ # Create an rvm gemset with the project name and
12
+ # creates file dictating gemset
13
+ #
14
+ # @todo - make it so can specify ruby version
15
+ #
16
+ # @example Create rvm sandbox for project named test
17
+ # install_sandbox #=> Executes `rvm gemset create test`
18
+ #
19
+ # @return Nothing
20
+ def install_sandbox
21
+ RVM.gemset_create @name
22
+ RVM.gemset_use @name
23
+
24
+ File.open('.ruby-gemset', 'w+') do |f|
25
+ f.write(@name)
26
+ end
27
+ end
28
+
29
+ # Installs dependencies in the new sandbox
30
+ #
31
+ # @example Installs rubocop in the gemset sandbox
32
+ # install_dependencies #=> rubocop is no installed in the gemset
33
+ #
34
+ # @return Nothing
35
+ def install_dependencies
36
+ gems_to_install = %w(rubocop)
37
+
38
+ gems_to_install.each do |g|
39
+ system("gem install #{g}")
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ # Namespace for CreateProj
2
+ module CreateProj
3
+ # Version number for the gem - make it only load once
4
+ VERSION ||= '0.0.2'
5
+ end
data/lib/createproj.rb ADDED
@@ -0,0 +1,13 @@
1
+ # require all files needed for createproj
2
+ require 'git'
3
+ require 'mustache'
4
+ require 'rvm'
5
+ require 'thor'
6
+
7
+ require 'createproj/version'
8
+ require 'createproj/cli'
9
+
10
+ require 'createproj/creator/creator'
11
+ require 'createproj/creator/haskell'
12
+ require 'createproj/creator/ruby'
13
+ require 'createproj/creator/rails'
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # taking this
4
+
5
+ require 'english'
6
+ require 'rubocop'
7
+
8
+ ADD_OR_MOD = /A|AM|^M/
9
+
10
+ all_added_or_mod = `git status --porcelain`.split(/\n/).select do |fn|
11
+ fn =~ ADD_OR_MOD
12
+ end
13
+
14
+ split = all_added_or_mod.map do |fn|
15
+ fn.split(' ')[1]
16
+ end
17
+
18
+ changed_files_arr = split.select do |fn|
19
+ File.extname(fn) == '{{ file_ext }}'
20
+ end
21
+
22
+ changed_files = changed_files_arr.join(' ')
23
+
24
+ system("{{ linter }} #{changed_files}") unless changed_files_arr.empty?
25
+ exit $CHILD_STATUS.to_s[-1].to_i
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: createproj
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Matt McNaughton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '10.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '10.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.28'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.28'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: git
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.2.8
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.2.8
97
+ - !ruby/object:Gem::Dependency
98
+ name: mustache
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 0.99.8
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.99.8
111
+ - !ruby/object:Gem::Dependency
112
+ name: rvm
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 1.11.3.9
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 1.11.3.9
125
+ - !ruby/object:Gem::Dependency
126
+ name: thor
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 0.19.1
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 0.19.1
139
+ description: Simple project creation gem.
140
+ email:
141
+ - mattjmcnaughton@gmail.com
142
+ executables:
143
+ - createproj
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - README.md
148
+ - bin/createproj
149
+ - lib/createproj.rb
150
+ - lib/createproj/cli.rb
151
+ - lib/createproj/creator/creator.rb
152
+ - lib/createproj/creator/haskell.rb
153
+ - lib/createproj/creator/rails.rb
154
+ - lib/createproj/creator/ruby.rb
155
+ - lib/createproj/version.rb
156
+ - templates/lint-pre-commit
157
+ homepage: https://github.com/mattjmcnaughton/createproj
158
+ licenses:
159
+ - MIT
160
+ metadata: {}
161
+ post_install_message:
162
+ rdoc_options: []
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - '>='
173
+ - !ruby/object:Gem::Version
174
+ version: 1.3.6
175
+ requirements: []
176
+ rubyforge_project: createproj
177
+ rubygems_version: 2.2.2
178
+ signing_key:
179
+ specification_version: 4
180
+ summary: Gem to make project creation easier!
181
+ test_files: []
182
+ has_rdoc: