Class: Gamefic::Sdk::Tasks::Web
- Inherits:
-
Object
- Object
- Gamefic::Sdk::Tasks::Web
- Includes:
- Common
- Defined in:
- lib/gamefic-sdk/tasks/web.rb
Overview
Tasks for running and building web apps.
Instance Attribute Summary
Attributes included from Common
Instance Method Summary collapse
-
#build ⇒ Object
Build a distributable web app using NPM.
-
#generate(version = '@1.6.1') ⇒ Object
Generate a web app using NPM.
-
#run ⇒ Object
Run the web app in a server.
Methods included from Common
#absolute_path, #initialize, #plot_class, #string_to_constant
Instance Method Details
#build ⇒ Object
Build a distributable web app using NPM.
38 39 40 41 42 43 44 45 46 |
# File 'lib/gamefic-sdk/tasks/web.rb', line 38 def build check_for_web_build Dir.chdir File.join(absolute_path, 'web') do system 'npm run build' end rescue Errno::ENOENT => e warn "#{e.class}: #{e.}" warn 'Web app building requires Node (https://nodejs.org).' end |
#generate(version = '@1.6.1') ⇒ Object
Generate a web app using NPM.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gamefic-sdk/tasks/web.rb', line 15 def generate version = '@1.6.1' puts "Node version #{check_for_npm} detected. Preparing the web app..." web_path = File.join(absolute_path, 'web') FileUtils.mkdir_p web_path Dir.chdir web_path do name = File.basename(absolute_path) system 'npx', '-y', "react-gamefic#{version}", '--name', name, '--class', 'GAMEFIC_PLOT_CLASS', '--path', '../lib' puts 'The web app is ready.' puts 'Run `rake web:run` to start the app in dev mode.' end end |
#run ⇒ Object
Run the web app in a server.
29 30 31 32 33 34 |
# File 'lib/gamefic-sdk/tasks/web.rb', line 29 def run check_for_web_build Dir.chdir File.join(absolute_path, 'web') do system 'npm start' end end |