Class: J1::Commands::Setup

Inherits:
J1::Command show all
Defined in:
lib/j1/commands/setup.rb

Class Method Summary collapse

Methods inherited from J1::Command

inherited, subclasses

Class Method Details

.init_with_program(prog) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/j1/commands/setup.rb', line 10

def init_with_program(prog)
  prog.command(:setup) do |c|
    c.description 'Initialize a J1 Project for first use'
    c.syntax 'setup'
    c.option 'force', '--force',                ' Force to install patches even already exists'
    c.option 'system', '--system',              ' Install patches on the Ruby SYSTEM gem folder'
    c.option 'skip-patches', '--skip-patches',  'Skip install any PATCHES build-in with J1'
    c.action do |args, options|
      J1::Commands::Setup.process(args, options)
    end
  end
end

.process(args, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/j1/commands/setup.rb', line 23

def process(args, options = {})
  @args = args
  path = File.expand_path(Dir.getwd)

  if J1::Utils::is_project?
    bundle_install(path, options)
    if options['skip-patches']
      J1.logger.info "#{timestamp} - SETUP: installing build-in patches skipped."
    else
      patch_install(options)
    end

    timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
    J1.logger.info "#{timestamp} - SETUP: initializing the project .."
    J1.logger.info "#{timestamp} - SETUP: be patient, this will take a while .."
    # process, output = J1::Utils::Exec.run('npm', 'run', 'setup')
    # output.to_s.each_line do |line|
    #   J1.logger.info('SETUP:', line.strip) unless line.to_s.empty?
    # end
    process = J1::Utils::Exec2.run('SETUP','npm', 'run', 'setup')
    if process.success?
      timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
      J1.logger.info "#{timestamp} - SETUP: initializing the project finished successfully."
      J1.logger.info "#{timestamp} - SETUP: to open your site, run: j1 site"
    else
      raise SystemExit
      end
  else
    raise SystemExit
  end
end