Class: WSlaveSage
- Inherits:
-
Object
- Object
- WSlaveSage
- Defined in:
- lib/wslave_sage.rb
Instance Attribute Summary collapse
-
#theme_name ⇒ Object
readonly
Returns the value of attribute theme_name.
Instance Method Summary collapse
- #_check ⇒ Object
- #_overwrite_sage_webpack_browsersync_config ⇒ Object
- #_write_wslave_sage_config(name) ⇒ Object
- #build ⇒ Object
- #create(name) ⇒ Object
- #dev ⇒ Object
-
#initialize ⇒ WSlaveSage
constructor
A new instance of WSlaveSage.
- #production ⇒ Object
- #theme_name? ⇒ Boolean
- #update ⇒ Object
Constructor Details
#initialize ⇒ WSlaveSage
Returns a new instance of WSlaveSage.
6 7 8 |
# File 'lib/wslave_sage.rb', line 6 def initialize() @theme_name = '' end |
Instance Attribute Details
#theme_name ⇒ Object (readonly)
Returns the value of attribute theme_name.
4 5 6 |
# File 'lib/wslave_sage.rb', line 4 def theme_name @theme_name end |
Instance Method Details
#_check ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/wslave_sage.rb', line 70 def _check() if (File.exist?("./config/.wslave") && File.exist?("./config/sage.yml")) theme_info = YAML.load_file("./config/sage.yml") @theme_name = theme_info[:theme] return true end puts "This does not appear to be the root of a WSlave managed app with a Sage theme." false end |
#_overwrite_sage_webpack_browsersync_config ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/wslave_sage.rb', line 58 def _overwrite_sage_webpack_browsersync_config return unless _check() theme_info = YAML.load_file("./config/sage.yml") Dir.chdir "#{Dir.pwd}/public/wp-content/themes/#{theme_info[:theme]}" webpack_config_path = './webpack.mix.js' new_webpack_config = File.read(webpack_config_path).gsub( /browserSync\('sage.test'\)/, "browserSync('localhost:8000')" ) File.open(webpack_config_path, 'w') { |f| f.puts new_webpack_config } end |
#_write_wslave_sage_config(name) ⇒ Object
54 55 56 |
# File 'lib/wslave_sage.rb', line 54 def _write_wslave_sage_config(name) File.open("./config/sage.yml", 'w') {|f| YAML.dump({theme: name}, f)} end |
#build ⇒ Object
39 40 41 42 |
# File 'lib/wslave_sage.rb', line 39 def build() return unless _check() system("cd public/wp-content/themes/#{@theme_name} && yarn build") end |
#create(name) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/wslave_sage.rb', line 10 def create(name) unless File.exist?("./config/.wslave") puts "This command must be run in the root of a WSlave setup" end name = 'wslave-sage-theme' if name.empty? project_root = Dir.pwd puts "Creating Sage theme at public/wp-content/themes/#{name}" Dir.chdir "public/wp-content/themes" `composer create-project roots/sage #{name}` Dir.chdir name `composer require roots/acorn` Dir.chdir project_root _write_wslave_sage_config(name) # _overwrite_sage_webpack_browsersync_config # TODO: sageの更新でwebpack.mix.jsが出力されなくなっている様子 end |
#dev ⇒ Object
34 35 36 37 |
# File 'lib/wslave_sage.rb', line 34 def dev() return unless _check() system("cd public/wp-content/themes/#{@theme_name} && yarn start") end |
#production ⇒ Object
44 45 46 47 |
# File 'lib/wslave_sage.rb', line 44 def production() return unless _check() system("cd public/wp-content/themes/#{@theme_name} && yarn build:production") end |
#theme_name? ⇒ Boolean
49 50 51 52 |
# File 'lib/wslave_sage.rb', line 49 def theme_name?() return '' unless _check() @theme_name end |
#update ⇒ Object
29 30 31 32 |
# File 'lib/wslave_sage.rb', line 29 def update() return unless _check() system("cd public/wp-content/themes/#{@theme_name} && yarn && yarn build") end |