mgen 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5a051bdb14b02c92045fd8905b8722efa29af9d9
4
+ data.tar.gz: 0dd47009f9e228c5b5e280458e23bdb762566a8d
5
+ SHA512:
6
+ metadata.gz: 635dcdfc5a3c4e8a6f1164f30820ebd068653e79187bed05465c7805ee5fb15d597d364f110b3b83513dc0605d1ca5f0421b22b6952074113106208c1387951c
7
+ data.tar.gz: 2c353e4eff9f7a0546ca818375778ad8919941cb49ee100972e13e12ea90d7b4e76f23d54372c7bdd8e4b5568ff84fa4141d42014656647caa87300411b67342
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mgen.gemspec
4
+ gem "pry"
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 miguel michelson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Mgen
2
+
3
+ mruby gem (mgem) generator
4
+
5
+ mgen is a ruby cli to generate mruby gem projects
6
+
7
+ `$ gem install mgen`
8
+
9
+ ## Usage
10
+
11
+ ```
12
+ Tasks:
13
+ mgen help [TASK] # Describe available tasks or one specific task
14
+ mgen info # information about Mgen.
15
+ mgen new <name> # generates a new mgem project.
16
+ ```
17
+
18
+ the mgem project layout will generate the maximal GEM structure based on mruby standard:
19
+
20
+ ```
21
+ +- GEM_NAME <- Name of GEM
22
+ |
23
+ +- include/ <- Header for Ruby extension (will exported)
24
+ |
25
+ +- mrblib/ <- Source for Ruby extension
26
+ |
27
+ +- src/ <- Source for C extension
28
+ |
29
+ +- test/ <- Test code (Ruby)
30
+ |
31
+ +- mrbgem.rake <- GEM Specification
32
+ |
33
+ +- README.md <- Readme for GEM
34
+ ```
35
+
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/mgen ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mgen'
4
+
5
+ Mgen::CLI.start
data/lib/mgen/cli.rb ADDED
@@ -0,0 +1,84 @@
1
+ require "thor"
2
+ require "thor/group"
3
+ require "pry"
4
+ require "erubis"
5
+
6
+ module Mgen
7
+ class CLI < Thor
8
+ #binding.pry
9
+ include Utils
10
+ include Thor::Actions
11
+
12
+ no_tasks {
13
+ def cli_error(message, exit_status=nil)
14
+ $stderr.puts message
15
+ exit_status = STATUS_TYPES[exit_status] if exit_status.is_a?(Symbol)
16
+ exit(exit_status || 1)
17
+ end
18
+
19
+ def create(name)
20
+ @project_name = name
21
+ begin
22
+ generate_files
23
+ say "Your mruby gem is ready for you to get coding!", :green
24
+ rescue => e
25
+ say "There was an error generating mgem. #{e}", :red
26
+ say e.backtrace.join("\r\n")
27
+ end
28
+ end
29
+
30
+ def generate_files
31
+ @project_dir = underscore(@project_name)
32
+
33
+ full_app_hash = {
34
+ :app_name => @project_name,
35
+ :app_name_underscore => @project_dir,
36
+ :platform => @device_platform
37
+ }
38
+
39
+ create_project_directory
40
+ create_with_template("#{@project_dir}/LICENSE", 'defaults/LICENSE', full_app_hash)
41
+ create_with_template("#{@project_dir}/mrbgem.rake", 'defaults/mrbgem.rake', full_app_hash)
42
+ create_with_template("#{@project_dir}/build_config.rb", 'defaults/build_config.rb', full_app_hash)
43
+ create_with_template("#{@project_dir}/Rakefile", 'defaults/Rakefile', full_app_hash)
44
+ end
45
+
46
+ def create_project_directory
47
+ create_directories( @project_dir )
48
+ dirs = %w(docs mrblib test include src test).map{|o| "#{@project_dir}/#{o}"}
49
+ create_directories(*dirs)
50
+ end
51
+
52
+ }
53
+
54
+ map %w(--version -v) => 'info'
55
+ desc "info", "information about Mgen."
56
+ def info
57
+ say "Version #{Mgen::VERSION}"
58
+ end
59
+
60
+ map %(n) => 'new'
61
+ desc "new <name> ", "generates a new mgem project."
62
+ long_desc "Generates a new mgem project. See 'mgen help new' for more information.
63
+ \n\nExample:
64
+ \n\nmgen new demo ==> Creates a new mruby gem skeleton."
65
+ def new(name)
66
+ if File.exist?(base_location.join(name))
67
+ if yes? "#{name} already exists, do you want to override? (yes or no)", :yellow
68
+ create(name)
69
+ else
70
+ say "Skipping #{name} because it already exists", :green
71
+ end
72
+ else
73
+ create(name)
74
+ end
75
+
76
+ end
77
+
78
+ map %w(--build -b) => 'build'
79
+ desc "build", "buid app with productbuild "
80
+ def build
81
+ say "Version #{Mgen::VERSION}"
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,11 @@
1
+ module Mgen
2
+ class Logger
3
+ def self.report(msg)
4
+ $stdout.puts(msg.green.bold)
5
+ end
6
+
7
+ def self.error(msg)
8
+ $stderr.puts(msg.red.bold)
9
+ end
10
+ end
11
+ end
File without changes
File without changes
@@ -0,0 +1,37 @@
1
+ STATIC_ROOT=ENV["STATIC_ROOT"] || Dir.pwd
2
+ MRUBY_ROOT=ENV["MRUBY_ROOT"] || "#{STATIC_ROOT}/mruby"
3
+ MRUBY_CONFIG=File.expand_path(ENV["MRUBY_CONFIG"] || "build_config.rb")
4
+ INSTALL_PREFIX=ENV["INSTALL_PREFIX"] || "#{STATIC_ROOT}/build"
5
+ MRUBY_VERSION=ENV["MRUBY_VERSION"] || "1.1.0"
6
+
7
+ file :mruby do
8
+ sh "wget --no-check-certificate -O mruby.tar.gz https://github.com/mruby/mruby/archive/#{MRUBY_VERSION}.tar.gz"
9
+ sh "tar -xvzf mruby.tar.gz"
10
+ sh "rm mruby.tar.gz"
11
+ sh "mv mruby-#{MRUBY_VERSION} #{MRUBY_ROOT}"
12
+ end
13
+
14
+ desc "compile binary"
15
+ task :compile => :mruby do
16
+ sh "cd #{MRUBY_ROOT} && MRUBY_CONFIG=#{MRUBY_CONFIG} rake all"
17
+ sh "cp -p #{MRUBY_ROOT}/bin/mruby #{STATIC_ROOT}/bin/static"
18
+ end
19
+
20
+ desc "test"
21
+ task :test => :mruby do
22
+ sh "cd #{MRUBY_ROOT} && MRUBY_CONFIG=#{MRUBY_CONFIG} rake all test"
23
+ end
24
+
25
+ desc "install"
26
+ task :install => :compile do
27
+ sh "mkdir -p #{INSTALL_PREFIX}/bin"
28
+ sh "cp -p #{STATIC_ROOT}/bin/static #{INSTALL_PREFIX}/bin/."
29
+ end
30
+
31
+ desc "cleanup"
32
+ task :clean do
33
+ sh "rm #{STATIC_ROOT}/bin/static"
34
+ sh "cd #{MRUBY_ROOT} && rake deep_clean"
35
+ end
36
+
37
+ task :default => :test
@@ -0,0 +1,17 @@
1
+ MRuby::Build.new do |conf|
2
+ # Gets set by the VS command prompts.
3
+ if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
4
+ toolchain :visualcpp
5
+ else
6
+ toolchain :gcc
7
+ end
8
+
9
+ enable_debug
10
+
11
+ conf.gembox 'default'
12
+
13
+ #conf.gem :github => 'iij/mruby-io'
14
+
15
+ # be sure to include this gem
16
+ conf.gem File.expand_path(File.dirname(__FILE__))
17
+ end
@@ -0,0 +1,11 @@
1
+ MRuby::Gem::Specification.new('mruby-<%= app_name %>') do |spec|
2
+ spec.license = 'MIT'
3
+ spec.authors = 'your name <your@email>'
4
+ spec.summary = 'drescription here'
5
+
6
+ #spec.add_dependency 'mruby-io'
7
+
8
+ #spec.cc.include_paths << "#{spec.dir}/include" << "#{spec.dir}/<%= app_name %>"
9
+
10
+ #spec.objs << (Dir.glob("#{dir}/src/*.c") + Dir.glob("#{dir}/<%= app_name %>/*.c")).map { |f| f.relative_path_from(dir).pathmap("#{build_dir}/%X.o") }
11
+ end
data/lib/mgen/utils.rb ADDED
@@ -0,0 +1,78 @@
1
+ module Mgen
2
+ module Utils
3
+ include Thor::Actions
4
+
5
+ def self.source_root
6
+ File.dirname(__FILE__)
7
+ end
8
+
9
+ def create_new_file(name, file=nil)
10
+ log "Creating #{name}"
11
+ contents = file.nil? ? '' : File.read(file)
12
+ unless File.file?(location.join(name))
13
+ File.open(location.join(name), 'w') { |f| f.write(contents) }
14
+ end
15
+ end
16
+
17
+ def remove_files(*files)
18
+ files.each do |file|
19
+ log "Removing #{file} file."
20
+ FileUtils.rm(location.join(file))
21
+ end
22
+ end
23
+
24
+ def touch(*filenames)
25
+ filenames.each do |filename|
26
+ log "Creating #{filename} file."
27
+ FileUtils.touch(location.join(filename))
28
+ end
29
+ end
30
+
31
+ def create_directories(*dirs)
32
+ dirs.each do |dir|
33
+ log "Creating the #{dir} directory."
34
+ FileUtils.mkdir_p(location.join(dir))
35
+ end
36
+ end
37
+
38
+ def remove_directories(*names)
39
+ names.each do |name|
40
+ log "Removing #{name} directory."
41
+ FileUtils.rm_rf(location.join(name))
42
+ end
43
+ end
44
+
45
+ def create_with_template(name, template_location, contents={})
46
+ template = templates("#{template_location}.erb")
47
+ eruby = Erubis::Eruby.new(File.read(template))
48
+ File.open(location.join(name.gsub(/^\//, '')), 'w') { |f| f.write(eruby.result(contents))}
49
+ end
50
+
51
+ def templates(path)
52
+ ::Mgen.root.join('mgen/templates').join(path)
53
+ end
54
+
55
+ def log(msg)
56
+ say msg, :green
57
+ end
58
+
59
+ def error(msg)
60
+ say msg, :red
61
+ end
62
+
63
+ def base_location
64
+ @location ||= Pathname.new(Dir.pwd)
65
+ end
66
+
67
+ alias_method :location, :base_location
68
+
69
+ def underscore(string)
70
+ string.gsub(/::/, '/').
71
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
72
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
73
+ tr("-", "_").
74
+ downcase
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module Mgen
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mgen.rb ADDED
@@ -0,0 +1,12 @@
1
+
2
+ module Mgen
3
+ autoload :CLI, 'mgen/cli.rb'
4
+ autoload :Utils, 'mgen/utils.rb'
5
+
6
+ autoload :Logger, 'mgen/logger.rb'
7
+ autoload :Version, 'mgen/version.rb'
8
+
9
+ def self.root
10
+ @root ||= Pathname(__FILE__).dirname.expand_path
11
+ end
12
+ end
data/mgen.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mgen/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mgen"
8
+ spec.version = Mgen::VERSION
9
+ spec.authors = ["miguel michelson"]
10
+ spec.email = ["miguelmichelson@gmail.com"]
11
+ spec.description = "simple mgem generator"
12
+ spec.summary = "simple mgem generator"
13
+ spec.homepage = "http://github.com/michelson/mgen"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+
23
+ spec.add_runtime_dependency(%q<colored>, ["~> 1.2"])
24
+ spec.add_runtime_dependency(%q<rake>, ["~> 0.9.2"])
25
+ spec.add_runtime_dependency(%q<erubis>, ["~> 2.7.0"])
26
+ spec.add_runtime_dependency(%q<thor>, ["~> 0.15.4"])
27
+ spec.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mgen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - miguel michelson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colored
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: erubis
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.7.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.7.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.15.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.15.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.6.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.6.0
97
+ description: simple mgem generator
98
+ email:
99
+ - miguelmichelson@gmail.com
100
+ executables:
101
+ - mgen
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/mgen
111
+ - lib/mgen.rb
112
+ - lib/mgen/cli.rb
113
+ - lib/mgen/logger.rb
114
+ - lib/mgen/templates/defaults/LICENSE.erb
115
+ - lib/mgen/templates/defaults/README.md.erb
116
+ - lib/mgen/templates/defaults/Rakefile.erb
117
+ - lib/mgen/templates/defaults/build_config.rb.erb
118
+ - lib/mgen/templates/defaults/mrbgem.rake.erb
119
+ - lib/mgen/utils.rb
120
+ - lib/mgen/version.rb
121
+ - mgen.gemspec
122
+ homepage: http://github.com/michelson/mgen
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.2.2
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: simple mgem generator
146
+ test_files: []