crafti 0.0.18 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/README.md +85 -1
- data/lib/crafti/version.rb +1 -1
- data/lib/crafti.rb +36 -9
- data/test/assets/app_template.rb +2 -0
- data/test/dsl_test.rb +8 -2
- metadata +3 -3
- data/spike.rb +0 -110
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8766c9dd2a82d0af8cd5dddab5993b5e25146c33
|
4
|
+
data.tar.gz: 93303fa34da492afd27bcd70f221167744d57da4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4bd2a65671feafccc65c8504ef172367a4c2dc4e53e8663b4bf3d49afbad3f5e6caeb8deaa9dbf7cb4b6de4d668e4be0e1ee8770b791128ef206c40a45a0129
|
7
|
+
data.tar.gz: 3f61cef9c39cfe9b86b0586314a0400e78638c295229021f73b45542b73b355bd8811f30b04480958c3a11a76dc6d8e5c878da487c5b159353c00c179fe5cdec
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1 +1,85 @@
|
|
1
|
-
# Craft
|
1
|
+
# Craft - Project Generation Tool
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/revans/crafti.png?branch=master)](https://travis-ci.org/revans/crafti)
|
4
|
+
|
5
|
+
## About its Birth
|
6
|
+
|
7
|
+
I like modular applications. I'm tired of Rails bulk, so I prefer building libraries, using Rack, or using Sinatra in place of the kitchen sink that is Rails.
|
8
|
+
|
9
|
+
I build a lot of libraries. I write a lot of tiny/small applications that mostly do one thing. Each time I do, I tend to favor a certain type of folder structure, file setup, etc. Creating this by hand, each time, is extremely frusterating and goes against my own principles.
|
10
|
+
|
11
|
+
So, I decided to turn to a project generator. I could use some open source one, already built, but honestly, they're all bloated, kitchen-sink, crap - at least the ones I saw that were written in Ruby.
|
12
|
+
|
13
|
+
I could just use bash and I almost did. Then, as I was reading the docs for FileUtils for something else I was doing, I realized that FileUtils is a module and that lit a spark.
|
14
|
+
|
15
|
+
So, Crafti (don't ask me about the name...) was born.
|
16
|
+
|
17
|
+
I really wanted something that was bash like, but with Ruby block syntax. Something that you could read and get a basic understanding of what is being created. So, the current structure was what I came up with initially and then coded for. I like it, I don't care if you like it, but I'm happy if you want to use it.
|
18
|
+
|
19
|
+
## Examples
|
20
|
+
|
21
|
+
### Sinatra Style Structure
|
22
|
+
|
23
|
+
````ruby
|
24
|
+
root "appname" do
|
25
|
+
mkdirs "log", "test"
|
26
|
+
touch "Readme.mkd", "config.ru", "test/test_helper.rb"
|
27
|
+
end
|
28
|
+
````
|
29
|
+
|
30
|
+
### Use your own templates with ERB
|
31
|
+
|
32
|
+
Assume you have the following files in a directory:
|
33
|
+
|
34
|
+
* app_template.rb
|
35
|
+
* templates/config.ru.erb
|
36
|
+
* templates/test/test_helper.rb.erb
|
37
|
+
* templates/Procfile
|
38
|
+
* templates/Guardfile
|
39
|
+
* templates/Gemfile.erb
|
40
|
+
* templates/gitignore
|
41
|
+
|
42
|
+
````ruby
|
43
|
+
# inside the app_template.rb file
|
44
|
+
|
45
|
+
require 'pathname'
|
46
|
+
path = ::Pathname.new(path/to/template/file).expand_path
|
47
|
+
|
48
|
+
root "appname" do
|
49
|
+
mkdirs "test" # takes multiple arguments
|
50
|
+
mkdir "log" # takes a single argument
|
51
|
+
mkdir "assets/javascripts"
|
52
|
+
mkdir "assets/stylesheets"
|
53
|
+
|
54
|
+
touch "Readme.mkd" # can take multiple arguments
|
55
|
+
touch "assets/stylesheets/application.css.scss"
|
56
|
+
|
57
|
+
# 1st argument is the name and path of where the file will be created
|
58
|
+
# 2nd argument is the name/path to the template file
|
59
|
+
copy "Procfile", path.join("Procfile")
|
60
|
+
cp "Guardfile", path.join("Guardfile") # you can use either cp or copy
|
61
|
+
cp ".gitignore", path.join("gitignore")
|
62
|
+
|
63
|
+
template "Gemfile", # 1st argument is the name and path of where the file will be created
|
64
|
+
path.join("Gemfile.erb"), # 2nd argument is the actual template
|
65
|
+
{ ruby_version: '2.1.0' } # 3rd argument is a hash of variables for the ERB template
|
66
|
+
|
67
|
+
template "config.ru",
|
68
|
+
path.join("config.ru.erb"),
|
69
|
+
{ app_classname: 'FannyPackApplication' }
|
70
|
+
|
71
|
+
template "test/test_helper.rb",
|
72
|
+
path.join("test/test_helper.rb"),
|
73
|
+
{ app_classname: 'FannyPackApplication',
|
74
|
+
environment: 'ENV["RACK_ENV"]' }
|
75
|
+
|
76
|
+
run "bundle install --binstubs" # runs a terminal command
|
77
|
+
end
|
78
|
+
|
79
|
+
````
|
80
|
+
|
81
|
+
## Features coming....
|
82
|
+
|
83
|
+
* command to read templates from the internet (e.g. github)
|
84
|
+
* generate a starter template
|
85
|
+
* allow the main template file be an erb file where command options can be passed into (e.g. the name passed to the root method)
|
data/lib/crafti/version.rb
CHANGED
data/lib/crafti.rb
CHANGED
@@ -65,14 +65,6 @@ module Crafti
|
|
65
65
|
::FileUtils.chmod_R(mode, file)
|
66
66
|
end
|
67
67
|
|
68
|
-
def run(command)
|
69
|
-
system("cd #{app_path} && #{command}")
|
70
|
-
end
|
71
|
-
|
72
|
-
def sudo(command)
|
73
|
-
run "sudo #{command}"
|
74
|
-
end
|
75
|
-
|
76
68
|
def template(dest, erb_template, values)
|
77
69
|
temp = ::Pathname.new(erb_template)
|
78
70
|
|
@@ -99,7 +91,7 @@ module Crafti
|
|
99
91
|
|
100
92
|
def evaluate
|
101
93
|
klass = Class.new do
|
102
|
-
Kernel.extend(Crafti::KernelExtension)
|
94
|
+
::Kernel.extend(Crafti::KernelExtension)
|
103
95
|
def self.execute(string)
|
104
96
|
eval string
|
105
97
|
end
|
@@ -109,8 +101,43 @@ module Crafti
|
|
109
101
|
end
|
110
102
|
end
|
111
103
|
|
104
|
+
module RunCommands
|
105
|
+
def run(command)
|
106
|
+
system("cd #{app_path} && #{command}")
|
107
|
+
end
|
108
|
+
|
109
|
+
def sudo(command)
|
110
|
+
run "sudo #{command}"
|
111
|
+
end
|
112
|
+
|
113
|
+
def bower(*packages)
|
114
|
+
packages.each do |package|
|
115
|
+
run "bower install #{package}"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
module Git
|
121
|
+
include RunCommands
|
122
|
+
|
123
|
+
def git(command)
|
124
|
+
run "git #{command}"
|
125
|
+
end
|
126
|
+
|
127
|
+
class Init
|
128
|
+
end
|
129
|
+
|
130
|
+
class Add
|
131
|
+
end
|
132
|
+
|
133
|
+
class Commit
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
112
137
|
class Root
|
113
138
|
include FileUtilsExtension
|
139
|
+
include RunCommands
|
140
|
+
include Git
|
114
141
|
|
115
142
|
def self.root(appname, &block)
|
116
143
|
app = new(appname)
|
data/test/assets/app_template.rb
CHANGED
data/test/dsl_test.rb
CHANGED
@@ -10,8 +10,14 @@ class DSLTest < Minitest::Test
|
|
10
10
|
file = Crafti::FileReader.new(template_file)
|
11
11
|
file.evaluate
|
12
12
|
|
13
|
+
assert File.exists?("appname/.git")
|
14
|
+
|
13
15
|
assert File.exists?("appname")
|
14
|
-
|
15
|
-
|
16
|
+
cleanup("appname")
|
17
|
+
end
|
18
|
+
|
19
|
+
def cleanup(application_name)
|
20
|
+
FileUtils.rm_rf(application_name)
|
21
|
+
refute File.exists?(application_name)
|
16
22
|
end
|
17
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crafti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -61,6 +61,7 @@ extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE.txt
|
66
67
|
- README.md
|
@@ -71,7 +72,6 @@ files:
|
|
71
72
|
- lib/crafti/cli.rb
|
72
73
|
- lib/crafti/project.rb
|
73
74
|
- lib/crafti/version.rb
|
74
|
-
- spike.rb
|
75
75
|
- test/assets/app_template.rb
|
76
76
|
- test/assets/test_helper.rb.erb
|
77
77
|
- test/crafti_test.rb
|
data/spike.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'pathname'
|
3
|
-
|
4
|
-
module Generate
|
5
|
-
# generate files from templates
|
6
|
-
# generate directories
|
7
|
-
# copy files
|
8
|
-
# generate files via touch
|
9
|
-
#
|
10
|
-
# TODO:
|
11
|
-
#
|
12
|
-
# Turn FileUtils into a DSL
|
13
|
-
|
14
|
-
# Generate.project!(options.project_name, options.template_path)
|
15
|
-
def self.project!(project_name, template_path)
|
16
|
-
Project.new(project_name, template_path).generate
|
17
|
-
end
|
18
|
-
|
19
|
-
class Project
|
20
|
-
attr_reader :name, :path
|
21
|
-
|
22
|
-
def initialize(name, path)
|
23
|
-
@name, @path = name, ::Pathname.new(path).expand_path
|
24
|
-
end
|
25
|
-
|
26
|
-
def generate
|
27
|
-
eval do
|
28
|
-
include Template
|
29
|
-
path.read
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
module Template
|
35
|
-
extend FileUtils
|
36
|
-
|
37
|
-
def self.root(name, &block)
|
38
|
-
mkdir_p name
|
39
|
-
module_eval &block
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
# bin/generate file:
|
46
|
-
require 'rubygems'
|
47
|
-
require 'generate'
|
48
|
-
require 'optparse'
|
49
|
-
require 'ostruct'
|
50
|
-
|
51
|
-
class ProjectParser
|
52
|
-
def self.parse(args)
|
53
|
-
options = OpenStruct.new
|
54
|
-
options.project_name = args.reverse.pop
|
55
|
-
options.root_path = Dir.pwd
|
56
|
-
|
57
|
-
opt_parser = OptionParser.new do |opts|
|
58
|
-
opts.banner = "Usage: generate project_name app_template.rb"
|
59
|
-
|
60
|
-
opts.seperator ""
|
61
|
-
opts.on("-m", "--template", "The Template File used to create your project") do |template|
|
62
|
-
options.template_path = template
|
63
|
-
end
|
64
|
-
|
65
|
-
opts.on("-v", "--version", "Generate Version") do |v|
|
66
|
-
puts "Version Number 0.0.1"
|
67
|
-
exit
|
68
|
-
end
|
69
|
-
|
70
|
-
opts.on_tail("-h", "--help", "Get some Help") do
|
71
|
-
puts opts
|
72
|
-
exit
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
opt_parser.parse!(args)
|
77
|
-
options
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
options = ProjectParser.parse(ARGV)
|
83
|
-
puts options
|
84
|
-
puts ARGV
|
85
|
-
|
86
|
-
|
87
|
-
Generate.project!(options.project_name, options.template_path)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
# Run this by doing:
|
92
|
-
#
|
93
|
-
# generate project -m app_template.rb
|
94
|
-
|
95
|
-
|
96
|
-
# This is the app_template.rb file
|
97
|
-
#
|
98
|
-
root(appname) do
|
99
|
-
mkdir "config"
|
100
|
-
mkdir "log"
|
101
|
-
mkdir "test"
|
102
|
-
|
103
|
-
touch "Readme.mkd"
|
104
|
-
template "config.ru", file_or_string
|
105
|
-
template "config/application.rb", file_or_string
|
106
|
-
cp "test/test_helper.rb", file_or_string
|
107
|
-
template "bin/script", file_or_string
|
108
|
-
chmod "bin/script", 700
|
109
|
-
ln "db/database.yml", "db/database.yml.example"
|
110
|
-
end
|