mise_en_place 0.1.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/bin/console +8 -0
- data/bin/setup +6 -0
- data/exe/mise_en_place +8 -0
- data/lib/mise_en_place/mise.rb +139 -0
- data/lib/mise_en_place/parser.rb +55 -0
- data/lib/mise_en_place/version.rb +3 -0
- data/mise_en_place.gemspec +32 -0
- data/sample_config.yml +12 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d2ee03a9e595096ccc9f73aa0b042afb1cd977d3
|
4
|
+
data.tar.gz: ae15bd5d4d80e483c25677315ed0069f8a2728dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9d1b7636b2f9b40e8876ac49527ee82b793de57077b672965edfdb50a2a470300b7ccadcf62c9b66420c79aef59e21a7da69885f99d51e7994570c838efb00d1
|
7
|
+
data.tar.gz: 50fb138888ae6285a98059078599b3734524ec940f1864b215c36ac1070c586d3e0dcc2ee95a9fbe5f16f5e8bc887b92e59582c0531311d18737dfb8ab955416
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Patrick O'Brien
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
[](https://travis-ci.org/pmo3/mise_en_place)
|
2
|
+
|
3
|
+
# MiseEnPlace
|
4
|
+
|
5
|
+
MiseEnPlace is a ruby gem made for quick and easy bootstrapping of new projects. By specifying your desired directory structure in YAML files, you can create folders and files for complex projects with one command.
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'mise_en_place'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install mise_en_place
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Basic usage is `mise_en_place PROJECT_NAME`.
|
25
|
+
|
26
|
+
By default Mise looks in the current directory and its parents for a .mise_en_place.yml file, but you can specify the location of a config file with `-c` or `--config`.
|
27
|
+
|
28
|
+
A config file should look something like this:
|
29
|
+
|
30
|
+
```yaml
|
31
|
+
---
|
32
|
+
- default:
|
33
|
+
- js:
|
34
|
+
- index.js
|
35
|
+
- subfolder:
|
36
|
+
- something.js
|
37
|
+
- index.html
|
38
|
+
- images
|
39
|
+
|
40
|
+
- html:
|
41
|
+
- index.html
|
42
|
+
- contact.html
|
43
|
+
```
|
44
|
+
The `default` structure is required, and will be used in the absence of the project flag. To use a different structure specify the type with `-p` or `--project`
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pmo3/mise_en_place.
|
54
|
+
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/exe/mise_en_place
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'yaml'
|
5
|
+
require 'pathname'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'optparse'
|
8
|
+
|
9
|
+
module MiseEnPlace
|
10
|
+
class Mise
|
11
|
+
CONFIG_FILENAME = ".mise_en_place.yml"
|
12
|
+
CONFIG_PATH = Pathname(File.expand_path('~')) + CONFIG_FILENAME
|
13
|
+
|
14
|
+
def initialize(options={})
|
15
|
+
@options = OpenStruct.new options
|
16
|
+
@top_level_dir = Pathname(@options.project_name)
|
17
|
+
request_and_overwrite if File.exist? @top_level_dir
|
18
|
+
FileUtils.mkdir_p(@top_level_dir)
|
19
|
+
end
|
20
|
+
|
21
|
+
def options
|
22
|
+
@options
|
23
|
+
end
|
24
|
+
|
25
|
+
def fetch_yaml(config_path=@options.config)
|
26
|
+
begin
|
27
|
+
full_yaml = YAML.load_file(config_path || find_config)
|
28
|
+
unless full_yaml
|
29
|
+
warn_no_project_type
|
30
|
+
return
|
31
|
+
end
|
32
|
+
project_type = options.project_type || "default"
|
33
|
+
full_yaml = full_yaml.reduce(:merge)[project_type]
|
34
|
+
warn_no_project_type unless full_yaml
|
35
|
+
return full_yaml
|
36
|
+
rescue Errno::ENOENT, TypeError
|
37
|
+
puts "\
|
38
|
+
Please make sure a file named #{CONFIG_FILENAME} exists in your current directory or any of its parent directories or specify a path with the --config option"
|
39
|
+
exit(false)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_file_structure(yaml=fetch_yaml, path=@top_level_dir)
|
44
|
+
path = Pathname(path)
|
45
|
+
return unless yaml
|
46
|
+
yaml.each do |file|
|
47
|
+
if file.is_a?(Hash)
|
48
|
+
file.values.each do |sub_file|
|
49
|
+
build_file_structure(sub_file, path + file.keys.first)
|
50
|
+
end
|
51
|
+
else
|
52
|
+
# cast to Array to avoid type checking between Array or String
|
53
|
+
Array[file].each do |sub_file|
|
54
|
+
create_file_or_dir(sub_file, path)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def warn_no_project_type
|
63
|
+
puts "\
|
64
|
+
Could not find a valid yaml structure for your project. Make sure that a default structure or one for your project type exists in your config file. Try something like this:
|
65
|
+
|
66
|
+
---
|
67
|
+
- default:
|
68
|
+
- file_structure_here
|
69
|
+
"
|
70
|
+
puts "\
|
71
|
+
- #{options.project_type}
|
72
|
+
- file_structure_here" if options.project_type
|
73
|
+
exit(false)
|
74
|
+
return
|
75
|
+
end
|
76
|
+
|
77
|
+
def create_file_or_dir(file_or_dir, path)
|
78
|
+
full_path = Pathname(path + file_or_dir)
|
79
|
+
if is_dir?(file_or_dir)
|
80
|
+
FileUtils.mkdir_p(full_path)
|
81
|
+
else
|
82
|
+
FileUtils.mkdir_p(path)
|
83
|
+
FileUtils.touch(full_path)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def is_dir?(file_or_dir)
|
88
|
+
Pathname(file_or_dir).extname == ""
|
89
|
+
end
|
90
|
+
|
91
|
+
def find_config
|
92
|
+
path = Pathname(Dir.pwd)
|
93
|
+
while path != Pathname("/")
|
94
|
+
return path + CONFIG_FILENAME if File.exist? path + CONFIG_FILENAME
|
95
|
+
path = path.parent
|
96
|
+
end
|
97
|
+
return request_and_build_config
|
98
|
+
end
|
99
|
+
|
100
|
+
def request_and_build_config
|
101
|
+
input = ask_to_build_config
|
102
|
+
if input == "" || input == "y"
|
103
|
+
|
104
|
+
File.open(CONFIG_PATH, 'w') do |f|
|
105
|
+
f.puts "---"
|
106
|
+
f.puts "- default:"
|
107
|
+
end unless File.exist? CONFIG_PATH
|
108
|
+
puts "File created at #{CONFIG_PATH}. Add your desired project structure under default and run MiseEnPlace again."
|
109
|
+
return CONFIG_PATH
|
110
|
+
else
|
111
|
+
|
112
|
+
return nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def ask_to_build_config
|
117
|
+
puts "Could not find a config file. Would you like to create one now? [Y/n]"
|
118
|
+
gets.chomp.downcase
|
119
|
+
end
|
120
|
+
|
121
|
+
def ask_to_overwrite
|
122
|
+
puts "A folder with #{@top_level_dir} already exists. Overwrite? [y/N]"
|
123
|
+
gets.chomp.downcase
|
124
|
+
end
|
125
|
+
|
126
|
+
def request_and_overwrite
|
127
|
+
input = ask_to_overwrite
|
128
|
+
if input == "y"
|
129
|
+
return true
|
130
|
+
else
|
131
|
+
exit(false)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def command_line_args
|
136
|
+
ARGV
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'optparse'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
module MiseEnPlace
|
6
|
+
class Parser
|
7
|
+
FLAGS = %w(-c --config -h --help -p --project)
|
8
|
+
|
9
|
+
def self.parse(args)
|
10
|
+
options = OpenStruct.new
|
11
|
+
|
12
|
+
opt_parser = OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: ProjectCreator [project_title] [options]"
|
14
|
+
opts.separator ""
|
15
|
+
opts.separator "Specific Options:"
|
16
|
+
|
17
|
+
opts.on("-c", "--config PATH", "Path to your config file") do |path|
|
18
|
+
options.config = Pathname(path)
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-h", "--help", "Show this message") do
|
22
|
+
puts ""
|
23
|
+
puts opts
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on("-p", "--project TYPE", "Specify a project type that matches a type in your config file") do |type|
|
28
|
+
options.project_type = type
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on_tail("-v", "--version", "Show Version number") do
|
32
|
+
puts VERSION
|
33
|
+
exit
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
opt_parser.parse!(args)
|
38
|
+
project_name = args.shift
|
39
|
+
unless valid_project_name? project_name
|
40
|
+
puts "Please specify a project name"
|
41
|
+
exit(false)
|
42
|
+
end
|
43
|
+
options.project_name = project_name
|
44
|
+
options
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def self.valid_project_name?(project_name)
|
50
|
+
is_flag = FLAGS.include? project_name
|
51
|
+
does_not_exist = (project_name == nil)
|
52
|
+
return !(is_flag || does_not_exist)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "mise_en_place/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "mise_en_place"
|
7
|
+
spec.version = MiseEnPlace::VERSION
|
8
|
+
spec.platform = Gem::Platform::RUBY
|
9
|
+
spec.authors = ["Patrick O'Brien"]
|
10
|
+
spec.email = ["patrick@patrickmobrien.com"]
|
11
|
+
spec.homepage = "http://rubygems.org/gems/mise_en_place"
|
12
|
+
spec.summary = %q{A gem to quickly bootstrap new projects by specifying directory structure in yaml files}
|
13
|
+
spec.description = %q{MiseEnPlace is a ruby gem made for quick and easy bootstrapping of new projects. By specifying your desired directory structure in YAML files, you can create folders and files for complex projects with one command.}
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
end
|
data/sample_config.yml
ADDED
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mise_en_place
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patrick O'Brien
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: MiseEnPlace is a ruby gem made for quick and easy bootstrapping of new
|
56
|
+
projects. By specifying your desired directory structure in YAML files, you can
|
57
|
+
create folders and files for complex projects with one command.
|
58
|
+
email:
|
59
|
+
- patrick@patrickmobrien.com
|
60
|
+
executables:
|
61
|
+
- mise_en_place
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- ".gitignore"
|
66
|
+
- ".rspec"
|
67
|
+
- ".travis.yml"
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- exe/mise_en_place
|
75
|
+
- lib/mise_en_place/mise.rb
|
76
|
+
- lib/mise_en_place/parser.rb
|
77
|
+
- lib/mise_en_place/version.rb
|
78
|
+
- mise_en_place.gemspec
|
79
|
+
- sample_config.yml
|
80
|
+
homepage: http://rubygems.org/gems/mise_en_place
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata:
|
84
|
+
allowed_push_host: https://rubygems.org
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.4.8
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: A gem to quickly bootstrap new projects by specifying directory structure
|
105
|
+
in yaml files
|
106
|
+
test_files: []
|