Class: Neutron::Generator
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Neutron::Generator
- Includes:
- Thor::Actions
- Defined in:
- lib/neutron/generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #copy_template ⇒ Object
- #generate! ⇒ Object
- #generate_package_json ⇒ Object
-
#initialize(options) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(options) ⇒ Generator
Returns a new instance of Generator.
14 15 16 17 |
# File 'lib/neutron/generator.rb', line 14 def initialize() super() @options = end |
Class Method Details
.source_root ⇒ Object
19 20 21 |
# File 'lib/neutron/generator.rb', line 19 def self.source_root File.dirname(__FILE__) end |
Instance Method Details
#copy_template ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/neutron/generator.rb', line 28 def copy_template directory(TEMPLATE_PATH, [:path], exclude_pattern: /components/) if [:react] directory(File.join(TEMPLATE_PATH, 'src/assets/javascripts/components'), File.join([:path], 'src/assets/javascripts/components')) end inside(File.join([:path], 'src')) do system 'bundle install' end end |
#generate! ⇒ Object
23 24 25 26 |
# File 'lib/neutron/generator.rb', line 23 def generate! self.copy_template self.generate_package_json end |
#generate_package_json ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/neutron/generator.rb', line 38 def generate_package_json say_status :generate, File.join([:path], 'src', 'package.json') inside(File.join([:path], 'src')) do # Init NPM `npm init -y` # Install local neutron npm package system "npm install --save-dev #{NEUTRON_NPM_PACKAGE_PATH}" # Install NPM packages %w(electron electron-prebuilt-compile).each do |package| system "npm install --save-dev #{package}" end if [:jquery] || [:bootstrap] system "npm install --save jquery" end if [:bootstrap] system "npm install --save bootstrap" end if [:react] system "npm install --save react" system "npm install --save react-dom" end # Edit package.json username = Etc.getlogin.downcase json = JSON.parse(File.read('package.json')) json['name'] = [:name] json['description'] = 'Another Neutron app' json['repository'] = "https://github.com/#{username}/#{[:name]}" json['author'] = username json['license'] = 'MIT' json['main'] = 'main_window.js' json['scripts']['boot'] = './node_modules/.bin/electron .' json['scripts']['buildjs'] = 'NODE_ENV=production ./node_modules/.bin/electron-compile .' #json['babel'] = {'presets' => ['es2015']} File.open('package.json', 'w') {|f| f << json.to_json} end end |