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 ⇒ Object
Generate a web app using NPM.
-
#run ⇒ Object
Run the web app in a server.
Methods included from Common
Instance Method Details
#build ⇒ Object
Build a distributable web app using NPM.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gamefic-sdk/tasks/web.rb', line 41 def build check_for_web_build Dir.chdir absolute_path do # exec 'npm run build' pid = Process.spawn 'npm run build' Process.wait pid end rescue Errno::ENOENT => e STDERR.puts "#{e.class}: #{e.message}" STDERR.puts "Web app building requires Node (https://nodejs.org)." end |
#generate ⇒ Object
Generate a web app using NPM.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gamefic-sdk/tasks/web.rb', line 13 def generate Dir.chdir absolute_path do nv = `npm -v`.strip puts "Node version #{nv} detected. Preparing the web app..." Gamefic::Sdk::Scaffold.build 'react', '.' puts 'The web app scaffold is ready.' puts 'Run `npm install` to download the dependencies.' end rescue Errno::ENOENT => e STDERR.puts "#{e.class}: #{e.message}" STDERR.puts "Web app generation requires Node (https://nodejs.org)." end |
#run ⇒ Object
Run the web app in a server.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gamefic-sdk/tasks/web.rb', line 28 def run check_for_web_build build_development listener = Listen.to(File.join(absolute_path, 'web')) do |_mod, _add, _rem| build_development end listener.start # @todo Get the public folder from a config? Gamefic::Sdk::Server.run! source_dir: absolute_path, public_folder: File.join(absolute_path, 'builds', 'web', 'development') end |