Class: ZAFReact::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/zaf_react/cli.rb,
lib/zaf_react/cli/init.rb,
lib/zaf_react/cli/build.rb,
lib/zaf_react/cli/start.rb,
lib/zaf_react/cli/server.rb,
lib/zaf_react/cli/package.rb,
lib/zaf_react/cli/validate.rb

Instance Method Summary collapse

Instance Method Details

#buildObject

Raises:

  • (Error)


10
11
12
13
14
15
# File 'lib/zaf_react/cli/build.rb', line 10

def build
  remove_dir 'build'
  directory 'zendesk', 'build'
  raise Error, "React build failed".light_red if !system("npm run build --prefix source")
  directory 'source/build', 'build/assets'
end

#initObject

Raises:

  • (Error)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/zaf_react/cli/init.rb', line 10

def init# _git = false
  if Dir.exists?("source/src")
    exit if ask("Are you sure you want to create a fresh app? This will remove all current work. Type ".light_cyan << "yes".light_yellow << " to continue.".light_cyan).downcase != "yes"
  end
  # remove_dir ".git" if _git
  remove_dir "source"
  remove_dir "zendesk"
  remove_dir "build"
  raise Error, "npm create failed".light_red if !system("create-react-app source")
  remove_dir "source/.git"
  copy_file "#{APP_ROOT}/lib/zaf_react/source/react/public/index.html", "source/public/index.html", force: true
  remove_dir "source/src"
  directory "#{APP_ROOT}/lib/zaf_react/source/react/src", "source/src"
  directory "#{APP_ROOT}/lib/zaf_react/source/zendesk", "zendesk"
  remove_file "source/.gitignore"
  copy_file "#{APP_ROOT}/lib/zaf_react/ignore", ".gitignore"
  # system "git init" if _git
end

#packageObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/zaf_react/cli/package.rb', line 10

def package
  build

  directory "build/assets/static/js", "build/assets" if Dir.exists?("build/assets/static/js")
  directory "build/assets/static/css", "build/assets" if Dir.exists?("build/assets/static/css")

  remove_dir "build/assets/static"

  Dir.glob([
    "build/assets/*.js",
    "build/assets/*.css",
    "build/assets/*.json",
    "build/assets/*.map",
    "build/assets/*.html"
 ]) do |filename|
    gsub_file filename, /(\"\/static\/(js|css)\/)|(\"static\/(js|css)\/)/i, '"'
  end

  system "zat package --path=build"
end

#serverObject

Raises:

  • (Error)


10
11
12
13
# File 'lib/zaf_react/cli/server.rb', line 10

def server
  build
  raise Error, "ZAT build failed".light_red if !system("zat server --path=build")
end

#startObject



10
11
12
# File 'lib/zaf_react/cli/start.rb', line 10

def start
  system "npm start --prefix source"
end

#validateObject



10
11
12
# File 'lib/zaf_react/cli/validate.rb', line 10

def validate
  system "zat validate --path=build"
end