new 0.0.0 → 0.0.1

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. metadata +7 -66
  3. data/.gitignore +0 -7
  4. data/.rspec +0 -2
  5. data/Gemfile +0 -16
  6. data/Gemfile.lock +0 -79
  7. data/Guardfile +0 -14
  8. data/LICENSE.txt +0 -22
  9. data/README.md +0 -121
  10. data/bin/new +0 -6
  11. data/lib/new/cli.rb +0 -94
  12. data/lib/new/core.rb +0 -6
  13. data/lib/new/dsl.rb +0 -42
  14. data/lib/new/interpolate.rb +0 -100
  15. data/lib/new/project.rb +0 -34
  16. data/lib/new/task.rb +0 -41
  17. data/lib/new/template.rb +0 -64
  18. data/lib/new/version.rb +0 -41
  19. data/lib/new.rb +0 -72
  20. data/spec/fixtures/custom/tasks/custom_bar_task/custom_bar_task.rb +0 -3
  21. data/spec/fixtures/custom/templates/custom_bar_template/custom_bar.txt +0 -0
  22. data/spec/fixtures/tasks/custom_bar_task/custom_bar_task.rb +0 -1
  23. data/spec/fixtures/tasks/foo_task/foo_task.rb +0 -7
  24. data/spec/fixtures/templates/foo_template/[FOO.BAR].txt.erb +0 -1
  25. data/spec/fixtures/templates/foo_template/nested_[FOO.BAR]/foo.txt.erb +0 -1
  26. data/spec/lib/new/cli_spec.rb +0 -104
  27. data/spec/lib/new/interpolate_spec.rb +0 -41
  28. data/spec/lib/new/project_spec.rb +0 -30
  29. data/spec/lib/new/task_spec.rb +0 -39
  30. data/spec/lib/new/template_spec.rb +0 -59
  31. data/spec/lib/new/version_spec.rb +0 -28
  32. data/spec/lib/new_spec.rb +0 -19
  33. data/spec/spec_helper.rb +0 -26
  34. data/tasks/gem/README.md +0 -36
  35. data/tasks/gem/gem.rb +0 -118
  36. data/templates/js/Gemfile +0 -30
  37. data/templates/js/Guardfile +0 -7
  38. data/templates/js/LICENSE-MIT.erb +0 -22
  39. data/templates/js/README.md.erb +0 -61
  40. data/templates/js/demo/index.html.erb +0 -7
  41. data/templates/js/lib/README.md +0 -2
  42. data/templates/js/spec/[PROJECT_NAME].spec.js.coffee.erb +0 -1
  43. data/templates/js/spec/index.html.erb +0 -29
  44. data/templates/js/spec/spec_helper.js.coffee +0 -0
  45. data/templates/js/spec/vendor/chai.js +0 -3765
  46. data/templates/js/spec/vendor/sinon-chai.js +0 -106
  47. data/templates/js/spec/vendor/sinon.js +0 -4246
  48. data/templates/js/src/README.md +0 -3
  49. data/templates/js/src/[PROJECT_NAME].js.coffee.erb +0 -10
  50. data/templates/js/testem.yml +0 -12
data/lib/new/task.rb DELETED
@@ -1,41 +0,0 @@
1
- require 'yaml'
2
-
3
- class New::Task
4
- def self.inherited task_class
5
- task_class.name = caller.first[/[a-z_]+?(?=\.rb)/].to_sym
6
- end
7
-
8
- def initialize project_config
9
- @project_config = project_config
10
- run
11
- end
12
-
13
- def self.name= name
14
- @name = name
15
- end
16
- def self.name; @name; end
17
- def name; self.class.name.to_sym; end
18
-
19
- # Return ALL available options
20
- #
21
- def project_options
22
- custom_options = New.custom_config
23
- project_options = @project_config
24
-
25
- all_options = custom_options.deep_merge(project_options)
26
-
27
- # Groom tasks (prevent tasks from the custom config from polluting the project config)
28
- all_options[:tasks].each_key do |task|
29
- all_options[:tasks].delete(task) unless project_options[:tasks].has_key?(task)
30
- end
31
-
32
- @project_options ||= all_options
33
- end
34
-
35
- # Return only the options for the given task
36
- #
37
- def options
38
- default_options = self.class::OPTIONS rescue {}
39
- @options ||= default_options.deep_merge(project_options[:tasks][name])
40
- end
41
- end
data/lib/new/template.rb DELETED
@@ -1,64 +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: '[VERSION]',
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_name: @name,
33
- type: @type.to_s
34
- })
35
- end
36
-
37
- private
38
-
39
- # Get the template directory to copy from
40
- #
41
- def template_dir
42
- @template_dir ||= if New.custom_templates.include? @type
43
- @custom = true
44
- File.join(New::CUSTOM_DIR, New::TEMPLATES_DIR_NAME, @type.to_s)
45
- else
46
- File.join(New::DEFAULT_DIR, New::TEMPLATES_DIR_NAME, @type.to_s)
47
- end
48
- end
49
-
50
- # Get the configuration for the template
51
- #
52
- def template_config
53
- return @template_config if @template_config
54
-
55
- @template_config = YAML.load(File.open(File.join(template_dir, New::CONFIG_FILE))).deep_symbolize_keys! rescue {}
56
- if @custom
57
- @template_config.merge!({
58
- custom: true
59
- })
60
- end
61
-
62
- @template_config
63
- end
64
- end
data/lib/new/version.rb DELETED
@@ -1,41 +0,0 @@
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 DELETED
@@ -1,72 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- class New::Task::CustomBarTask < New::Task
2
- def run; end
3
- end
@@ -1 +0,0 @@
1
- raise 'This class should not have been loaded since there is a custom task that should be taking precedence'
@@ -1,7 +0,0 @@
1
- class New::Task::FooTask < New::Task
2
- OPTIONS = {
3
- foo: 'default',
4
- default: true
5
- }
6
- def run; end
7
- end
@@ -1 +0,0 @@
1
- foo <%= foo.bar %>
@@ -1 +0,0 @@
1
- foo <%= foo.bar %>
@@ -1,104 +0,0 @@
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
@@ -1,41 +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 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
@@ -1,30 +0,0 @@
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
@@ -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
- 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
@@ -1,59 +0,0 @@
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
@@ -1,28 +0,0 @@
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
data/spec/lib/new_spec.rb DELETED
@@ -1,19 +0,0 @@
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 DELETED
@@ -1,26 +0,0 @@
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 DELETED
@@ -1,36 +0,0 @@
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