codgen 0.0.5 → 0.0.6

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.
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.1
5
+ - 2.1.2
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # Codgen
2
2
 
3
- A cross language, template based, code generator, capable of generating multiple applications from a common model.
3
+ Codgen is a cross language, template based, code generator, capable of generating multiple applications from a common model.
4
4
 
5
- Right now it uses mustache for it's template files and JSON for it's config and model. We're working on making it so that you can use whatever template engine you want though like mustache or erb.
5
+ It uses JSON for it's model and config and you can use mustache or handlebars templates or just verbatim copy.
6
6
 
7
- If you find bugs or bad error messages be sure to log an issue.
7
+ If you find bugs or bad error messages be sure to log an issue. If it's not to big I'll probably get to pretty quickly. Pull requests are also most welcome!
8
8
 
9
9
 
10
- [![Gem Version](https://badge.fury.io/rb/codgen.svg)](http://badge.fury.io/rb/codgen)
10
+ [![Gem Version](https://badge.fury.io/rb/codgen.svg)](http://badge.fury.io/rb/codgen) [![Build Status](https://travis-ci.org/beattyml1/codgen.svg)](https://travis-ci.org/beattyml1/codgen)
11
11
 
12
12
  ## Installation
13
13
 
data/Rakefile CHANGED
@@ -1,2 +1,24 @@
1
1
  require "bundler/gem_tasks"
2
+ #require_relative 'test/behavior/output_spec'
3
+ #Dir['test/unit/*.rb'].each {|file| require_relative file }
4
+ require 'rspec/core/rake_task'
2
5
 
6
+
7
+ task :unit_tests do
8
+ Dir.chdir('test/data/Input')
9
+ puts ''
10
+ puts 'Running unit tests'
11
+ puts `rspec ../../unit/*_spec.rb`
12
+ puts ''
13
+ puts ''
14
+ Dir.chdir('../../..')
15
+ end
16
+
17
+ task :behavior_tests do
18
+ puts 'Running behavior tests'
19
+ puts `rspec test/behavior/output_spec.rb`
20
+ end
21
+
22
+ task :default => [:unit_tests, :behavior_tests] do
23
+
24
+ end
@@ -8,16 +8,30 @@ require 'fileutils'
8
8
  class CommandLineArguments
9
9
  def initialize(arguments)
10
10
  if arguments.count < 1
11
- puts 'Help file placeholder'
12
- exit 0
11
+ @input_directory = '.'
12
+ @json_config = 'config.json'
13
13
  end
14
14
 
15
- if arguments.count == 1
16
- @json_config = arguments[0]
15
+ if arguments.count >= 1
16
+ if arguments[0] == '--help'
17
+ puts 'Help will be here later'
18
+ exit 0
19
+ elsif File.directory?(arguments[0])
20
+ @input_directory = arguments[0]
21
+ @json_config = 'config.json'
22
+ elsif File.extname(arguments[0]).downcase == '.json'
23
+ @json_config = File.basename(arguments[0])
24
+ @input_directory = File.dirname(arguments[0])
25
+ else
26
+ puts "Could not find directory '#{arguments[0]}', must be either a directory or a .json file"
27
+ exit 1
28
+ end
17
29
  end
30
+
31
+ @output_directory = (arguments.count >= 2) ? arguments[1] : '.'
18
32
  end
19
33
 
20
- attr_reader :json_config
34
+ attr_reader :json_config, :input_directory, :output_directory
21
35
  end
22
36
 
23
37
  def get_file_contents(filepath)
@@ -37,14 +51,25 @@ end
37
51
 
38
52
 
39
53
  def main(args)
40
- if args.json_config != nil
54
+ original_dir = Dir.pwd
55
+ Dir.chdir args.input_directory
56
+
41
57
  json_config_text = get_file_contents(args.json_config)
42
58
  json_config = JSON.parse(json_config_text)
59
+
43
60
  output = Codgen.run(json_config)
61
+
62
+ output_dir = "#{original_dir}/#{args.output_directory}"
63
+
64
+ if !Dir.exists?(output_dir)
65
+ Dir.mkdir(output_dir)
66
+ end
67
+
68
+ Dir.chdir(output_dir)
69
+
44
70
  output.each do |path, text|
45
71
  write_file_contents(path, text)
46
72
  end
47
- end
48
73
  end
49
74
 
50
75
  main(CommandLineArguments.new(ARGV))
@@ -9,11 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Matthew Beatty"]
10
10
  spec.email = ["beattyml1@gmail.com"]
11
11
  spec.summary = 'Generate multiple applications from a common model written in JSON using template'
12
- spec.description = "A cross language, template based, code generator, capable of generating multiple applications from a common model.
13
-
14
- Right now it uses mustache for it's template files and JSON for it's config and model. We're working on making it so that you can use whatever template engine you want though like mustache or erb.
15
-
16
- If you find bugs or bad error messages be sure to log an issue on GitHub."
12
+ spec.description = "Codgen is a cross language, template based, code generator, capable of generating multiple applications from a common model. It uses JSON for it's model and config and you can use mustache or handlebars templates or just verbatim copy. If you find a bug or bad error message be sure to log an issue on GitHub."
17
13
 
18
14
  spec.homepage = "https://github.com/beattyml1/codgen"
19
15
  spec.license = "MIT"
@@ -24,7 +20,7 @@ If you find bugs or bad error messages be sure to log an issue on GitHub."
24
20
  spec.require_paths = ["lib"]
25
21
  spec.required_ruby_version = ">= 2.0.0"
26
22
 
27
- spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "bundler", "~> 1.6"
28
24
  spec.add_development_dependency "rake", "~> 10.0"
29
25
  spec.add_development_dependency "rspec"
30
26
  spec.add_development_dependency "given_when_then"
@@ -25,7 +25,7 @@ module Codgen
25
25
  @unpacked_path = File.basename(@input_path, '.zip')
26
26
  unzip_file(@input_path)
27
27
  else
28
- Logger.error 'Invalid package file format: should be a zip or a directory'
28
+ Logger.error "Invalid package #{@input_path}: should be a zip or a directory"
29
29
  end
30
30
 
31
31
  config_path = "#{@unpacked_path}/config.json"
@@ -1,3 +1,3 @@
1
1
  module Codgen
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -3,13 +3,13 @@ require 'fileutils'
3
3
  require_relative 'test_utils'
4
4
 
5
5
  describe 'Application' do
6
- $expectation_directory = 'expected_output'
7
- $output_directory = 'Output'
6
+ $expectation_directory = 'test/data/expected_output'
7
+ $output_directory = 'test/data/Output'
8
8
  before :all do
9
9
 
10
10
  FileUtils.rm_rf($output_directory)
11
11
 
12
- puts `../../bin/codgen.rb config.json`
12
+ puts `bin/codgen.rb test/data/Input test/data/Output`
13
13
  end
14
14
 
15
15
  it 'should produce all expected files' do
File without changes
@@ -0,0 +1,44 @@
1
+ {
2
+ "map": "Map.json",
3
+ "templates": [
4
+ {
5
+ "in": "model_template.rb.mustache",
6
+ "source": "entities",
7
+ "out": "Ruby/{{application_name}}/Models/{{entity_name}}.rb"
8
+ },
9
+ {
10
+ "in": "ModelTemplate.cs.mustache",
11
+ "source": "entities",
12
+ "out": "MsMvc/{{ApplicationName}}/Models/{{EntityName}}.cs"
13
+ },
14
+ {
15
+ "in": "DbContextTemplate.cs.mustache",
16
+ "source": "entities",
17
+ "out": "MsMvc/{{ApplicationName}}/DAL/{{ApplicationName}}Context.cs"
18
+ },
19
+ {
20
+ "in": "CreateDatabase.sql.mustache",
21
+ "out": "Create{{ApplicationName}}Database.sql"
22
+ },
23
+ {
24
+ "in": "explicit_names.txt",
25
+ "out": "explicit_names.txt",
26
+ "template engine": "mustache"
27
+ },
28
+ {
29
+ "in": "static_text.txt",
30
+ "out": "static_text.txt",
31
+ "template engine": "static"
32
+ },
33
+ {
34
+ "in": "i_can_ride_my_bike_with_no.handlebars",
35
+ "out": "i_can_ride_my_bike_with_no"
36
+ }
37
+ ],
38
+
39
+ "packages": [
40
+ "package_test_dir",
41
+ "package_test_zip.zip"
42
+ ],
43
+ "data": "example-data.json"
44
+ }
@@ -2,7 +2,7 @@
2
2
  "templates": [
3
3
  {
4
4
  "in": "package_hello_world.txt.mustache",
5
- "out": "Output/package_hello_world.txt"
5
+ "out": "package_hello_world.txt"
6
6
  }
7
7
  ]
8
8
  }
@@ -3,7 +3,7 @@ require_relative '../../lib/codgen'
3
3
 
4
4
  describe 'codgen' do
5
5
  config = {
6
- 'templates' => [{'source' => 'data', 'in' => 'Input/hello_world.txt.mustache', 'out' => 'Output/hello_world.txt' }],
6
+ 'templates' => [{'source' => 'data', 'in' => 'hello_world.txt.mustache', 'out' => 'hello_world.txt' }],
7
7
  'data' => { 'data' => [{'name' => 'World'}], 'foo' => 'blah' }
8
8
  }
9
9
  it 'should have one result' do
@@ -4,11 +4,11 @@ require_relative '../../lib/codgen/package'
4
4
 
5
5
  describe 'Package' do
6
6
  Given 'A unpacked package with a string input' do
7
- path = 'Input/package_test_dir'
7
+ path = 'package_test_dir'
8
8
  When 'the package object is initialized' do
9
9
  package = Codgen::Package.new(path)
10
10
  Then 'the path to the templates pointed at package path' do
11
- expect(package.unpacked_path).to eq 'Input/package_test_dir'
11
+ expect(package.unpacked_path).to eq 'package_test_dir'
12
12
  end
13
13
 
14
14
  Then 'templates should be an array' do
@@ -19,12 +19,12 @@ describe 'Package' do
19
19
  expect(package.templates.length).to eq 1
20
20
  end
21
21
 
22
- Then 'the first template should have an "in" value of "Input/package_test_dir/templates/package_hello_world.txt.mustache"' do
23
- expect(package.templates[0]['in']).to eq 'Input/package_test_dir/templates/package_hello_world.txt.mustache'
22
+ Then 'the first template should have an "in" value of "package_test_dir/templates/package_hello_world.txt.mustache"' do
23
+ expect(package.templates[0]['in']).to eq 'package_test_dir/templates/package_hello_world.txt.mustache'
24
24
  end
25
25
 
26
- Then 'the first template should have an "out" value of "Output/package_hello_world.txt"' do
27
- expect(package.templates[0]['out']).to eq 'Output/package_hello_world.txt'
26
+ Then 'the first template should have an "out" value of "package_hello_world.txt"' do
27
+ expect(package.templates[0]['out']).to eq 'package_hello_world.txt'
28
28
  end
29
29
 
30
30
  Then 'config should be a hash' do
@@ -34,7 +34,7 @@ describe 'Package' do
34
34
  end
35
35
 
36
36
  Given 'A compressed package with a string path input' do
37
- path = 'Input/package_test_zip.zip'
37
+ path = 'package_test_zip.zip'
38
38
  When 'the package object is initialized' do
39
39
  package = Codgen::Package.new(path)
40
40
  Then 'the path to the templates pointed at the unpacked directory' do
@@ -53,8 +53,8 @@ describe 'Package' do
53
53
  expect(package.templates[0]['in']).to eq 'package_test_zip/templates/package_zip_hello_world.txt.mustache'
54
54
  end
55
55
 
56
- Then 'the first template should have an "out" value of "Output/package_zip_hello_world.txt"' do
57
- expect(package.templates[0]['out']).to eq 'Output/package_zip_hello_world.txt'
56
+ Then 'the first template should have an "out" value of "package_zip_hello_world.txt"' do
57
+ expect(package.templates[0]['out']).to eq 'package_zip_hello_world.txt'
58
58
  end
59
59
 
60
60
  Then 'config should be a hash' do
@@ -64,11 +64,11 @@ describe 'Package' do
64
64
  end
65
65
 
66
66
  Given 'A unpacked package with a json object with path property' do
67
- package_info = { 'path' => 'Input/package_test_dir' }
67
+ package_info = { 'path' => 'package_test_dir' }
68
68
  When 'the package object is initialized' do
69
69
  package = Codgen::Package.new(package_info)
70
70
  Then 'the path to the templates pointed at package path' do
71
- expect(package.unpacked_path).to eq 'Input/package_test_dir'
71
+ expect(package.unpacked_path).to eq 'package_test_dir'
72
72
  end
73
73
 
74
74
  Then 'templates should be an array' do
@@ -79,12 +79,12 @@ describe 'Package' do
79
79
  expect(package.templates.length).to eq 1
80
80
  end
81
81
 
82
- Then 'the first template should have an "in" value of "Input/package_test_dir/templates/package_hello_world.txt.mustache"' do
83
- expect(package.templates[0]['in']).to eq 'Input/package_test_dir/templates/package_hello_world.txt.mustache'
82
+ Then 'the first template should have an "in" value of "package_test_dir/templates/package_hello_world.txt.mustache"' do
83
+ expect(package.templates[0]['in']).to eq 'package_test_dir/templates/package_hello_world.txt.mustache'
84
84
  end
85
85
 
86
- Then 'the first template should have an "out" value of "Output/package_hello_world.txt"' do
87
- expect(package.templates[0]['out']).to eq 'Output/package_hello_world.txt'
86
+ Then 'the first template should have an "out" value of "package_hello_world.txt"' do
87
+ expect(package.templates[0]['out']).to eq 'package_hello_world.txt'
88
88
  end
89
89
 
90
90
  Then 'config should be a hash' do
@@ -2,7 +2,7 @@ require 'rspec'
2
2
  require_relative '../../lib/codgen/template'
3
3
 
4
4
  describe 'template' do
5
- config = {'source' => 'data', 'in' => 'Input/hello_world.txt.mustache', 'out' => 'Output/hello_world.txt' }
5
+ config = {'source' => 'data', 'in' => 'hello_world.txt.mustache', 'out' => 'hello_world.txt' }
6
6
  data_root = { 'data' => [{'name' => 'World'}], 'foo' => 'blah' }
7
7
  template_text = 'Hello {{name}}'
8
8
  template = Codgen::Template.new(config, data_root)
@@ -20,11 +20,11 @@ describe 'template' do
20
20
  it 'should return a hash' do
21
21
  expect(template.fill_template.is_a?(Hash)).to eq(true)
22
22
  end
23
- it 'should return a output file with location "Output/hello_world.txt"' do
24
- expect(template.fill_template.keys[0]).to eq('Output/hello_world.txt')
23
+ it 'should return a output file with location "hello_world.txt"' do
24
+ expect(template.fill_template.keys[0]).to eq('hello_world.txt')
25
25
  end
26
- it 'should return a output file with location "Output/hello_world.txt"' do
27
- expect(template.fill_template['Output/hello_world.txt']).to eq('Hello World')
26
+ it 'should return a output file with location "hello_world.txt"' do
27
+ expect(template.fill_template['hello_world.txt']).to eq('Hello World')
28
28
  end
29
29
  end
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Beatty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-29 00:00:00.000000000 Z
11
+ date: 2014-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -136,12 +136,10 @@ dependencies:
136
136
  - - '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description: |-
140
- A cross language, template based, code generator, capable of generating multiple applications from a common model.
141
-
142
- Right now it uses mustache for it's template files and JSON for it's config and model. We're working on making it so that you can use whatever template engine you want though like mustache or erb.
143
-
144
- If you find bugs or bad error messages be sure to log an issue on GitHub.
139
+ description: Codgen is a cross language, template based, code generator, capable of
140
+ generating multiple applications from a common model. It uses JSON for it's model
141
+ and config and you can use mustache or handlebars templates or just verbatim copy.
142
+ If you find a bug or bad error message be sure to log an issue on GitHub.
145
143
  email:
146
144
  - beattyml1@gmail.com
147
145
  executables:
@@ -153,7 +151,6 @@ files:
153
151
  - .idea/.name
154
152
  - .idea/.rakeTasks
155
153
  - .idea/codgen.iml
156
- - .idea/dictionaries/matthew.xml
157
154
  - .idea/encodings.xml
158
155
  - .idea/idea/.name
159
156
  - .idea/idea/codgen.iml
@@ -173,6 +170,7 @@ files:
173
170
  - .idea/scopes/scope_settings.xml
174
171
  - .idea/vcs.xml
175
172
  - .idea/workspace.xml
173
+ - .travis.yml
176
174
  - Gemfile
177
175
  - LICENSE.txt
178
176
  - README.md
@@ -197,7 +195,9 @@ files:
197
195
  - test/behavior/test_utils.rb
198
196
  - test/data/Input/CreateDatabase.sql.mustache
199
197
  - test/data/Input/DbContextTemplate.cs.mustache
198
+ - test/data/Input/Map.json
200
199
  - test/data/Input/ModelTemplate.cs.mustache
200
+ - test/data/Input/config.json
201
201
  - test/data/Input/example-data.json
202
202
  - test/data/Input/explicit_names.txt
203
203
  - test/data/Input/hello_world.txt.mustache
@@ -207,9 +207,6 @@ files:
207
207
  - test/data/Input/package_test_dir/templates/package_hello_world.txt.mustache
208
208
  - test/data/Input/package_test_zip.zip
209
209
  - test/data/Input/static_text.txt
210
- - test/data/Map.json
211
- - test/data/__MACOSX/package_test_zip/._.DS_Store
212
- - test/data/config.json
213
210
  - test/data/expected_output/MsMvc/MyBlog/DAL/MyBlogContext.cs
214
211
  - test/data/expected_output/MsMvc/MyBlog/Models/Comment.cs
215
212
  - test/data/expected_output/MsMvc/MyBlog/Models/Post.cs
@@ -220,10 +217,6 @@ files:
220
217
  - test/data/expected_output/package_hello_world.txt
221
218
  - test/data/expected_output/package_zip_hello_world.txt
222
219
  - test/data/expected_output/static_text.txt
223
- - test/data/package_test_zip/config.json
224
- - test/data/package_test_zip/templates/config.json
225
- - test/data/package_test_zip/templates/package_zip_hello_world.txt.mustache
226
- - test/data/test.mustache
227
220
  - test/unit/codgen_engine_spec.rb
228
221
  - test/unit/flattener_spec.rb
229
222
  - test/unit/package_spec.rb
@@ -259,7 +252,9 @@ test_files:
259
252
  - test/behavior/test_utils.rb
260
253
  - test/data/Input/CreateDatabase.sql.mustache
261
254
  - test/data/Input/DbContextTemplate.cs.mustache
255
+ - test/data/Input/Map.json
262
256
  - test/data/Input/ModelTemplate.cs.mustache
257
+ - test/data/Input/config.json
263
258
  - test/data/Input/example-data.json
264
259
  - test/data/Input/explicit_names.txt
265
260
  - test/data/Input/hello_world.txt.mustache
@@ -269,9 +264,6 @@ test_files:
269
264
  - test/data/Input/package_test_dir/templates/package_hello_world.txt.mustache
270
265
  - test/data/Input/package_test_zip.zip
271
266
  - test/data/Input/static_text.txt
272
- - test/data/Map.json
273
- - test/data/__MACOSX/package_test_zip/._.DS_Store
274
- - test/data/config.json
275
267
  - test/data/expected_output/MsMvc/MyBlog/DAL/MyBlogContext.cs
276
268
  - test/data/expected_output/MsMvc/MyBlog/Models/Comment.cs
277
269
  - test/data/expected_output/MsMvc/MyBlog/Models/Post.cs
@@ -282,10 +274,6 @@ test_files:
282
274
  - test/data/expected_output/package_hello_world.txt
283
275
  - test/data/expected_output/package_zip_hello_world.txt
284
276
  - test/data/expected_output/static_text.txt
285
- - test/data/package_test_zip/config.json
286
- - test/data/package_test_zip/templates/config.json
287
- - test/data/package_test_zip/templates/package_zip_hello_world.txt.mustache
288
- - test/data/test.mustache
289
277
  - test/unit/codgen_engine_spec.rb
290
278
  - test/unit/flattener_spec.rb
291
279
  - test/unit/package_spec.rb