Class: Trio::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions, GetCurrentDirectoryBasename, ProjectExist
Defined in:
lib/trio/cli.rb

Instance Method Summary collapse

Methods included from ProjectExist

#project?

Methods included from GetCurrentDirectoryBasename

#get_current_directory_basename

Instance Method Details

#initObject



15
16
17
18
19
20
21
22
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/trio/cli.rb', line 15

def init()

  if options.length == 1

    if options[:middleman]

      trio_path = File.join('source', 'trio')

      self.trio_exist? trio_path

      self.add_trio trio_path, File.join('.')

      gsub_file 'gulpfile.js', /{{ trio }}/,  trio_path  unless !File.exists? 'gulpfile.js'

      gsub_file 'config.rb',   /(')(img|css|js)(')/,  '\1trio/\2\3'  unless !File.exists? 'config.rb'

      [
        /\s*activate\s:external_pipeline*/,
        /\s*name:\s.*gulp.*/,
        /\s*command:\s.*gulp.*/,
        /\s*source:\s.*tmp\/dist.*/
      ].each do |line|

        uncomment_lines 'config.rb', line

      end

      run 'npm install' unless !File.exists? 'package.json'

    elsif options[:wordpress]

      theme_path = File.join('wp-content', 'themes', options[:wordpress])
      trio_path  = File.join(theme_path , 'trio')

      self.trio_exist? trio_path

      self.show_message 'provide_wordpress_theme', 'red' unless  options[:wordpress] != 'wordpress'

      if File.directory?(theme_path)

        self.add_trio trio_path, '.'

        gsub_file 'gulpfile.js', /{{ trio }}/, trio_path unless !File.exists? 'gulpfile.js'

        inside trio_path do

          ['css', 'js', 'sass'].each do |dir|

            remove_dir(dir)

          end
        end
      else

        self.show_message 'no_wordpress_theme', 'red', options[:wordpress]
      end
    end

  elsif options.length == 0

    trio_path  = File.join('trio')

    self.trio_exist? trio_path

    self.add_trio trio_path, '.'

    gsub_file 'gulpfile.js', /{{ trio }}/, trio_path unless !File.exists? 'gulpfile.js'
  else

    self.show_message 'trio_options', 'red'
  end

end