strap 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ test/test_constants.rb
2
+
3
+ *.gem
4
+ *.rbc
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in strap.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'minitest' do
2
+ watch(%r|^test/(.*)\/?test_(.*)\.rb|)
3
+ watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
4
+ watch(%r|^test/test_helper\.rb|) { "test" }
5
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Matt Fordham
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,126 @@
1
+ # Strap
2
+
3
+ Strap is a simple tool for bootstrapping new projects based on a template Git repo. With a couple commands, it will check out the
4
+ specified repo into a new project directory, do some stuff*, initialize a new Git repo and push to the project's remote repo.
5
+
6
+ \* Before committing to the new repo, strap can create a database, import SQL, rename files and change file permissions.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'strap'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install strap
21
+
22
+ ## Usage
23
+
24
+ ### Bootstrapping a new project
25
+
26
+ To bootstrap a new project, execute:
27
+
28
+ $ strap init path/to/project
29
+
30
+ In the above example, the project directory will be named "project". This command will simply create the project directory and
31
+ drop a "Strapfile" in it for you to configure.
32
+
33
+ Once the Strapfile has been configured to your specific needs (more on that below), execute:
34
+
35
+ $ strap go
36
+
37
+ This command will check out the template repo specified in the Strapfile, run some some optional tasks and push the new project
38
+ to a remote repo, if one was specified.
39
+
40
+ ### The Strapfile
41
+
42
+ After running `strap init PATH`, you'll need to edit the project's Strapfile before running `strap go`. The Strapfile is where
43
+ you tell Strap what to do. All the options available to you are described in the default Strapfile:
44
+
45
+ ## REPO SETTINGS
46
+ ## ---------------------------
47
+ ## Source repo is required. Repo will be cloned into new project.
48
+
49
+ set :source_repo, ""
50
+
51
+ ## If 'destination_repo' is set, Strap will initialize a new Git repo
52
+ ## and push to specified remote destination.
53
+ # set :destination_repo, ""
54
+
55
+
56
+ ## DATABASE SETTINGS
57
+ ## ---------------------------
58
+ ## If you set at least 'db_name', 'db_user', and 'db_password', Strap
59
+ ## will attempt to create a database for you.
60
+
61
+ # set :db_name, ""
62
+ # set :db_user, ""
63
+ # set :db_password, ""
64
+ # set :db_socket, ""
65
+ # set :db_host, ""
66
+ # set :db_port, ""
67
+
68
+ ## If you specify an SQL file below, it'll be imported into your new DB.
69
+ # set :sql, ""
70
+
71
+
72
+ ## FILE UTILITIES
73
+ ## ---------------------------
74
+
75
+ ## Use this to rename a file before it gets committed to new repo
76
+ # rename_file "path/to/old_name", "path/to/new_name"
77
+
78
+ ## Use this to change permissions of a file before it gets committed
79
+ # change_permissions 0777, "change_permissions"
80
+
81
+
82
+ ## CUSTOM COMMANDS
83
+ ## ---------------------------
84
+ ## Use after_bootstrap to execute any custom Ruby code after the
85
+ ## bootstrap process
86
+
87
+ after_bootstrap do
88
+ # Do something using Ruby
89
+ end
90
+
91
+ At the very least, you'll need to set a source repo (otherwise there really isn't any point to using the tool).
92
+
93
+ ### Strapfile Templates
94
+
95
+ You may find that you'd like to customize the template Strapfile, or use multiple. To do this, first run the
96
+ following command:
97
+
98
+ $ strap install
99
+
100
+ This will create a ".strap" directory in your user home directory. Inside, you'll find a "default" Strapfile.
101
+ Edit this to change the default. Additionally, you can create other templates. For example if you put a
102
+ file named "wordpress" in the ".strap" directory containing settings for your default Wordpress install, you
103
+ could use "-t" flag to specify this custom template:
104
+
105
+ $ strap init path/to/project -t wordpress
106
+
107
+ The contents of the new project's Strapfile will match that of the "wordpress" template.
108
+
109
+ ## Inspiration
110
+
111
+ This project was inspired by Carl Crawley's EECI 2012 talk on bootstrapping ExpressionEngine. In particular, the bash script
112
+ he shared got me thinking. Thanks Carl! https://bitbucket.org/cwcrawley/eeci-talk-files/
113
+
114
+ ## To-do
115
+
116
+ * Add some more tests for CLI commands
117
+ * Figure out a way to mock file system actions in tests, the files don't actually have to be created
118
+ * Test in environments other than Mac OSX.
119
+
120
+ ## Contributing
121
+
122
+ 1. Fork it
123
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
124
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
125
+ 4. Push to the branch (`git push origin my-new-feature`)
126
+ 5. Create new Pull Request
data/bin/strap ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('../../lib/strap', __FILE__)
4
+
5
+ Strap::CLI.start(ARGV)
data/lib/strap/cli.rb ADDED
@@ -0,0 +1,66 @@
1
+ require 'thor'
2
+
3
+ module Strap
4
+
5
+ class CLI < Thor
6
+
7
+ desc "install", "Create '~/.strap' templates directory"
8
+ def install
9
+ if File.exists?(File.expand_path('~/.strap'))
10
+ say "'~/.strap' directory already exists\n", :red
11
+ else
12
+ Dir::mkdir(File.expand_path('~/.strap'))
13
+ FileUtils.cp(CONFIG_TEMPLATE, File.expand_path('~/.strap/default'))
14
+ say "'~/.strap' directory created. Add some template files.", :cyan
15
+ end
16
+ end
17
+
18
+ desc "init PATH", "Initialize a new project directory at PATH and generate Strapfile"
19
+ method_option :template, :aliases => "-t", :desc => "Specify a template Strapfile from '~/.strap'"
20
+ def init(path)
21
+ say ""
22
+ if File.exists?(path)
23
+ say "That directory already exists\n", :red
24
+ else
25
+ template = options[:template]
26
+ core = Strap::Core.new(self)
27
+ core.create_project_directory(path)
28
+ core.create_config(path, template)
29
+ core.update_database_name(path)
30
+ say "\nStrap project created. Now edit the Strapfile and run 'strap go' from the project directory to bootstrap your project.\n\n"
31
+ end
32
+ end
33
+
34
+ desc "go", "Bootstrap the project: clone bootstrap repo, create database, make first commit to project repo"
35
+ def go(strapfile = "Strapfile")
36
+ unless File.exists?(strapfile)
37
+ say "\nNo Strapfile in current directory. Use the 'strap init PATH' command first to setup your project directory and to initialize a Strapfile.\n", :red
38
+ return false
39
+ end
40
+ config = Strap::Config.new(strapfile)
41
+ core = Strap::Core.new(self)
42
+ core.clone_repo(config.source_repo)
43
+
44
+ core.create_database(config.db_user,
45
+ config.db_password,
46
+ config.db_socket,
47
+ config.db_name,
48
+ config.db_port,
49
+ config.db_host)
50
+
51
+ core.import_to_database(config.sql,
52
+ config.db_user,
53
+ config.db_password,
54
+ config.db_socket,
55
+ config.db_name,
56
+ config.db_port,
57
+ config.db_host)
58
+
59
+ core.commit_to_repo(config.destination_repo)
60
+
61
+ config.run_after_bootstrap
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,34 @@
1
+ module Strap
2
+
3
+ class Config
4
+
5
+ attr_accessor :db_name, :db_user, :db_password, :db_socket, :db_host, :db_port,
6
+ :sql, :source_repo, :destination_repo, :after
7
+
8
+ def initialize(file)
9
+ instance_eval File.read(file)
10
+ end
11
+
12
+ def set(key, value)
13
+ instance_variable_set("@#{key}", value)
14
+ end
15
+
16
+ def after_bootstrap(&block)
17
+ self.after = block
18
+ end
19
+
20
+ def run_after_bootstrap
21
+ instance_eval &after if after
22
+ end
23
+
24
+ def rename_file(old_name, new_name)
25
+ File.rename(old_name, new_name)
26
+ end
27
+
28
+ def change_permissions(permission, file)
29
+ File.chmod permission, file
30
+ end
31
+
32
+ end
33
+
34
+ end
data/lib/strap/core.rb ADDED
@@ -0,0 +1,128 @@
1
+ require 'mysql'
2
+
3
+ module Strap
4
+
5
+ class Core
6
+
7
+ attr_accessor :cli
8
+
9
+ def initialize(cli = nil)
10
+ self.cli = cli
11
+ end
12
+
13
+ def create_project_directory(path)
14
+ output "- Creating project directory: #{path}"
15
+ Dir::mkdir(path)
16
+ end
17
+
18
+ def create_config(path, template = nil)
19
+ strapfile = "#{path}/#{CONFIG_FILENAME}"
20
+ output "- Writing new config to #{strapfile}"
21
+ if template
22
+ config = File.expand_path(File.expand_path("~/.strap/#{template}"))
23
+ elsif File.exists?(File.expand_path('~/.strap/default'))
24
+ config = File.expand_path(File.expand_path('~/.strap/default'))
25
+ else
26
+ config = CONFIG_TEMPLATE
27
+ end
28
+ FileUtils.cp(config, strapfile)
29
+ end
30
+
31
+ def extract_project_name_from_path(path)
32
+ path.match(/\w*$/).to_s
33
+ end
34
+
35
+ def update_database_name(path)
36
+ project_name = extract_project_name_from_path(path)
37
+ bootfile = "#{path}/#{CONFIG_FILENAME}"
38
+ bootfile_text = File.read(bootfile)
39
+ temporary_database_name = /set :db_name,\s*("\w*")/.match(bootfile_text)[0]
40
+ updated_boofile_text = bootfile_text.gsub(/#{temporary_database_name}/, "set :db_name, \"#{project_name}\"")
41
+ File.open(bootfile, "w") do |file|
42
+ file.puts updated_boofile_text
43
+ end
44
+ end
45
+
46
+ def clone_repo(repo, directory=".")
47
+ if !repo.empty? && !File.exists?("#{directory}/.git")
48
+ output "- Cloning source repo"
49
+ clone = system("cd #{directory} && git clone #{repo} strap_temp")
50
+ unless clone
51
+ output "- Source repo clone failed", :error
52
+ exit
53
+ end
54
+ remove_tmp = system("cd #{directory} && shopt -s dotglob && mv strap_temp/* . && rm -rf strap_temp/* && rm -rf .git")
55
+ unless remove_tmp
56
+ output "- Removal of temporary clone failed", :error
57
+ exit
58
+ end
59
+ else
60
+ output "- No source repo provided", :error
61
+ exit
62
+ end
63
+ end
64
+
65
+ def commit_to_repo(repo, directory=".", force=false)
66
+ if !repo.empty?
67
+ commit = system("cd #{directory} && git init . && git add -A && git commit -m 'Initial commit from Strap'")
68
+ if commit
69
+ output "- Git repo initialized"
70
+ push = system("cd #{directory} && git remote add origin #{repo} && git push #{"-f" if force} origin master")
71
+ if push
72
+ output "- Project pushed to destination repo"
73
+ else
74
+ output "- Git push to destination repo failed", :error
75
+ exit
76
+ end
77
+ else
78
+ output "- Git init failed", :error
79
+ exit
80
+ end
81
+ end
82
+ end
83
+
84
+ def create_database(db_user, db_password, db_socket=nil, db_name=nil, db_port=nil, db_host=nil)
85
+ if db_user.empty? and db_password.empty? and db_name.empty?
86
+ return false
87
+ end
88
+ mysql = Mysql::new(db_host, db_user, db_password, nil, db_port, db_socket)
89
+ output("- Error connecting to MySQL", :error) unless mysql
90
+ db_exists = mysql.list_dbs.include?(db_name)
91
+ if db_exists
92
+ output "- Database already exists", :error
93
+ else
94
+ mysql.query("CREATE DATABASE #{db_name}")
95
+ mysql.list_dbs.include?(db_name) ? output("Database created") : output("Error creating database", :error)
96
+ end
97
+ end
98
+
99
+ def import_to_database(sql, db_user, db_password, db_socket=nil, db_name=nil, db_port=nil, db_host=nil)
100
+ if db_user.empty? and db_password.empty? and db_name.empty? and sql.empty?
101
+ return false
102
+ end
103
+ import = system("mysql -u#{db_user} -p#{db_password} -S#{db_socket} #{db_name} < #{sql}")
104
+ if import
105
+ output "- Database dump imported"
106
+ else
107
+ output "- Database import failed", :error
108
+ exit
109
+ end
110
+ end
111
+
112
+ private
113
+
114
+ def output(message, message_type = :notice)
115
+ if @cli
116
+ if message_type == :error
117
+ @cli.say message, :red
118
+ elsif message_type == :notice
119
+ @cli.say message, :cyan
120
+ end
121
+ else
122
+ puts message
123
+ end
124
+ end
125
+
126
+ end
127
+
128
+ end
@@ -0,0 +1,3 @@
1
+ module Strap
2
+ VERSION = "0.0.2"
3
+ end
data/lib/strap.rb ADDED
@@ -0,0 +1,14 @@
1
+ lib_dir = File.expand_path("..", __FILE__)
2
+ $:.unshift( lib_dir ) unless $:.include?( lib_dir )
3
+
4
+ require "strap/version"
5
+ require "strap/core"
6
+ require "strap/config"
7
+ require "strap/cli"
8
+
9
+ module Strap
10
+
11
+ CONFIG_FILENAME = "Strapfile"
12
+ CONFIG_TEMPLATE = File.expand_path("../templates/#{CONFIG_FILENAME}", __FILE__)
13
+
14
+ end
@@ -0,0 +1,45 @@
1
+ ## REPO SETTINGS
2
+ ## ---------------------------
3
+ ## Source repo is required. Repo will be cloned into new project.
4
+
5
+ set :source_repo, ""
6
+
7
+ ## If 'destination_repo' is set, Strap will initialize a new Git repo
8
+ ## and push to specified remote destination.
9
+ # set :destination_repo, ""
10
+
11
+
12
+ ## DATABASE SETTINGS
13
+ ## ---------------------------
14
+ ## If you set at least 'db_name', 'db_user', and 'db_password', Strap
15
+ ## will attempt to create a database for you.
16
+
17
+ # set :db_name, ""
18
+ # set :db_user, ""
19
+ # set :db_password, ""
20
+ # set :db_socket, ""
21
+ # set :db_host, ""
22
+ # set :db_port, ""
23
+
24
+ ## If you specify an SQL file below, it'll be imported into your new DB.
25
+ # set :sql, ""
26
+
27
+
28
+ ## FILE UTILITIES
29
+ ## ---------------------------
30
+
31
+ ## Use this to rename a file before it gets committed to new repo
32
+ # rename_file "path/to/old_name", "path/to/new_name"
33
+
34
+ ## Use this to change permissions of a file before it gets committed
35
+ # change_permissions 0777, "change_permissions"
36
+
37
+
38
+ ## CUSTOM COMMANDS
39
+ ## ---------------------------
40
+ ## Use after_bootstrap to execute any custom Ruby code after the
41
+ ## bootstrap process
42
+
43
+ after_bootstrap do
44
+ # Do something using Ruby
45
+ end
data/strap.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/strap/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Matt Fordham"]
6
+ gem.email = ["matt@revolvercreative.com"]
7
+ gem.description = %q{Bootstrap new projects based on a template Git repo}
8
+ gem.summary = %q{A simple tool for bootstrapping new projects based on a template Git repo}
9
+ gem.homepage = "http://github.com/mattfordham/Strap"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ # gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.executables = "strap"
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "strap"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = Strap::VERSION
18
+
19
+ gem.add_development_dependency 'rake'
20
+ gem.add_development_dependency 'debugger'
21
+ gem.add_development_dependency 'guard'
22
+ gem.add_development_dependency 'guard-minitest'
23
+ gem.add_development_dependency 'rb-fsevent'
24
+ gem.add_runtime_dependency "thor"
25
+ gem.add_runtime_dependency "mysql"
26
+ end
@@ -0,0 +1,31 @@
1
+ require_relative '../../test_helper'
2
+ require_relative '../../test_constants'
3
+ require "debugger"
4
+
5
+ describe Strap::CLI do
6
+
7
+ before do
8
+ @path = "test_project"
9
+ end
10
+
11
+ after do
12
+ FileUtils.remove_dir(@path) if File.directory?(@path)
13
+ end
14
+
15
+ it "should create a new project directory" do
16
+ Strap::CLI.start ["init", @path]
17
+ File.directory?(@path).must_equal true
18
+ end
19
+
20
+ it "should create a new Strapfile" do
21
+ Strap::CLI.start ["init", @path]
22
+ File.file?("#{@path}/#{Strap::CONFIG_FILENAME}").must_equal true
23
+ end
24
+
25
+ it "should update database name" do
26
+ Strap::CLI.start ["init", @path]
27
+ has_new_database_name = open("#{@path}/#{Strap::CONFIG_FILENAME}") { |f| f.grep(/set :db_name, "#{@path}"/) }
28
+ has_new_database_name.length.must_equal 1
29
+ end
30
+
31
+ end
@@ -0,0 +1,61 @@
1
+ require_relative '../../test_helper'
2
+ require_relative '../../test_constants'
3
+ require "debugger"
4
+
5
+ describe Strap::Config do
6
+
7
+ before do
8
+ @path = "test_path"
9
+ File.new("old_name", "w")
10
+ File.new("change_permissions", "w")
11
+ @core = Strap::Core.new
12
+ @core.create_project_directory(@path)
13
+ @core.create_config(@path)
14
+ end
15
+
16
+ after do
17
+ FileUtils.remove_file("old_name") if File.file?("old_name")
18
+ FileUtils.remove_file("new_name") if File.file?("new_name")
19
+ FileUtils.remove_file("change_permissions") if File.file?("change_permissions")
20
+ FileUtils.remove_dir(@path) if File.directory?(@path)
21
+ end
22
+
23
+ it "should set config variables" do
24
+ @config = Strap::Config.new("test/lib/templates/#{Strap::CONFIG_FILENAME}")
25
+ @config.db_name.must_equal "strap_tester"
26
+ @config.db_user.must_equal Strap::Test::MYSQL_USER
27
+ @config.db_password.must_equal Strap::Test::MYSQL_PASSWORD
28
+ @config.db_socket.must_equal Strap::Test::MYSQL_SOCKET
29
+ @config.db_host.must_equal Strap::Test::MYSQL_HOST
30
+ @config.db_port.must_equal Strap::Test::MYSQL_PORT
31
+ @config.source_repo.must_equal Strap::Test::SOURCE_REPO
32
+ @config.destination_repo.must_equal Strap::Test::DESTINATION_REPO
33
+ end
34
+
35
+ it "should set 'after' block" do
36
+ @config = Strap::Config.new("test/lib/templates/#{Strap::CONFIG_FILENAME}")
37
+ @config.run_after_bootstrap
38
+ @config.test.must_equal "it works!"
39
+ end
40
+
41
+ it "should rename a file" do
42
+ File.file?("old_name").must_equal true
43
+ @config = Strap::Config.new("test/lib/templates/#{Strap::CONFIG_FILENAME}")
44
+ File.file?("new_name").must_equal true
45
+ end
46
+
47
+ it "should change file permissions" do
48
+ @config = Strap::Config.new("test/lib/templates/#{Strap::CONFIG_FILENAME}")
49
+ File.stat("change_permissions").mode.must_equal 33279
50
+ end
51
+
52
+ end
53
+
54
+ module Strap
55
+ class Config
56
+ attr_accessor :test
57
+ def test_method
58
+ self.test = "it works!"
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,72 @@
1
+ require_relative '../../test_helper'
2
+ require_relative '../../test_constants'
3
+ require "debugger"
4
+
5
+ describe Strap::Core do
6
+
7
+ before do
8
+ @core = Strap::Core.new
9
+ @path = "test_path"
10
+ end
11
+
12
+ after do
13
+ FileUtils.remove_dir(@path) if File.directory?(@path)
14
+ end
15
+
16
+ it "should create project directory" do
17
+ @core.create_project_directory(@path)
18
+ File.directory?(@path).must_equal true
19
+ end
20
+
21
+ it "should create config file in directory" do
22
+ @core.create_project_directory(@path)
23
+ @core.create_config(@path)
24
+ File.file?("#{@path}/#{Strap::CONFIG_FILENAME}").must_equal true
25
+ end
26
+
27
+ it "should extract project name from path" do
28
+ path = "test/path/goes/here"
29
+ project_name = @core.extract_project_name_from_path(path)
30
+ project_name.must_equal "here"
31
+ end
32
+
33
+ it "should update database name" do
34
+ @core.create_project_directory(@path)
35
+ @core.create_config(@path)
36
+ @core.update_database_name(@path)
37
+ has_new_database_name = open("#{@path}/#{Strap::CONFIG_FILENAME}") { |f| f.grep(/set :db_name, "#{@path}"/) }
38
+ has_new_database_name.length.must_equal 1
39
+ end
40
+
41
+ it "should clone a repo and cleanup after itself" do
42
+ @core.create_project_directory(@path)
43
+ @core.clone_repo(Strap::Test::SOURCE_REPO, @path)
44
+ File.directory?("#{@path}/system").must_equal true
45
+ end
46
+
47
+ it "should initialize Git repo and push to new remote" do
48
+ @core.create_project_directory(@path)
49
+ @core.clone_repo(Strap::Test::SOURCE_REPO, @path)
50
+ @core.commit_to_repo(Strap::Test::DESTINATION_REPO, @path, true)
51
+ File.directory?("#{@path}/.git").must_equal true
52
+ end
53
+
54
+ it "should create a new database" do
55
+ mysql = Mysql::new(Strap::Test::MYSQL_HOST, Strap::Test::MYSQL_USER, Strap::Test::MYSQL_PASSWORD, nil, Strap::Test::MYSQL_PORT, Strap::Test::MYSQL_SOCKET)
56
+ mysql.list_dbs.include?("strap_tester").must_equal false
57
+ @core.create_database(Strap::Test::MYSQL_USER, Strap::Test::MYSQL_PASSWORD, Strap::Test::MYSQL_SOCKET, "strap_tester", Strap::Test::MYSQL_PORT, Strap::Test::MYSQL_HOST)
58
+ mysql.list_dbs.include?("strap_tester").must_equal true
59
+ mysql.query("DROP DATABASE strap_tester")
60
+ end
61
+
62
+ it "should import SQL to database" do
63
+ @core.create_database(Strap::Test::MYSQL_USER, Strap::Test::MYSQL_PASSWORD, Strap::Test::MYSQL_SOCKET, "strap_tester", Strap::Test::MYSQL_PORT, Strap::Test::MYSQL_HOST)
64
+ File.file?("test/sql/import_me.sql").must_equal true
65
+ @core.import_to_database("test/sql/import_me.sql", Strap::Test::MYSQL_USER, Strap::Test::MYSQL_PASSWORD, Strap::Test::MYSQL_SOCKET, "strap_tester", Strap::Test::MYSQL_PORT, Strap::Test::MYSQL_HOST)
66
+ mysql = Mysql::new(Strap::Test::MYSQL_HOST, Strap::Test::MYSQL_USER, Strap::Test::MYSQL_PASSWORD, "strap_tester", Strap::Test::MYSQL_PORT, Strap::Test::MYSQL_SOCKET)
67
+ res = mysql.query("select * from test")
68
+ res.num_rows.must_equal 3
69
+ mysql.query("DROP DATABASE strap_tester")
70
+ end
71
+
72
+ end
@@ -0,0 +1,16 @@
1
+ set :db_name, "strap_tester"
2
+ set :db_user, Strap::Test::MYSQL_USER
3
+ set :db_password, Strap::Test::MYSQL_PASSWORD
4
+ set :db_socket, Strap::Test::MYSQL_SOCKET
5
+ set :db_host, Strap::Test::MYSQL_HOST
6
+ set :db_port, Strap::Test::MYSQL_PORT
7
+ set :source_repo, Strap::Test::SOURCE_REPO
8
+ set :destination_repo, Strap::Test::DESTINATION_REPO
9
+
10
+ rename_file "old_name", "new_name"
11
+
12
+ change_permissions 0777, "change_permissions"
13
+
14
+ after_bootstrap do
15
+ test_method
16
+ end
@@ -0,0 +1,31 @@
1
+ /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
2
+ /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
3
+ /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
4
+ /*!40101 SET NAMES utf8 */;
5
+ /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
6
+ /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
7
+ /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
8
+
9
+
10
+ # Dump of table test
11
+ # ------------------------------------------------------------
12
+
13
+ DROP TABLE IF EXISTS `test`;
14
+
15
+ CREATE TABLE `test` (
16
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
17
+ `name` varchar(11) DEFAULT NULL,
18
+ PRIMARY KEY (`id`)
19
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
20
+
21
+ LOCK TABLES `test` WRITE;
22
+ /*!40000 ALTER TABLE `test` DISABLE KEYS */;
23
+
24
+ INSERT INTO `test` (`id`, `name`)
25
+ VALUES
26
+ (1,'Han'),
27
+ (2,'Luke'),
28
+ (3,'Chewbacca');
29
+
30
+ /*!40000 ALTER TABLE `test` ENABLE KEYS */;
31
+ UNLOCK TABLES;
@@ -0,0 +1,4 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+
4
+ require File.expand_path('../../lib/strap.rb', __FILE__)
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Fordham
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: debugger
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-minitest
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rb-fsevent
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: thor
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: mysql
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Bootstrap new projects based on a template Git repo
127
+ email:
128
+ - matt@revolvercreative.com
129
+ executables:
130
+ - strap
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - Gemfile
136
+ - Guardfile
137
+ - LICENSE
138
+ - README.md
139
+ - bin/strap
140
+ - lib/strap.rb
141
+ - lib/strap/cli.rb
142
+ - lib/strap/config.rb
143
+ - lib/strap/core.rb
144
+ - lib/strap/version.rb
145
+ - lib/templates/Strapfile
146
+ - strap.gemspec
147
+ - test/lib/strap/test_cli.rb
148
+ - test/lib/strap/test_config.rb
149
+ - test/lib/strap/test_core.rb
150
+ - test/lib/templates/Strapfile
151
+ - test/sql/import_me.sql
152
+ - test/test_helper.rb
153
+ homepage: http://github.com/mattfordham/Strap
154
+ licenses: []
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ! '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 1.8.24
174
+ signing_key:
175
+ specification_version: 3
176
+ summary: A simple tool for bootstrapping new projects based on a template Git repo
177
+ test_files:
178
+ - test/lib/strap/test_cli.rb
179
+ - test/lib/strap/test_config.rb
180
+ - test/lib/strap/test_core.rb
181
+ - test/lib/templates/Strapfile
182
+ - test/sql/import_me.sql
183
+ - test/test_helper.rb