new 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +79 -0
- data/Guardfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +121 -0
- data/bin/new +6 -0
- data/lib/new/cli.rb +94 -0
- data/lib/new/core.rb +6 -0
- data/lib/new/dsl.rb +42 -0
- data/lib/new/interpolate.rb +100 -0
- data/lib/new/project.rb +34 -0
- data/lib/new/task.rb +41 -0
- data/lib/new/template.rb +64 -0
- data/lib/new/version.rb +41 -0
- data/lib/new.rb +72 -0
- data/spec/fixtures/custom/tasks/custom_bar_task/custom_bar_task.rb +3 -0
- data/spec/fixtures/custom/templates/custom_bar_template/custom_bar.txt +0 -0
- data/spec/fixtures/tasks/custom_bar_task/custom_bar_task.rb +1 -0
- data/spec/fixtures/tasks/foo_task/foo_task.rb +7 -0
- data/spec/fixtures/templates/foo_template/[FOO.BAR].txt.erb +1 -0
- data/spec/fixtures/templates/foo_template/nested_[FOO.BAR]/foo.txt.erb +1 -0
- data/spec/lib/new/cli_spec.rb +104 -0
- data/spec/lib/new/interpolate_spec.rb +41 -0
- data/spec/lib/new/project_spec.rb +30 -0
- data/spec/lib/new/task_spec.rb +39 -0
- data/spec/lib/new/template_spec.rb +59 -0
- data/spec/lib/new/version_spec.rb +28 -0
- data/spec/lib/new_spec.rb +19 -0
- data/spec/spec_helper.rb +26 -0
- data/tasks/gem/README.md +36 -0
- data/tasks/gem/gem.rb +118 -0
- data/templates/js/Gemfile +30 -0
- data/templates/js/Guardfile +7 -0
- data/templates/js/LICENSE-MIT.erb +22 -0
- data/templates/js/README.md.erb +61 -0
- data/templates/js/demo/index.html.erb +7 -0
- data/templates/js/lib/README.md +2 -0
- data/templates/js/spec/[PROJECT_NAME].spec.js.coffee.erb +1 -0
- data/templates/js/spec/index.html.erb +29 -0
- data/templates/js/spec/spec_helper.js.coffee +0 -0
- data/templates/js/spec/vendor/chai.js +3765 -0
- data/templates/js/spec/vendor/sinon-chai.js +106 -0
- data/templates/js/spec/vendor/sinon.js +4246 -0
- data/templates/js/src/README.md +3 -0
- data/templates/js/src/[PROJECT_NAME].js.coffee.erb +10 -0
- data/templates/js/testem.yml +12 -0
- metadata +102 -0
data/lib/new/version.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module New::Version
|
2
|
+
require 'semantic'
|
3
|
+
|
4
|
+
def version= string
|
5
|
+
@version ||= begin
|
6
|
+
Semantic::Version.new string
|
7
|
+
rescue
|
8
|
+
New.say "#{string} is not a semantic version. Use format `1.2.3`", type: :fail
|
9
|
+
exit
|
10
|
+
end
|
11
|
+
end
|
12
|
+
def version; @version; end
|
13
|
+
|
14
|
+
def bump_version part
|
15
|
+
case part
|
16
|
+
when :major
|
17
|
+
version.major += 1
|
18
|
+
when :minor
|
19
|
+
version.minor += 1
|
20
|
+
when :patch
|
21
|
+
version.patch += 1
|
22
|
+
end
|
23
|
+
|
24
|
+
version
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_part
|
28
|
+
New.say " Current Version: #{version}", type: :success
|
29
|
+
New.say " Specify which part to bump: [#{'Mmp'.green}] (#{'M'.green}ajor / #{'m'.green}inor / #{'p'.green}atch)"
|
30
|
+
part = STDIN.gets.chomp!
|
31
|
+
|
32
|
+
case part
|
33
|
+
when 'M'
|
34
|
+
:major
|
35
|
+
when 'm'
|
36
|
+
:minor
|
37
|
+
when 'p'
|
38
|
+
:patch
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/new.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class New
|
4
|
+
VERSION = '0.0.1'
|
5
|
+
DEFAULT_DIR = File.expand_path('../..', __FILE__)
|
6
|
+
CUSTOM_DIR = File.expand_path('~/.new')
|
7
|
+
TEMP_DIR = File.expand_path('../../.tmp', __FILE__)
|
8
|
+
TASKS_DIR_NAME = 'tasks'
|
9
|
+
TEMPLATES_DIR_NAME = 'templates'
|
10
|
+
CONFIG_FILE = '.new'
|
11
|
+
|
12
|
+
# List all the available tasks
|
13
|
+
#
|
14
|
+
def self.tasks
|
15
|
+
custom_tasks | default_tasks
|
16
|
+
end
|
17
|
+
|
18
|
+
# List all the available templates
|
19
|
+
#
|
20
|
+
def self.templates
|
21
|
+
custom_templates | default_templates
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.default_templates
|
25
|
+
@default_templates ||= get_list TEMPLATES_DIR_NAME, :default
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.custom_templates
|
29
|
+
@custom_templates ||= get_list TEMPLATES_DIR_NAME, :custom
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.default_tasks
|
33
|
+
@default_tasks ||= get_list TASKS_DIR_NAME, :default
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.custom_tasks
|
37
|
+
@custom_tasks ||= get_list TASKS_DIR_NAME, :custom
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.custom_config
|
41
|
+
@custom_config ||= YAML.load(File.open(File.join(CUSTOM_DIR, CONFIG_FILE))).deep_symbolize_keys! rescue {}
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def self.get_list dir, filter
|
47
|
+
case filter
|
48
|
+
when :default
|
49
|
+
Dir[File.join(DEFAULT_DIR, dir, '**')]
|
50
|
+
when :custom
|
51
|
+
Dir[File.join(CUSTOM_DIR, dir, '**')]
|
52
|
+
end.map{ |d| File.basename(d).to_sym }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# core
|
57
|
+
require 'new/core'
|
58
|
+
|
59
|
+
# modules
|
60
|
+
require 'new/dsl'
|
61
|
+
require 'new/interpolate'
|
62
|
+
require 'new/version'
|
63
|
+
|
64
|
+
# classes
|
65
|
+
require 'new/cli'
|
66
|
+
require 'new/project'
|
67
|
+
require 'new/template'
|
68
|
+
require 'new/task'
|
69
|
+
|
70
|
+
class New
|
71
|
+
extend New::Dsl
|
72
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
raise 'This class should not have been loaded since there is a custom task that should be taking precedence'
|
@@ -0,0 +1 @@
|
|
1
|
+
foo <%= foo.bar %>
|
@@ -0,0 +1 @@
|
|
1
|
+
foo <%= foo.bar %>
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe New::Cli do
|
4
|
+
describe '#projects' do
|
5
|
+
before do
|
6
|
+
New.stub(:templates).and_return([:foo])
|
7
|
+
subject.stub(:project)
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
New.unstub(:templates)
|
12
|
+
subject.unstub(:project)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should accept template name as argument' do
|
16
|
+
expect { subject.foo 'party' }.to_not raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should raise an error if no name is given' do
|
20
|
+
expect { subject.foo }.to raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should raise an error for non-template argument' do
|
24
|
+
expect { subject.bar }.to raise_error
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#init' do
|
29
|
+
before do
|
30
|
+
stub_const 'New::CUSTOM_DIR', root('.tmp', '.new')
|
31
|
+
subject.init
|
32
|
+
end
|
33
|
+
|
34
|
+
after :all do
|
35
|
+
FileUtils.rm_r root('.tmp', '.new')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should create .new dir' do
|
39
|
+
expect(Dir.exists?(root('.tmp', '.new'))).to be_true
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should create .new file' do
|
43
|
+
expect(File.exists?(root('.tmp', '.new', '.new'))).to be_true
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should create an empty templates & tasks dir' do
|
47
|
+
expect(Dir.exists?(root('.tmp', '.new', 'templates'))).to be_true
|
48
|
+
expect(Dir.exists?(root('.tmp', '.new', 'tasks'))).to be_true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#release' do
|
53
|
+
context 'for an invalid project' do
|
54
|
+
before do
|
55
|
+
Dir.chdir root('.tmp')
|
56
|
+
File.delete '.new' rescue nil
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should raise an error if no config file is found' do
|
60
|
+
expect { subject.release }.to raise_error
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'for a valid project' do
|
65
|
+
before do
|
66
|
+
Dir.chdir root('spec', 'fixtures', 'project')
|
67
|
+
end
|
68
|
+
|
69
|
+
# test that the task is required
|
70
|
+
describe 'require' do
|
71
|
+
before do
|
72
|
+
New::Task.stub(:inherited)
|
73
|
+
subject.release
|
74
|
+
end
|
75
|
+
|
76
|
+
after do
|
77
|
+
New::Task.unstub(:inherited)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should require the task' do
|
81
|
+
expect(New::Task).to have_received(:inherited).with(New::Task::FooTask).once
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# test that the task is initialized
|
86
|
+
describe 'initialize' do
|
87
|
+
before do
|
88
|
+
require root('spec', 'fixtures', 'custom', 'tasks', 'custom_bar_task', 'custom_bar_task')
|
89
|
+
New::Task::CustomBarTask.stub(:new)
|
90
|
+
stub_const 'New::CONFIG_FILE', '.new_cli_release_spec'
|
91
|
+
subject.release
|
92
|
+
end
|
93
|
+
|
94
|
+
after do
|
95
|
+
New::Task::CustomBarTask.unstub(:new)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should initialize the task' do
|
99
|
+
expect(New::Task::CustomBarTask).to have_received(:new).with({ tasks: { custom_bar_task: nil }})
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class InterpolateSpec
|
4
|
+
include New::Interpolate
|
5
|
+
end
|
6
|
+
|
7
|
+
describe New::Interpolate do
|
8
|
+
let(:template_dir){ root('spec', 'fixtures', 'templates', 'foo_template') }
|
9
|
+
|
10
|
+
before do
|
11
|
+
# don't use let. since interpolate creates files, we only want to generate files once to test aginst.
|
12
|
+
@obj = InterpolateSpec.new
|
13
|
+
@obj.interpolate(template_dir, {
|
14
|
+
'foo' => {
|
15
|
+
'bar' => 'baz'
|
16
|
+
}
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
FileUtils.rm_rf @obj.dir
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should process and rename .erb files' do
|
25
|
+
# check that files exist
|
26
|
+
expect(File.exists?(File.join(@obj.dir, 'baz.txt'))).to eq true
|
27
|
+
expect(File.exists?(File.join(@obj.dir, 'nested_baz', 'foo.txt'))).to eq true
|
28
|
+
|
29
|
+
# check their content has been processed
|
30
|
+
expect(File.open(File.join(@obj.dir, 'baz.txt')).read).to include 'foo baz'
|
31
|
+
expect(File.open(File.join(@obj.dir, 'nested_baz', 'foo.txt')).read).to include 'foo baz'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should create dot notation accessible options' do
|
35
|
+
expect(@obj.dot_options.foo.bar).to eq('baz')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should respond to options as methods' do
|
39
|
+
expect(@obj.foo.bar).to eq 'baz'
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'recursive-open-struct'
|
3
|
+
|
4
|
+
describe New::Project do
|
5
|
+
let(:template_dir){ File.join(New::TEMP_DIR, 'custom_bar_template') }
|
6
|
+
let(:project_dir){ File.join(New::TEMP_DIR, 'new_project') }
|
7
|
+
let(:project){ New::Project.new(:custom_bar_template, :new_project) }
|
8
|
+
let(:project_config) { YAML.load(File.open(File.join(project_dir, New::CONFIG_FILE))).deep_symbolize_keys! }
|
9
|
+
|
10
|
+
before do
|
11
|
+
Dir.chdir New::TEMP_DIR
|
12
|
+
FileUtils.cp_r root('spec', 'fixtures', 'custom', 'templates', 'custom_bar_template'), New::TEMP_DIR
|
13
|
+
New::Template.stub(:new).and_return(RecursiveOpenStruct.new({ options: {}, dir: template_dir }))
|
14
|
+
project
|
15
|
+
end
|
16
|
+
|
17
|
+
after do
|
18
|
+
New::Template.unstub(:new)
|
19
|
+
FileUtils.rm_rf template_dir
|
20
|
+
FileUtils.rm_rf project_dir
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should copy the template' do
|
24
|
+
expect(Dir.exists?(project_dir)).to eq true
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should create a config file' do
|
28
|
+
expect(File.exists?(File.join(project_dir, New::CONFIG_FILE))).to eq true
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class New::Task::TaskSpec < New::Task
|
5
|
+
OPTIONS = {
|
6
|
+
default: true
|
7
|
+
}
|
8
|
+
def run; end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe New::Task do
|
12
|
+
let(:task){ New::Task::TaskSpec.new YAML.load(File.open(root('spec', 'fixtures', 'project', '.new'))).deep_symbolize_keys! }
|
13
|
+
|
14
|
+
describe '.inherited' do
|
15
|
+
it 'should create a name from the class name' do
|
16
|
+
expect(task.class.name).to eq :task_spec
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'instances' do
|
21
|
+
before do
|
22
|
+
task.stub(:name).and_return(:foo_task)
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
task.unstub(:name)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should not merge other tasks in' do
|
30
|
+
# make sure the custom config has the extra task, and make sure it doesnt come through to the task
|
31
|
+
expect(YAML.load(File.open(root('spec', 'fixtures', 'custom', New::CONFIG_FILE))).deep_symbolize_keys![:tasks].has_key?(:dont_include)).to be_true
|
32
|
+
expect(task.project_options[:tasks].has_key?(:dont_include)).to be_false
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should get the correct task options' do
|
36
|
+
expect(task.options).to eq({ foo: 'project', project: true, custom: true, default: true })
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe New::Template do
|
4
|
+
subject(:template){ New::Template.new type, 'new_template' }
|
5
|
+
let(:type){ :foo_template }
|
6
|
+
|
7
|
+
before do
|
8
|
+
New::Template.any_instance.stub(:interpolate)
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
New::Template.any_instance.unstub(:interpolate)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#template_dir' do
|
16
|
+
context 'with a default template' do
|
17
|
+
let(:type){ :foo_template }
|
18
|
+
|
19
|
+
it 'should return the default template path' do
|
20
|
+
expect(template.send(:template_dir)).to eq File.join(New::DEFAULT_DIR, New::TEMPLATES_DIR_NAME, type.to_s)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with a custom template' do
|
25
|
+
let(:type){ :custom_bar_template }
|
26
|
+
|
27
|
+
it 'should return the custom template path' do
|
28
|
+
expect(template.send(:template_dir)).to eq File.join(New::CUSTOM_DIR, New::TEMPLATES_DIR_NAME, type.to_s)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should set the custom flag' do
|
32
|
+
expect(template.instance_variable_get('@custom')).to be_true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#options' do
|
38
|
+
before do
|
39
|
+
stub_const('New::Template::CUSTOM_CONFIG_TEMPLATE', { default: true })
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should build complete options' do
|
43
|
+
options = template.send(:options)
|
44
|
+
|
45
|
+
# check default template options
|
46
|
+
expect(options[:default]).to be_true
|
47
|
+
|
48
|
+
# check template options
|
49
|
+
expect(options[:template]).to be_true
|
50
|
+
|
51
|
+
# check custom config options
|
52
|
+
expect(options[:custom]).to be_true
|
53
|
+
|
54
|
+
# check project specific options
|
55
|
+
expect(options[:type]).to eq('foo_template')
|
56
|
+
expect(options[:project_name]).to eq('new_template')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class VersionSpec
|
4
|
+
include New::Version
|
5
|
+
end
|
6
|
+
|
7
|
+
describe New::Version do
|
8
|
+
let(:version){ VersionSpec.new }
|
9
|
+
|
10
|
+
before do
|
11
|
+
version.version = '1.2.3'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should set a version' do
|
15
|
+
expect(version.version.to_s).to eq '1.2.3'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should bump the version' do
|
19
|
+
version.bump_version :major
|
20
|
+
expect(version.version.to_s).to eq '2.2.3'
|
21
|
+
|
22
|
+
version.bump_version :minor
|
23
|
+
expect(version.version.to_s).to eq '2.3.3'
|
24
|
+
|
25
|
+
version.bump_version :patch
|
26
|
+
expect(version.version.to_s).to eq '2.3.4'
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe New do
|
4
|
+
it 'should return a version' do
|
5
|
+
expect(New::VERSION).to match /[0-9]+.[0-9]+.[0-9]+/
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should return an array of available tasks' do
|
9
|
+
expect(New.tasks).to match_array [:foo_task, :custom_bar_task]
|
10
|
+
expect(New.default_tasks).to match_array [:foo_task, :custom_bar_task]
|
11
|
+
expect(New.custom_tasks).to match_array [:custom_bar_task]
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should return an array of available templates' do
|
15
|
+
expect(New.templates).to match_array [:foo_template, :custom_bar_template]
|
16
|
+
expect(New.default_templates).to match_array [:foo_template, :custom_bar_template]
|
17
|
+
expect(New.custom_templates).to match_array [:custom_bar_template]
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
$: << File.expand_path('../../lib', __FILE__)
|
2
|
+
$: << File.expand_path('../fixtures', __FILE__)
|
3
|
+
require 'new'
|
4
|
+
|
5
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
config.filter_run :focus
|
10
|
+
config.order = :random
|
11
|
+
|
12
|
+
config.before do
|
13
|
+
New.stub(:say)
|
14
|
+
stub_const 'New::DEFAULT_DIR', root('spec', 'fixtures')
|
15
|
+
stub_const 'New::CUSTOM_DIR', root('spec', 'fixtures', 'custom')
|
16
|
+
end
|
17
|
+
|
18
|
+
config.before :each do
|
19
|
+
# Force specs to always lookup new templates and tasks
|
20
|
+
New.instance_variables.each{ |v| New.instance_variable_set(v, nil) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def root *paths
|
25
|
+
paths.unshift(File.expand_path('../../', __FILE__)).compact.join '/'
|
26
|
+
end
|
data/tasks/gem/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# GEM TASK
|
2
|
+
|
3
|
+
###### gemspec attributes
|
4
|
+
|
5
|
+
You can add any of the supported gemspec attributes to your project's `.new` configuration file.
|
6
|
+
|
7
|
+
```yaml
|
8
|
+
tasks:
|
9
|
+
gem:
|
10
|
+
summary: My gem summary
|
11
|
+
test_files: <%= Dir.glob('spec/*.rb') %> # use erb rules for inline ruby
|
12
|
+
```
|
13
|
+
|
14
|
+
A full list can be found here http://guides.rubygems.org/specification-reference
|
15
|
+
|
16
|
+
The following attributes expect arrays of unix glob patterns
|
17
|
+
|
18
|
+
* files
|
19
|
+
* test_files
|
20
|
+
* extra_rdoc_files
|
21
|
+
|
22
|
+
```yaml
|
23
|
+
tasks:
|
24
|
+
gem:
|
25
|
+
gemspec:
|
26
|
+
files:
|
27
|
+
- 'lib/**/*.rb'
|
28
|
+
test_files:
|
29
|
+
- 'spec/**/*.rb'
|
30
|
+
```
|
31
|
+
|
32
|
+
The following attributes are automatically set.
|
33
|
+
|
34
|
+
* name
|
35
|
+
* version
|
36
|
+
* date
|
data/tasks/gem/gem.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class New::Task::Gem < New::Task
|
5
|
+
include New::Interpolate
|
6
|
+
include New::Version
|
7
|
+
|
8
|
+
GLOB_ATTRIBUTES = [:files, :test_files, :extra_rdoc_files]
|
9
|
+
OPTIONS = {
|
10
|
+
gemspec: {
|
11
|
+
summary: "A short summary of this gem's description. Displayed in `gem list -d`",
|
12
|
+
files: ['**/*']
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
def run
|
17
|
+
@gemspec = options[:gemspec]
|
18
|
+
|
19
|
+
validate_files
|
20
|
+
render_gemspec_options
|
21
|
+
set_version
|
22
|
+
write_gemspec
|
23
|
+
write_config
|
24
|
+
deploy
|
25
|
+
end
|
26
|
+
|
27
|
+
def render_gemspec_options
|
28
|
+
string = []
|
29
|
+
|
30
|
+
# set defaults
|
31
|
+
@gemspec[:date] = Date.today.to_s
|
32
|
+
@gemspec[:name] = project_options[:project_name]
|
33
|
+
@gemspec[:version] = project_options[:version]
|
34
|
+
@gemspec[:author] ||= project_options[:developer][:name]
|
35
|
+
@gemspec[:email] ||= project_options[:developer][:email]
|
36
|
+
@gemspec[:license] ||= project_options[:license]
|
37
|
+
|
38
|
+
# remove singular attributes if plural attribute is specified
|
39
|
+
if @gemspec[:authors]
|
40
|
+
@gemspec.delete(:author)
|
41
|
+
@gemspec[:authors] = @gemspec[:authors]
|
42
|
+
end
|
43
|
+
if @gemspec[:licenses]
|
44
|
+
@gemspec.delete(:license)
|
45
|
+
@gemspec[:licenses] = @gemspec[:licenses]
|
46
|
+
end
|
47
|
+
|
48
|
+
@gemspec.sort.each do |k,v|
|
49
|
+
val = case v
|
50
|
+
when String then "'#{v}'"
|
51
|
+
else v
|
52
|
+
end
|
53
|
+
|
54
|
+
string << " s.#{k} = #{val}"
|
55
|
+
end
|
56
|
+
|
57
|
+
project_options[:gemspec_string] = string.join("\n")
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate_files
|
61
|
+
GLOB_ATTRIBUTES.each do |file_attr|
|
62
|
+
next if @gemspec[file_attr].nil?
|
63
|
+
|
64
|
+
files = []
|
65
|
+
@gemspec[file_attr].each do |glob|
|
66
|
+
matching_files = FileList.new(glob).select{ |f| File.file? f }
|
67
|
+
|
68
|
+
if matching_files.empty?
|
69
|
+
New.say "The pattern `#{glob}` in `tasks.gem.gemspec.#{file_attr}` did not match any files."
|
70
|
+
New.say 'Please check your configuration file.'
|
71
|
+
exit
|
72
|
+
else
|
73
|
+
files << matching_files
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
@gemspec[file_attr] = files.flatten
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def set_version
|
82
|
+
# set version
|
83
|
+
self.version = project_options[:version]
|
84
|
+
|
85
|
+
# bump version
|
86
|
+
bump_version get_part
|
87
|
+
|
88
|
+
# set new version to config
|
89
|
+
project_options[:version] = version.to_s
|
90
|
+
end
|
91
|
+
|
92
|
+
def write_gemspec
|
93
|
+
# process gemspec
|
94
|
+
interpolate File.join(File.dirname(__FILE__), '.gemspec.erb'), project_options
|
95
|
+
|
96
|
+
# copy it to the project
|
97
|
+
FileUtils.cp File.join(@dest_path, '.gemspec'), Dir.pwd
|
98
|
+
|
99
|
+
# cleanup the tmp
|
100
|
+
FileUtils.rm_rf @dest_path
|
101
|
+
end
|
102
|
+
|
103
|
+
def write_config
|
104
|
+
writeable_options = project_options.dup
|
105
|
+
writeable_options.delete(:gemspec_string)
|
106
|
+
GLOB_ATTRIBUTES.each{ |a| writeable_options.delete(a) }
|
107
|
+
|
108
|
+
File.open(New::CONFIG_FILE, 'w+') do |f|
|
109
|
+
f.write writeable_options.deep_stringify_keys.to_yaml
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def deploy
|
114
|
+
`gem update --system`
|
115
|
+
`gem build .gemspec`
|
116
|
+
`gem push #{@gemspec[:name]}-#{@gemspec[:version]}.gem`
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'bundler', '>= 1.2.0'
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'guard'
|
7
|
+
gem 'guard-coffeescript'
|
8
|
+
gem 'guard-sass'
|
9
|
+
end
|
10
|
+
|
11
|
+
# Platform specific gems (set `require: false`)
|
12
|
+
group :development do
|
13
|
+
gem 'rb-fsevent', :require => false
|
14
|
+
gem 'growl', require: false
|
15
|
+
gem 'terminal-notifier-guard', require: false
|
16
|
+
end
|
17
|
+
|
18
|
+
# OS X
|
19
|
+
if RUBY_PLATFORM.downcase =~ /darwin/
|
20
|
+
require 'rb-fsevent'
|
21
|
+
|
22
|
+
# >= 10.8 Mountain Lion
|
23
|
+
if RUBY_PLATFORM.downcase =~ /darwin12/
|
24
|
+
require 'terminal-notifier-guard'
|
25
|
+
|
26
|
+
# <= 10.7 Lion
|
27
|
+
else
|
28
|
+
require 'growl'
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Source
|
2
|
+
guard :coffeescript, input: 'src', output: 'lib', hide_success: true
|
3
|
+
guard :sass, input: 'src', :noop => true
|
4
|
+
|
5
|
+
# Tests
|
6
|
+
guard :coffeescript, input: 'spec', output: '.tmp', hide_success: true
|
7
|
+
guard :sass, input: 'spec', output: '.tmp', hide_success: true
|