Class: Gamefic::Sdk::Tasks::Web

Inherits:
Object
  • Object
show all
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

#directory

Instance Method Summary collapse

Methods included from Common

#absolute_path, #initialize, #plot_class, #string_to_constant

Instance Method Details

#buildObject

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.message}"
  warn 'Web app building requires Node (https://nodejs.org).'
end

#generate(version = '@latest') ⇒ 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 = '@latest'
  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

#runObject

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