Class: Lanes::Command::ClientConfig

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/lanes/command/client_config.rb

Constant Summary collapse

ROOT =
Pathname.new(__FILE__).dirname.join("..", "..", "..")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#controlling_extensionObject (readonly)

Returns the value of attribute controlling_extension.



9
10
11
# File 'lib/lanes/command/client_config.rb', line 9

def controlling_extension
  @controlling_extension
end

#directoryObject (readonly)

Returns the value of attribute directory.



7
8
9
# File 'lib/lanes/command/client_config.rb', line 7

def directory
  @directory
end

#extension_pathObject (readonly)

Returns the value of attribute extension_path.



11
12
13
# File 'lib/lanes/command/client_config.rb', line 11

def extension_path
  @extension_path
end

#lanes_root_pathObject (readonly)

Returns the value of attribute lanes_root_path.



10
11
12
# File 'lib/lanes/command/client_config.rb', line 10

def lanes_root_path
  @lanes_root_path
end

#module_pathsObject (readonly)

Returns the value of attribute module_paths.



13
14
15
# File 'lib/lanes/command/client_config.rb', line 13

def module_paths
  @module_paths
end

Class Method Details

.source_rootObject



16
17
18
# File 'lib/lanes/command/client_config.rb', line 16

def self.source_root
    ROOT.join("templates", "js")
end

Instance Method Details

#apply_lanes_configObject



20
21
22
23
# File 'lib/lanes/command/client_config.rb', line 20

def apply_lanes_config
    Lanes::Configuration.apply
    Lanes::Extensions.load_controlling_config
end

#make_temp_dirObject



31
32
33
# File 'lib/lanes/command/client_config.rb', line 31

def make_temp_dir
    @directory = Pathname.new(Dir.mktmpdir)
end

#set_module_pathsObject



35
36
37
38
39
40
# File 'lib/lanes/command/client_config.rb', line 35

def set_module_paths
    @module_paths = Extensions.map { |e| e.root_path.join('client').to_s }.reverse + [
        controlling_extension.root_path.join('node_modules').to_s,
        directory.to_s
    ]
end

#set_varsObject



25
26
27
28
29
# File 'lib/lanes/command/client_config.rb', line 25

def set_vars
    @lanes_root_path = ROOT
    @controlling_extension = Command.load_current_extension(raise_on_fail: true)
    @extension_path = controlling_extension.root_path
end

#write_asset_filesObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/lanes/command/client_config.rb', line 42

def write_asset_files
    say "Generating config in #{directory}", :green

    template('jest.config.json',
             directory.join('jest.config.json'), verbose: false)

    template('root-view.html',
             directory.join('root-view.tmpl.html'), verbose: false)

    template('screens.js',
             directory.join('lanes/screen-definitions.js'), verbose: false)

    # set the mtime to the past, otherwise Webpack will build repeatedly for a second
    FileUtils.touch directory.join('index.html').to_s, mtime: Time.now - 1.minute
end