Class: J1::Commands::Reset

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

Class Method Summary collapse

Methods inherited from J1::Command

inherited, subclasses

Class Method Details

.init_with_program(prog) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/j1/commands/reset.rb', line 9

def init_with_program(prog)
  prog.command(:reset) do |c|
    c.description 'Reset a J1 Project to factory state'
    c.syntax 'reset'
    c.action do |args, options|
      J1::Commands::Reset.process(args, options)
    end
  end
end

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/j1/commands/reset.rb', line 19

def process(args, options = {})
  timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
  if J1::Utils::is_project?
    if J1::Utils::is_project_setup?
      J1.logger.info "#{timestamp} - RESET: reset the project to factory state .."
      J1.logger.info "#{timestamp} - RESET: be patient, this will take a while .."
      process = J1::Utils::Exec2.run('RESET','npm', 'run', 'reset')
      if process.success?
        timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
        J1.logger.info "#{timestamp} - RESET: resetting the project finished successfully."
        J1.logger.info "#{timestamp} - RESET: to setup the project, run: j1 setup"
      else
        raise SystemExit
      end
    else
      raise SystemExit
    end
  else
    raise SystemExit
  end
end