new 0.1.1 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/bin/new +0 -2
- data/lib/new.rb +125 -52
- data/lib/new/cli.rb +514 -67
- data/lib/new/source.rb +110 -0
- data/lib/new/task.rb +67 -24
- data/lib/new/validation.rb +191 -0
- metadata +75 -132
- data/.gitignore +0 -6
- data/.new +0 -23
- data/.rspec +0 -2
- data/Gemfile +0 -16
- data/Gemfile.lock +0 -82
- data/Guardfile +0 -16
- data/LICENSE.txt +0 -22
- data/README.md +0 -128
- data/lib/new/core.rb +0 -7
- data/lib/new/dsl.rb +0 -42
- data/lib/new/interpolate.rb +0 -106
- data/lib/new/project.rb +0 -34
- data/lib/new/template.rb +0 -67
- data/lib/new/version.rb +0 -54
- data/spec/fixtures/custom/.new +0 -16
- data/spec/fixtures/custom/tasks/custom_bar_task/custom_bar_task.rb +0 -3
- data/spec/fixtures/custom/templates/custom_bar_template/.new +0 -3
- data/spec/fixtures/custom/templates/custom_bar_template/custom_bar.txt +0 -0
- data/spec/fixtures/project/.new +0 -4
- data/spec/fixtures/project/.new_cli_release_spec +0 -2
- data/spec/fixtures/tasks/custom_bar_task/custom_bar_task.rb +0 -1
- data/spec/fixtures/tasks/foo_task/Gemfile +0 -5
- data/spec/fixtures/tasks/foo_task/foo_task.rb +0 -7
- data/spec/fixtures/templates/custom_bar_template/.gitkeep +0 -0
- data/spec/fixtures/templates/foo_template/.new +0 -1
- data/spec/fixtures/templates/foo_template/[FOO.BAR].txt.erb +0 -1
- data/spec/fixtures/templates/foo_template/nested_[FOO.BAR]/foo.txt.erb +0 -1
- data/spec/lib/new/cli_spec.rb +0 -107
- data/spec/lib/new/interpolate_spec.rb +0 -43
- data/spec/lib/new/project_spec.rb +0 -33
- data/spec/lib/new/task_spec.rb +0 -39
- data/spec/lib/new/template_spec.rb +0 -59
- data/spec/lib/new/version_spec.rb +0 -26
- data/spec/lib/new_spec.rb +0 -19
- data/spec/spec_helper.rb +0 -46
- data/tasks/gem/.gemspec.erb +0 -4
- data/tasks/gem/README.md +0 -36
- data/tasks/gem/gem.rb +0 -170
- data/tasks/gem/gem_spec.rb +0 -138
- data/templates/js/.bowerrc +0 -3
- data/templates/js/.gitignore +0 -3
- data/templates/js/.new.erb +0 -11
- data/templates/js/CHANGELOG.md +0 -3
- data/templates/js/Gemfile +0 -2
- data/templates/js/Guardfile +0 -7
- data/templates/js/LICENSE-MIT.erb +0 -22
- data/templates/js/README.md.erb +0 -41
- data/templates/js/bower.json.erb +0 -11
- data/templates/js/demo/[PROJECT.FILENAME]_demo.coffee +0 -0
- data/templates/js/demo/[PROJECT.FILENAME]_demo.sass +0 -0
- data/templates/js/demo/index.html.erb +0 -12
- data/templates/js/lib/README.md +0 -2
- data/templates/js/package.json +0 -5
- data/templates/js/spec/[PROJECT.FILENAME]_spec.coffee.erb +0 -1
- data/templates/js/spec/[PROJECT.FILENAME]_spec.sass +0 -0
- data/templates/js/spec/index.html.erb +0 -35
- data/templates/js/src/[PROJECT.FILENAME].coffee.erb +0 -18
- data/templates/js/src/[PROJECT.FILENAME].sass +0 -0
- data/templates/js/testem.yml +0 -23
- data/templates/js/yuyi_menu +0 -7
data/lib/new/project.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
class New::Project
|
2
|
-
include New::Version
|
3
|
-
|
4
|
-
# Create all variables and run new project creation methods
|
5
|
-
#
|
6
|
-
def initialize template, name
|
7
|
-
@project_dir = File.join(Dir.pwd, name.to_s) # the newly created project directory
|
8
|
-
@template = New::Template.new template, name
|
9
|
-
|
10
|
-
copy_template
|
11
|
-
create_config_file
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
# Create the new project by copying the template directory
|
17
|
-
#
|
18
|
-
def copy_template
|
19
|
-
FileUtils.cp_r @template.dir, @project_dir
|
20
|
-
|
21
|
-
# cleanup tmp
|
22
|
-
FileUtils.rm_rf @template.dir
|
23
|
-
end
|
24
|
-
|
25
|
-
# Create the .new configuration file in the new project
|
26
|
-
#
|
27
|
-
def create_config_file
|
28
|
-
new_config = File.join(@project_dir, New::CONFIG_FILE)
|
29
|
-
File.open new_config, 'w' do |f|
|
30
|
-
yaml_options = @template.options.deep_dup.deep_stringify_keys!.to_yaml
|
31
|
-
f.write(yaml_options)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/lib/new/template.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
class New::Template
|
4
|
-
include New::Interpolate
|
5
|
-
|
6
|
-
# The foundation for new template configuration files
|
7
|
-
#
|
8
|
-
CUSTOM_CONFIG_TEMPLATE = {
|
9
|
-
license: '[LICENSE]',
|
10
|
-
version: '0.0.0',
|
11
|
-
developer: {
|
12
|
-
name: '[NAME]',
|
13
|
-
email: '[EMAIL]'
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
def initialize type, name
|
18
|
-
@type = type
|
19
|
-
@name = name
|
20
|
-
|
21
|
-
interpolate template_dir, options
|
22
|
-
end
|
23
|
-
|
24
|
-
# Create the options object
|
25
|
-
#
|
26
|
-
def options
|
27
|
-
# merge options together
|
28
|
-
CUSTOM_CONFIG_TEMPLATE.clone
|
29
|
-
.deep_merge!(template_config)
|
30
|
-
.deep_merge!(New.custom_config)
|
31
|
-
.deep_merge!({
|
32
|
-
project: {
|
33
|
-
name: @name,
|
34
|
-
filename: to_filename(@name)
|
35
|
-
},
|
36
|
-
type: @type.to_s
|
37
|
-
})
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
# Get the template directory to copy from
|
43
|
-
#
|
44
|
-
def template_dir
|
45
|
-
@template_dir ||= if New.custom_templates.include? @type
|
46
|
-
@custom = true
|
47
|
-
File.join(New::CUSTOM_DIR, New::TEMPLATES_DIR_NAME, @type.to_s)
|
48
|
-
else
|
49
|
-
File.join(New::DEFAULT_DIR, New::TEMPLATES_DIR_NAME, @type.to_s)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# Get the configuration for the template
|
54
|
-
#
|
55
|
-
def template_config
|
56
|
-
return @template_config if @template_config
|
57
|
-
|
58
|
-
@template_config = YAML.load(File.open(File.join(template_dir, New::CONFIG_FILE))).deep_symbolize_keys! rescue {}
|
59
|
-
if @custom
|
60
|
-
@template_config.merge!({
|
61
|
-
custom: true
|
62
|
-
})
|
63
|
-
end
|
64
|
-
|
65
|
-
@template_config
|
66
|
-
end
|
67
|
-
end
|
data/lib/new/version.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
module New::Version
|
2
|
-
require 'semantic'
|
3
|
-
|
4
|
-
def part; @part; end
|
5
|
-
def previous_version; @previous_version; end
|
6
|
-
def version; @version; end
|
7
|
-
|
8
|
-
def bump_version previous_version, part = nil
|
9
|
-
@previous_version = get_version previous_version
|
10
|
-
@part = part ||= get_part
|
11
|
-
|
12
|
-
# bump version
|
13
|
-
case part
|
14
|
-
when :major
|
15
|
-
@previous_version.major += 1
|
16
|
-
@previous_version.minor = 0
|
17
|
-
@previous_version.patch = 0
|
18
|
-
when :minor
|
19
|
-
@previous_version.minor += 1
|
20
|
-
@previous_version.patch = 0
|
21
|
-
when :patch
|
22
|
-
@previous_version.patch += 1
|
23
|
-
end
|
24
|
-
|
25
|
-
# set new version
|
26
|
-
@version = @previous_version
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def get_part
|
32
|
-
New.say " Current Version: #{previous_version}", type: :success
|
33
|
-
New.say " Specify which part to bump: [#{'Mmp'.green}] (#{'M'.green}ajor / #{'m'.green}inor / #{'p'.green}atch)"
|
34
|
-
part = STDIN.gets.chomp!
|
35
|
-
|
36
|
-
case part
|
37
|
-
when 'M'
|
38
|
-
:major
|
39
|
-
when 'm'
|
40
|
-
:minor
|
41
|
-
when 'p'
|
42
|
-
:patch
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def get_version version
|
47
|
-
begin
|
48
|
-
Semantic::Version.new version.to_s
|
49
|
-
rescue
|
50
|
-
New.say "#{version} is not a semantic version. Use format `1.2.3`", type: :fail
|
51
|
-
exit
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/spec/fixtures/custom/.new
DELETED
File without changes
|
data/spec/fixtures/project/.new
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
raise 'This class should not have been loaded since there is a custom task that should be taking precedence'
|
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
template: true
|
@@ -1 +0,0 @@
|
|
1
|
-
foo <%= foo.bar %>
|
@@ -1 +0,0 @@
|
|
1
|
-
foo <%= foo.bar %>
|
data/spec/lib/new/cli_spec.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe New::Cli do
|
4
|
-
describe '#projects' do
|
5
|
-
before do
|
6
|
-
allow(New).to receive(:templates).and_return([:foo])
|
7
|
-
allow(subject).to receive(:project)
|
8
|
-
end
|
9
|
-
|
10
|
-
after do
|
11
|
-
allow(New).to receive(:templates).and_call_original
|
12
|
-
allow(subject).to receive(:project).and_call_original
|
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 eq true
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should create .new file' do
|
43
|
-
expect(File.exists?(root('.tmp', '.new', New::CONFIG_FILE))).to eq true
|
44
|
-
|
45
|
-
# Check that the keys are properly formatted in the yaml file
|
46
|
-
expect(File.read(root('.tmp', '.new', New::CONFIG_FILE))).to match /^version: 0.0.0$/
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should create an empty templates & tasks dir' do
|
50
|
-
expect(Dir.exists?(root('.tmp', '.new', 'templates'))).to eq true
|
51
|
-
expect(Dir.exists?(root('.tmp', '.new', 'tasks'))).to eq true
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe '#release' do
|
56
|
-
context 'for an invalid project' do
|
57
|
-
before do
|
58
|
-
Dir.chdir root('.tmp')
|
59
|
-
File.delete '.new' rescue nil
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'should raise an error if no config file is found' do
|
63
|
-
expect { subject.release }.to raise_error
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'for a valid project' do
|
68
|
-
before do
|
69
|
-
Dir.chdir root('spec', 'fixtures', 'project')
|
70
|
-
end
|
71
|
-
|
72
|
-
# test that the task is required
|
73
|
-
describe 'require' do
|
74
|
-
before do
|
75
|
-
allow(New::Task).to receive :inherited
|
76
|
-
subject.release
|
77
|
-
end
|
78
|
-
|
79
|
-
after do
|
80
|
-
allow(New::Task).to receive(:inherited).and_call_original
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should require the task' do
|
84
|
-
expect(New::Task).to have_received(:inherited).with(New::Task::FooTask).once
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# test that the task is initialized
|
89
|
-
describe 'initialize' do
|
90
|
-
before do
|
91
|
-
require root('spec', 'fixtures', 'custom', 'tasks', 'custom_bar_task', 'custom_bar_task')
|
92
|
-
allow(New::Task::CustomBarTask).to receive :new
|
93
|
-
stub_const 'New::CONFIG_FILE', '.new_cli_release_spec'
|
94
|
-
subject.release
|
95
|
-
end
|
96
|
-
|
97
|
-
after do
|
98
|
-
allow(New::Task::CustomBarTask).to receive(:new).and_call_original
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'should initialize the task' do
|
102
|
-
expect(New::Task::CustomBarTask).to have_received(:new).with({ tasks: { custom_bar_task: nil }})
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,43 +0,0 @@
|
|
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 their content has been processed
|
26
|
-
expect(File.open(File.join(@obj.dir, 'baz.txt')).read).to include 'foo baz'
|
27
|
-
expect(File.open(File.join(@obj.dir, 'nested_baz', 'foo.txt')).read).to include 'foo baz'
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should create dot notation accessible options' do
|
31
|
-
expect(@obj.dot_options.foo.bar).to eq('baz')
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should respond to options as methods' do
|
35
|
-
expect(@obj.foo.bar).to eq 'baz'
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#friendly_filename' do
|
39
|
-
it 'should convert a string to a unix compatible filename' do
|
40
|
-
expect(@obj.to_filename('Foo Bar')).to eq 'foo_bar'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'recursive-open-struct'
|
3
|
-
|
4
|
-
describe New::Project do
|
5
|
-
let(:template_dir){ File.join(@tmp_dir, 'custom_bar_template') }
|
6
|
-
let(:project_dir){ File.join(@tmp_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
|
-
@tmp_dir = Dir.mktmpdir
|
12
|
-
FileUtils.cp_r root('spec', 'fixtures', 'custom', 'templates', 'custom_bar_template'), @tmp_dir
|
13
|
-
allow(New::Template).to receive(:new).and_return(RecursiveOpenStruct.new({ options: {}, dir: template_dir }))
|
14
|
-
|
15
|
-
# change directory before creating a project since it uses pwd
|
16
|
-
Dir.chdir @tmp_dir
|
17
|
-
project
|
18
|
-
end
|
19
|
-
|
20
|
-
after do
|
21
|
-
allow(New::Template).to receive(:new).and_call_original
|
22
|
-
FileUtils.rm_rf template_dir
|
23
|
-
FileUtils.rm_rf project_dir
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should copy the template' do
|
27
|
-
expect(Dir.exists?(project_dir)).to eq true
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should create a config file' do
|
31
|
-
expect(File.exists?(File.join(project_dir, New::CONFIG_FILE))).to eq true
|
32
|
-
end
|
33
|
-
end
|
data/spec/lib/new/task_spec.rb
DELETED
@@ -1,39 +0,0 @@
|
|
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
|
-
allow(task).to receive(:name).and_return(:foo_task)
|
23
|
-
end
|
24
|
-
|
25
|
-
after do
|
26
|
-
allow(task).to receive(:name).and_call_original
|
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 eq true
|
32
|
-
expect(task.project_options[:tasks].has_key?(:dont_include)).to eq 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
|