vagrant-solidus 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +22 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +201 -0
- data/Rakefile +2 -0
- data/lib/vagrant-solidus.rb +26 -0
- data/lib/vagrant-solidus/command.rb +70 -0
- data/lib/vagrant-solidus/provisioner.rb +87 -0
- data/lib/vagrant-solidus/provisioner/.bashrc +6 -0
- data/lib/vagrant-solidus/provisioner/.gemrc +2 -0
- data/lib/vagrant-solidus/site/command.rb +21 -0
- data/lib/vagrant-solidus/site/create.rb +41 -0
- data/lib/vagrant-solidus/site/log.rb +27 -0
- data/lib/vagrant-solidus/site/restart.rb +18 -0
- data/lib/vagrant-solidus/site/run.rb +29 -0
- data/lib/vagrant-solidus/site/start.rb +52 -0
- data/lib/vagrant-solidus/site/status.rb +35 -0
- data/lib/vagrant-solidus/site/stop.rb +31 -0
- data/lib/vagrant-solidus/site/subcommand.rb +87 -0
- data/lib/vagrant-solidus/site/update.rb +70 -0
- data/lib/vagrant-solidus/site/watch.rb +58 -0
- data/lib/vagrant-solidus/site_helpers.rb +334 -0
- data/lib/vagrant-solidus/solidus-box/Vagrantfile +30 -0
- data/lib/vagrant-solidus/solidus-box/command.rb +21 -0
- data/lib/vagrant-solidus/solidus-box/init.rb +38 -0
- data/lib/vagrant-solidus/version.rb +5 -0
- data/vagrant-solidus.gemspec +22 -0
- metadata +100 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require_relative '../command'
|
|
2
|
+
|
|
3
|
+
module VagrantPlugins
|
|
4
|
+
module Solidus
|
|
5
|
+
module Site
|
|
6
|
+
class Command < VagrantPlugins::Solidus::Command
|
|
7
|
+
def self.synopsis
|
|
8
|
+
'manages Solidus sites'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def command
|
|
12
|
+
'site'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def subcommands
|
|
16
|
+
%w[create log restart run start status stop update watch]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require_relative 'subcommand'
|
|
2
|
+
|
|
3
|
+
module VagrantPlugins
|
|
4
|
+
module Solidus
|
|
5
|
+
module Site
|
|
6
|
+
class Create < Subcommand
|
|
7
|
+
def parse_arguments
|
|
8
|
+
extra_argv = parse_argv([1]) do |opts|
|
|
9
|
+
opts.banner << " <site>"
|
|
10
|
+
opts.separator "Create a new Solidus site, based on a Solidus site template."
|
|
11
|
+
opts.separator "See https://github.com/solidusjs/solidus-site-template for more information."
|
|
12
|
+
opts.separator ""
|
|
13
|
+
site_template_command_line_options(opts)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
@site_name = extra_argv[0]
|
|
17
|
+
|
|
18
|
+
load_site
|
|
19
|
+
fail("Directory already exists and is not empty: #{@site_host_path}") if directory_exists?(@site_host_path)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def execute
|
|
23
|
+
with_running_vm do
|
|
24
|
+
unless @site_template_guest_path
|
|
25
|
+
@env.ui.info("Cloning site template...")
|
|
26
|
+
clone_site_template(@site_template_git_url)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
@env.ui.info("Creating site from template...")
|
|
30
|
+
create_site_from_template(@site_template_guest_path)
|
|
31
|
+
|
|
32
|
+
@env.ui.success("#{@site_name} is created, ready to be started")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Success, exit status 0
|
|
36
|
+
0
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require_relative 'subcommand'
|
|
2
|
+
|
|
3
|
+
module VagrantPlugins
|
|
4
|
+
module Solidus
|
|
5
|
+
module Site
|
|
6
|
+
class Log < Subcommand
|
|
7
|
+
def parse_arguments
|
|
8
|
+
parse_argv do |opts|
|
|
9
|
+
opts.separator "Follow the site's log file."
|
|
10
|
+
opts.separator ""
|
|
11
|
+
site_name_command_line_option(opts)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def execute
|
|
16
|
+
with_running_vm do
|
|
17
|
+
@env.ui.info("Following #{@site_log_file_path} (press Ctrl+C to quit)...")
|
|
18
|
+
follow_site_log
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Success, exit status 0
|
|
22
|
+
0
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require_relative 'start'
|
|
2
|
+
|
|
3
|
+
module VagrantPlugins
|
|
4
|
+
module Solidus
|
|
5
|
+
module Site
|
|
6
|
+
# This is just an alias for the Start command...
|
|
7
|
+
class Restart < Start
|
|
8
|
+
def parse_arguments
|
|
9
|
+
parse_argv do |opts|
|
|
10
|
+
opts.separator "Restart a running site, or start it if it is stopped."
|
|
11
|
+
opts.separator ""
|
|
12
|
+
site_start_command_line_options(opts)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative 'subcommand'
|
|
2
|
+
|
|
3
|
+
module VagrantPlugins
|
|
4
|
+
module Solidus
|
|
5
|
+
module Site
|
|
6
|
+
class Run < Subcommand
|
|
7
|
+
def parse_arguments
|
|
8
|
+
extra_argv = parse_argv(1..Float::INFINITY) do |opts|
|
|
9
|
+
opts.banner << " <command>"
|
|
10
|
+
opts.separator "Run a command in the context of the site."
|
|
11
|
+
opts.separator ""
|
|
12
|
+
site_name_command_line_option(opts)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
@guest_command = extra_argv.join(' ')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def execute
|
|
19
|
+
with_running_vm do
|
|
20
|
+
guest_exec(:log_all, "cd #{@site_guest_path} && #{@guest_command}")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Command's exit status
|
|
24
|
+
@last_exit_code
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require_relative 'subcommand'
|
|
2
|
+
|
|
3
|
+
module VagrantPlugins
|
|
4
|
+
module Solidus
|
|
5
|
+
module Site
|
|
6
|
+
class Start < Subcommand
|
|
7
|
+
def parse_arguments
|
|
8
|
+
parse_argv do |opts|
|
|
9
|
+
opts.separator "Install and start the site."
|
|
10
|
+
opts.separator ""
|
|
11
|
+
site_start_command_line_options(opts)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def execute
|
|
16
|
+
with_running_vm do
|
|
17
|
+
stop_site
|
|
18
|
+
|
|
19
|
+
unless @fast
|
|
20
|
+
@env.ui.info("Installing site...")
|
|
21
|
+
fail("Site could not be installed") unless install_site
|
|
22
|
+
install_pow_site if pow_installed?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
@env.ui.info("Starting dev server...")
|
|
26
|
+
fail("Site could not be started") unless start_site_service
|
|
27
|
+
|
|
28
|
+
if site_responding?
|
|
29
|
+
save_site
|
|
30
|
+
start_site_watcher unless @deaf
|
|
31
|
+
|
|
32
|
+
@env.ui.success("#{@site_name} is started, accessible here:")
|
|
33
|
+
log_site_urls
|
|
34
|
+
else
|
|
35
|
+
log_site_log_tail(10)
|
|
36
|
+
fail("Site could not be started")
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Success, exit status 0
|
|
41
|
+
0
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def install_site
|
|
47
|
+
install_site_dependencies && install_site_node_packages && install_site_service
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require_relative 'subcommand'
|
|
2
|
+
|
|
3
|
+
module VagrantPlugins
|
|
4
|
+
module Solidus
|
|
5
|
+
module Site
|
|
6
|
+
class Status < Subcommand
|
|
7
|
+
def parse_arguments
|
|
8
|
+
parse_argv do |opts|
|
|
9
|
+
opts.separator "Show the current status of all available sites."
|
|
10
|
+
opts.separator ""
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def execute
|
|
15
|
+
with_running_vm do
|
|
16
|
+
Dir[File.join(ROOT_HOST_PATH, '*')].each do |path|
|
|
17
|
+
@site_name = File.basename(path)
|
|
18
|
+
next unless load_and_validate_site
|
|
19
|
+
|
|
20
|
+
if site_started?
|
|
21
|
+
@env.ui.success("#{@site_name} is started, accessible here:")
|
|
22
|
+
log_site_urls
|
|
23
|
+
else
|
|
24
|
+
@env.ui.error("#{@site_name} is stopped")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Success, exit status 0
|
|
30
|
+
0
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require_relative 'subcommand'
|
|
2
|
+
|
|
3
|
+
module VagrantPlugins
|
|
4
|
+
module Solidus
|
|
5
|
+
module Site
|
|
6
|
+
class Stop < Subcommand
|
|
7
|
+
def parse_arguments
|
|
8
|
+
parse_argv do |opts|
|
|
9
|
+
opts.separator "Stop the site."
|
|
10
|
+
opts.separator ""
|
|
11
|
+
site_name_command_line_option(opts)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def execute
|
|
16
|
+
with_running_vm do
|
|
17
|
+
@env.ui.info("Stopping site...")
|
|
18
|
+
stop_site
|
|
19
|
+
uninstall_site_service
|
|
20
|
+
uninstall_pow_site if pow_installed?
|
|
21
|
+
|
|
22
|
+
@env.ui.success("#{@site_name} is stopped")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Success, exit status 0
|
|
26
|
+
0
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
module VagrantPlugins
|
|
2
|
+
module Solidus
|
|
3
|
+
module Site
|
|
4
|
+
class Subcommand < Vagrant.plugin('2', :command)
|
|
5
|
+
include VagrantPlugins::Solidus::SiteHelpers
|
|
6
|
+
|
|
7
|
+
protected
|
|
8
|
+
|
|
9
|
+
def with_running_vm
|
|
10
|
+
unless @env.root_path
|
|
11
|
+
fail("A Vagrant environment is required to run this command. You can:
|
|
12
|
+
- Run `vagrant solidus-box init` to create a Solidus Vagrantfile in this directory
|
|
13
|
+
- Run `vagrant init` to create a default Vagrantfile in this directory
|
|
14
|
+
- Change to a directory with a Vagrantfile".gsub(/^\s*/, ''))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
initialize_env_constants
|
|
18
|
+
parse_arguments
|
|
19
|
+
prepare_data_folders
|
|
20
|
+
|
|
21
|
+
found = false
|
|
22
|
+
with_target_vms do |machine|
|
|
23
|
+
next unless machine.state.id == :running
|
|
24
|
+
@machine = machine
|
|
25
|
+
fail("Virtual machine needs to be provisioned, run `vagrant provision` and try again") unless provisioned?
|
|
26
|
+
found = true
|
|
27
|
+
yield
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
fail("Virtual machine is not started, run `vagrant up` and try again") unless found
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def initialize_env_constants
|
|
34
|
+
env = @env
|
|
35
|
+
env_constants_module = Module.new do
|
|
36
|
+
const_set :ROOT_HOST_PATH, env.root_path
|
|
37
|
+
const_set :ROOT_GUEST_PATH, '/vagrant'
|
|
38
|
+
const_set :DATA_HOST_PATH, File.join(self::ROOT_HOST_PATH, '.vagrant-solidus/data')
|
|
39
|
+
const_set :DATA_GUEST_PATH, File.join(self::ROOT_GUEST_PATH, '.vagrant-solidus/data')
|
|
40
|
+
const_set :SITE_TEMPLATE_HOST_PATH, File.join(self::DATA_HOST_PATH, 'solidus-site-template')
|
|
41
|
+
const_set :SITE_TEMPLATE_GUEST_PATH, File.join(self::DATA_GUEST_PATH, 'solidus-site-template')
|
|
42
|
+
const_set :SITES_CONFIGS_FILE_HOST_PATH, File.join(self::DATA_HOST_PATH, 'sites.json')
|
|
43
|
+
const_set :LOG_HOST_PATH, File.join(self::ROOT_HOST_PATH, '.vagrant-solidus/log')
|
|
44
|
+
const_set :LOG_GUEST_PATH, File.join(self::ROOT_GUEST_PATH, '.vagrant-solidus/log')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
self.class.send(:include, env_constants_module)
|
|
48
|
+
VagrantPlugins::Solidus::SiteHelpers.send(:include, env_constants_module)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def prepare_data_folders
|
|
52
|
+
FileUtils.mkdir_p VagrantPlugins::Solidus::SiteHelpers::DATA_HOST_PATH
|
|
53
|
+
FileUtils.mkdir_p VagrantPlugins::Solidus::SiteHelpers::LOG_HOST_PATH
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def parse_argv(extra_argv_range = [0])
|
|
57
|
+
opts = OptionParser.new do |opts|
|
|
58
|
+
command = self.class.name.split('::').last.downcase
|
|
59
|
+
opts.banner = "Usage: vagrant site #{command} [OPTIONS]"
|
|
60
|
+
opts.separator ""
|
|
61
|
+
yield opts
|
|
62
|
+
help_command_line_option(opts)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
begin
|
|
66
|
+
extra_argv = opts.order(ARGV[2..-1])
|
|
67
|
+
rescue OptionParser::InvalidOption
|
|
68
|
+
raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
unless extra_argv_range.include?(extra_argv.size)
|
|
72
|
+
raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
fail("Not a Solidus site: #{@site_host_path}") if @site_name && !load_and_validate_site
|
|
76
|
+
|
|
77
|
+
return extra_argv
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def load_and_validate_site
|
|
81
|
+
load_site
|
|
82
|
+
validate_site
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require_relative 'subcommand'
|
|
2
|
+
|
|
3
|
+
module VagrantPlugins
|
|
4
|
+
module Solidus
|
|
5
|
+
module Site
|
|
6
|
+
class Update < Subcommand
|
|
7
|
+
def parse_arguments
|
|
8
|
+
parse_argv do |opts|
|
|
9
|
+
opts.separator "Update the site to reflect the latest Solidus site template."
|
|
10
|
+
opts.separator "See https://github.com/solidusjs/solidus-site-template for more information."
|
|
11
|
+
opts.separator ""
|
|
12
|
+
site_name_command_line_option(opts)
|
|
13
|
+
site_template_command_line_options(opts)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def execute
|
|
18
|
+
with_running_vm do
|
|
19
|
+
confirm_command
|
|
20
|
+
|
|
21
|
+
unless @site_template_host_path
|
|
22
|
+
@env.ui.info("Cloning site template...")
|
|
23
|
+
clone_site_template(@site_template_git_url)
|
|
24
|
+
@site_template_host_path = SITE_TEMPLATE_HOST_PATH
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
@env.ui.info("Updating site from template...")
|
|
28
|
+
update_gruntfile
|
|
29
|
+
update_package_dependencies
|
|
30
|
+
|
|
31
|
+
@env.ui.success("#{@site_name} is updated, please review the modified files")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Success, exit status 0
|
|
35
|
+
0
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
protected
|
|
39
|
+
|
|
40
|
+
def confirm_command
|
|
41
|
+
@env.ui.warn("Warning! The following files will be modified:")
|
|
42
|
+
@env.ui.info(" #{@site_name}/Gruntfile.js")
|
|
43
|
+
@env.ui.info(" #{@site_name}/package.json")
|
|
44
|
+
abort unless @env.ui.ask("Are you sure you want to update #{@site_name}? [y/n] ") == 'y'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def update_gruntfile
|
|
48
|
+
template_file_path = File.join(@site_template_host_path, 'root/Gruntfile.js')
|
|
49
|
+
site_file_path = File.join(@site_host_path, 'Gruntfile.js')
|
|
50
|
+
|
|
51
|
+
FileUtils.copy(template_file_path, site_file_path)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def update_package_dependencies
|
|
55
|
+
template_file_path = File.join(@site_template_host_path, 'root/package.json')
|
|
56
|
+
site_file_path = File.join(@site_host_path, 'package.json')
|
|
57
|
+
|
|
58
|
+
template_package = JSON.load(File.new(template_file_path))
|
|
59
|
+
site_package = JSON.load(File.new(site_file_path))
|
|
60
|
+
site_package['devDependencies'].merge!(template_package['devDependencies'])
|
|
61
|
+
site_package['dependencies'].merge!(template_package['dependencies'])
|
|
62
|
+
|
|
63
|
+
File.open(site_file_path, 'w') do |file|
|
|
64
|
+
file.write(JSON.pretty_generate(site_package))
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require_relative 'subcommand'
|
|
2
|
+
require 'listen'
|
|
3
|
+
|
|
4
|
+
module VagrantPlugins
|
|
5
|
+
module Solidus
|
|
6
|
+
module Site
|
|
7
|
+
class Watch < Subcommand
|
|
8
|
+
IGNORED_SITE_DIRECTORIES = [/\.sass-cache/, /deploy/, /node_modules/]
|
|
9
|
+
|
|
10
|
+
def parse_arguments
|
|
11
|
+
parse_argv do |opts|
|
|
12
|
+
opts.separator "Watch the site's files (the default VirtualBox watcher is not reliable)."
|
|
13
|
+
opts.separator ""
|
|
14
|
+
site_name_command_line_option(opts)
|
|
15
|
+
quiet_command_line_option(opts)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def execute
|
|
20
|
+
with_running_vm do
|
|
21
|
+
@env.ui.info("Watching #{@site_name} (press Ctrl+C to quit)...") unless @quiet
|
|
22
|
+
|
|
23
|
+
@listener = Listen.to(@site_host_path, ignore: IGNORED_SITE_DIRECTORIES, &method(:send_file_events_to_vm))
|
|
24
|
+
@listener.start
|
|
25
|
+
|
|
26
|
+
Vagrant::Util::Busy.busy(-> {@listener.stop}) do
|
|
27
|
+
wait_until_listener_or_site_is_stopped
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Success, exit status 0
|
|
32
|
+
0
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
protected
|
|
36
|
+
|
|
37
|
+
def send_file_events_to_vm(modified, added, removed)
|
|
38
|
+
(modified + added + removed).each do |file_host_path|
|
|
39
|
+
@env.ui.info(file_host_path) unless @quiet
|
|
40
|
+
file_guest_path = File.join(@site_guest_path, file_host_path.gsub(@site_host_path, ''))
|
|
41
|
+
with_mutex {guest_exec(nil, "head -c 1 #{file_guest_path} > /dev/null")}
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def wait_until_listener_or_site_is_stopped
|
|
46
|
+
while @listener.listen?
|
|
47
|
+
if with_mutex {site_started? rescue false}
|
|
48
|
+
sleep(SITE_STATUS_WATCHER_POLLING_FREQUENCY)
|
|
49
|
+
else
|
|
50
|
+
@env.ui.error("#{@site_name} is stopped") unless @quiet
|
|
51
|
+
@listener.stop
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|